Skip to content

Commit 013edbf

Browse files
committed
addres PR comments and make more use of constants
1 parent 6a33395 commit 013edbf

6 files changed

Lines changed: 24 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ New developers of the NHS Notify Supplier API should understand the below.
122122

123123
##### SDKs
124124

125-
- The [SDK](sdk) folder is excluded from all pre requisites
125+
- The [SDK](sdk) folder is excluded from all pre reqs
126126
- DO NOT make manual changes to the [SDK](sdk), instead [build](#build) it
127127
- The SDK folder is excluded from git commits,
128128
and will be built as part of the CI/CD pipeline and released as a GitHub

tests/e2e-tests/api/mi/test_get_mi_information.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def test_404_mi_does_not_exist(url, authentication_secret):
4141
@pytest.mark.devtest
4242
@pytest.mark.inttest
4343
@pytest.mark.prodtest
44-
def test_404_mi_miId_from_different_supplier_returns_does_not_exist(url, authentication_secret, supplier1_authentication_secret):
44+
def test_404_mi_miId_from_different_supplier_returns_does_not_exist(url, authentication_secret, secondary_supplier_authentication_secret):
4545
headers = Generators.generate_valid_headers(authentication_secret)
46-
other_supplier_headers = Generators.generate_valid_headers(supplier1_authentication_secret) # secondary_auth
46+
other_supplier_headers = Generators.generate_valid_headers(secondary_supplier_authentication_secret)
4747
data = Generators.generate_valid_mi_record_body()
4848
create_mi = requests.post(
4949
f"{url}/{MI_ENDPOINT}",

tests/e2e-tests/lib/authentication.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import jwt
55
import requests
66
import json
7+
from .constants import SUPPLIER, SECONDARY_SUPPLIER
78
from .secret import Secret
89

910

@@ -32,38 +33,39 @@ def generate_authentication(self, env, base_url, path, supplier_id = None):
3233
# the backend. The test will only check that the API doesn't return a 401,
3334
# a 404 response means the authentication is working.
3435
test_url = f"{base_url}{path}"
36+
api_key = None
3537

3638
if env == "internal-dev":
37-
if (supplier_id == "TestSupplier1"):
39+
if (supplier_id == SECONDARY_SUPPLIER):
3840
api_key = os.environ["NON_PROD_SECONDARY_API_KEY"]
39-
else:
41+
elif (supplier_id == SUPPLIER):
4042
api_key = os.environ["NON_PROD_API_KEY"]
4143

4244
private_key = os.environ["NON_PROD_PRIVATE_KEY"]
4345
url = "https://internal-dev.api.service.nhs.uk/oauth2/token"
4446
kid = "internal-dev-test-1"
4547
elif env == "ref":
46-
if (supplier_id == "TestSupplier1"):
48+
if (supplier_id == SECONDARY_SUPPLIER):
4749
api_key = os.environ["NON_PROD_SECONDARY_API_KEY"]
48-
else:
50+
elif (supplier_id == SUPPLIER):
4951
api_key = os.environ["NON_PROD_API_KEY"]
5052

5153
private_key = os.environ["NON_PROD_PRIVATE_KEY"]
5254
url = "https://ref.api.service.nhs.uk/oauth2/token"
5355
kid = "internal-dev-test-1"
5456
elif env == "int":
55-
if (supplier_id == "TestSupplier1"):
57+
if (supplier_id == SECONDARY_SUPPLIER):
5658
api_key = os.environ["INTEGRATION_SECONDARY_API_KEY"]
57-
else:
59+
elif (supplier_id == SUPPLIER):
5860
api_key = os.environ["INTEGRATION_API_KEY"]
5961

6062
private_key = os.environ.get("INTEGRATION_PRIVATE_KEY")
6163
url = "https://int.api.service.nhs.uk/oauth2/token"
6264
kid = "internal-dev-test-1"
6365
elif env == "prod":
64-
if (supplier_id == "TestSupplier1"):
66+
if (supplier_id == SECONDARY_SUPPLIER):
6567
api_key = os.environ.get("PRODUCTION_SECONDARY_API_KEY")
66-
else:
68+
elif (supplier_id == SUPPLIER):
6769
api_key = os.environ.get("PRODUCTION_API_KEY")
6870

6971
private_key = os.environ.get("PRODUCTION_PRIVATE_KEY")
@@ -82,10 +84,10 @@ def generate_authentication(self, env, base_url, path, supplier_id = None):
8284
_, latest_token_expiry = self.tokens.get(env, (None, 0))
8385

8486
# Generate new token if latest token will expire in 15 seconds
85-
if env not in self.tokens or latest_token_expiry < int(time()) + 15:
86-
self.tokens[env] = self.generate_and_test_new_token(api_key, private_key, url, kid, test_url)
87+
if (env, supplier_id) not in self.tokens or latest_token_expiry < int(time()) + 15:
88+
self.tokens[(env, supplier_id)] = self.generate_and_test_new_token(api_key, private_key, url, kid, test_url)
8789

88-
authentication_secret = self.tokens[env][0]
90+
authentication_secret = self.tokens[(env, supplier_id)][0]
8991
return Secret(authentication_secret)
9092

9193
def generate_and_test_new_token(self, api_key, private_key, url, kid, test_url):

tests/e2e-tests/lib/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
DEFAULT_CONTENT_TYPE = "application/vnd.api+json"
44
LETTERS_ENDPOINT = "/letters"
55
MI_ENDPOINT = "/mi"
6-
SUPPLIER = "TestSupplier1"
7-
SECONDARY_SUPPLIER = "supplier1"
6+
SUPPLIER = "supplier1"
7+
SECONDARY_SUPPLIER = "TestSupplier1"

tests/e2e-tests/lib/fixtures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import os
33
import re
4+
from .constants import SUPPLIER, SECONDARY_SUPPLIER
45
from .authentication import AuthenticationCache
56

67
# for now this is the same as PROXY_NAME
@@ -54,7 +55,7 @@ def authentication_cache():
5455
@pytest.fixture()
5556
def authentication_secret(url, authentication_cache):
5657
environment = os.environ['API_ENVIRONMENT']
57-
return authentication_cache.generate_authentication(environment, url, "/", "TestSupplier1")
58+
return authentication_cache.generate_authentication(environment, url, "/", SUPPLIER)
5859

5960
@pytest.fixture()
6061
def status_authentication_secret(url, authentication_cache):
@@ -66,6 +67,6 @@ def status_endpoint_api_key():
6667
return os.environ["STATUS_ENDPOINT_API_KEY"]
6768

6869
@pytest.fixture()
69-
def supplier1_authentication_secret(url, authentication_cache):
70+
def secondary_supplier_authentication_secret(url, authentication_cache):
7071
environment = os.environ['API_ENVIRONMENT']
71-
return authentication_cache.generate_authentication(environment, url, "/", "supplier1")
72+
return authentication_cache.generate_authentication(environment, url, "/", SECONDARY_SUPPLIER)

tests/e2e-tests/lib/letters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import pathlib
44
import time
55
import requests
6+
from .constants import SUPPLIER
67
from lib.errorhandler import ErrorHandler
78

89

910
_REPO_ROOT = pathlib.Path(__file__).resolve().parents[3]
1011
_CLI_WORKSPACE = "nhs-notify-supplier-api-letter-test-data-utility"
11-
_SUPPLIER_ID = "TestSupplier1"
1212

1313

1414
def create_test_data(count: int = 10) -> None:
@@ -28,7 +28,7 @@ def create_test_data(count: int = 10) -> None:
2828
"cli",
2929
"--",
3030
"create-letter-batch",
31-
"--supplier-id", _SUPPLIER_ID,
31+
"--supplier-id", SUPPLIER,
3232
"--environment", environment,
3333
"--awsAccountId", aws_account_id,
3434
"--group-id", "TestGroupID",

0 commit comments

Comments
 (0)