Skip to content

Commit 9a6b256

Browse files
tests
1 parent f1a6521 commit 9a6b256

6 files changed

Lines changed: 39 additions & 42 deletions

File tree

tests/e2e-tests/api/get_letters_tests.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/e2e-tests/api/content_types/test_406_errors.py renamed to tests/e2e-tests/api/headers/test-x-request-id.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
from lib.fixtures import * # NOSONAR
44
from lib.constants import DEFAULT_CONTENT_TYPE, VALID_ENDPOINTS
55

6-
HEADER_NAME = ["accept", "ACCEPT"]
7-
HEADER_VALUE = ["", "application/xml", "application/json; charset=utf-9"]
86
METHODS = ["get", "post"]
9-
CORRELATION_IDS = [None, "88b10816-5d45-4992-bed0-ea685aaa0e1f"]
7+
REQUEST_ID = [None, "88b10816-5d45-4992-bed0-ea685aaa0e1f"]
108

119

1210
@pytest.mark.test
1311
@pytest.mark.devtest
1412
@pytest.mark.inttest
1513
@pytest.mark.prodtest
16-
@pytest.mark.parametrize("accept_header_name", HEADER_NAME)
17-
@pytest.mark.parametrize("accept_header_value", HEADER_VALUE)
18-
@pytest.mark.parametrize("correlation_id", CORRELATION_IDS)
14+
@pytest.mark.parametrize("request_id", REQUEST_ID)
1915
@pytest.mark.parametrize("method", METHODS)
2016
@pytest.mark.parametrize("endpoints", VALID_ENDPOINTS)
2117
def test_406(
@@ -27,10 +23,9 @@ def test_406(
2723
endpoints
2824
):
2925
resp = getattr(requests, method)(f"{url}/{endpoints}", headers={
30-
"Authorization": "Bearer v2tQ9ez4uiEIcEm1fapYN0DrVYyL",
26+
"Authorization": "Bearer BdXxzeUkIu7F3Fu91Hsa4URYORMa",
3127
accept_header_name: accept_header_value,
32-
"X-Correlation-Id": correlation_id
28+
"X-Correlation-Id": request_id
3329
})
3430

35-
assert resp.status_code == 406
36-
assert resp.headers.get("Content-Type") == DEFAULT_CONTENT_TYPE
31+
assert resp.status_code == 500
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import requests
2+
import pytest
3+
from lib.fixtures import * # NOSONAR
4+
from lib.constants import DEFAULT_CONTENT_TYPE, VALID_ENDPOINTS
5+
6+
@pytest.mark.test
7+
@pytest.mark.devtest
8+
@pytest.mark.inttest
9+
@pytest.mark.prodtest
10+
def test_406(url, bearer_token):
11+
12+
headers = Generators.generate_valid_headers(bearer_token)
13+
data = Generators.generate_valid_create_message_body(url)
14+
15+
get_message_response = requests.get(f"{url}/letters/status", headers=headers)
16+
17+
18+
assert get_message_response.status_code == 200

tests/e2e-tests/lib/authentication.py

Whitespace-only changes.

tests/e2e-tests/lib/fixtures.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import os
33
import re
4-
4+
from .authentication import AuthenticationCache
55

66
# for now this is the same as PROXY_NAME
77
# this is here to illustrate how these can be decoupled
@@ -43,3 +43,10 @@ def url(api_product_name):
4343
# Everything else (dev, test, pr environments, internal-dev)
4444
else:
4545
return f"https://{environment}.api.service.nhs.uk/{suffix}"
46+
47+
# By setting the scope to session on the cache but leaving session scope OFF
48+
# the fixtures for each bearer token, we ensure the cache is checked and has a
49+
# chance to refresh before any test which might depend on a bearer token
50+
@pytest.fixture(scope='session')
51+
def authentication_cache():
52+
return AuthenticationCache()

tests/e2e-tests/lib/generators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ def generate_valid_create_message_body(environment="sandbox"):
1010
"type": "Letter"
1111
}
1212
}
13+
14+
@staticmethod
15+
def generate_valid_headers(auth):
16+
return {
17+
"Authorization": auth,
18+
"Content-Type": "application/json",
19+
"Accept": "application/json"
20+
}

0 commit comments

Comments
 (0)