Skip to content

Commit 2c36240

Browse files
test
1 parent 3c026ac commit 2c36240

File tree

11 files changed

+234
-193
lines changed

11 files changed

+234
-193
lines changed

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ node_modules/
1111
/allure-report
1212
/e2e-tests/.pytest_cache
1313
/e2e-tests/__pycache__/
14+
/e2e-tests/_lib/_pycache__/
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.constants import METHODS, VALID_ENDPOINTS
4+
from lib.fixtures import * # NOSONAR
5+
6+
@pytest.mark.test
7+
@pytest.mark.devtest
8+
@pytest.mark.inttest
9+
@pytest.mark.prodtest
10+
@pytest.mark.parametrize("method", METHODS)
11+
@pytest.mark.parametrize("endpoints", VALID_ENDPOINTS)
12+
def test_401_invalid(url, method, endpoints):
13+
14+
resp = getattr(requests, method)(f"{url}{endpoints}", headers={
15+
"Authorization": "invalid",
16+
})
17+
18+
assert(resp.status_code == "401")

tests/e2e-tests/endpoint_tests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def _get(url, headers=None, timeout=10):
99
def test_ping(nhsd_apim_proxy_url):
1010
resp = requests.get(nhsd_apim_proxy_url + "/_ping")
1111
assert resp.status_code == 200
12-
print("Ping Response Body:", resp.text)
1312

1413
@pytest.mark.smoketest
1514
def test_401_status_without_api_key(nhsd_apim_proxy_url):
@@ -27,10 +26,9 @@ def test_invalid_jwt_rejected(nhsd_apim_proxy_url, nhsd_apim_auth_headers):
2726
"""
2827
headers = {
2928
**nhsd_apim_auth_headers,
30-
"headerauth1": "headervalue1",
3129
"x-request-id": "123456"
3230
}
33-
print(headers)
31+
3432
# If no Authorization configured in project headers, skip
3533
if "Authorization" not in headers:
3634
pytest.skip("JWT auth not configured for this environment")

tests/e2e-tests/get_letters_tests.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,10 @@ def client():
1414
config = ApigeeNonProdCredentials()
1515
return ApigeeClient(config=config)
1616

17-
@pytest.mark.nhsd_apim_authorization(access="application", level="level3")
18-
def test_app_level0_access(nhsd_apim_proxy_url, nhsd_apim_auth_headers, _create_test_app, client: ApigeeClient ):
19-
headers = {
20-
**nhsd_apim_auth_headers,
21-
"headerauth1": "headervalue1",
22-
"x-request-id": "123456"
23-
}
24-
25-
app_api = DeveloperAppsAPI(client=client)
26-
app_name = _create_test_app["name"]
27-
28-
attributes = app_api.get_app_attributes(
29-
email="[email protected]", app_name=app_name
30-
)
31-
32-
attributes['attribute'].append({'name': 'NHSD-Supplier-ID' , 'value': 'supplier1'})
33-
34-
app_api.post_app_attributes(
35-
36-
app_name=app_name,
37-
body=attributes
38-
)
39-
40-
resp = requests.get(
41-
nhsd_apim_proxy_url + "/letters?limit=10", headers=headers
42-
)
43-
assert resp.status_code == 200
44-
4517
@pytest.mark.nhsd_apim_authorization(access="application", level="level3")
4618
def test_app_level0_access_post(nhsd_apim_proxy_url, nhsd_apim_auth_headers, _create_test_app, client: ApigeeClient ):
4719
headers = {
4820
**nhsd_apim_auth_headers,
49-
"headerauth1": "headervalue1",
5021
"x-request-id": "123456"
5122
}
5223

-704 Bytes
Binary file not shown.

tests/e2e-tests/lib/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VALID_ENDPOINTS = ["/letters", "/mi"]
2+
METHODS = ["get", "post", "patch", "head"]

tests/e2e-tests/lib/fixtures.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# for now this is the same as PROXY_NAME
2+
# this is here to illustrate how these can be decoupled
3+
@pytest.fixture(scope='session')
4+
def api_product_name():
5+
try:
6+
return os.environ['API_PROXY']
7+
except KeyError:
8+
# fall back to PROXY_NAME
9+
return os.environ['PROXY_NAME']
10+
11+
@pytest.fixture(scope='session')
12+
def url(api_product_name):
13+
# PR build naming: nhs-pr112-supapi
14+
if api_product_name is not None and api_product_name.startswith('nhs-pr'):
15+
pr_number = re.search(r'\d+', api_product_name).group()
16+
suffix = f"nhs-pr{pr_number}-supapi"
17+
else:
18+
suffix = "nhs-main-supapi"
19+
20+
environment = os.environ['API_ENVIRONMENT']
21+
22+
if environment == "prod":
23+
return "https://api.service.nhs.uk/nhs-main-supapi"
24+
25+
elif environment in ["ref", "ref2"]:
26+
return "https://internal-dev.api.service.nhs.uk/nhs-main-supapi"
27+
28+
else:
29+
return f"https://{environment}.api.service.nhs.uk/{suffix}"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Scenario: An API consumer submitting a request with an invalid authorization token receives a 401 'Access Denied' response
2+
==========================================================================================================================
3+
4+
| **Given** the API consumer provides an invalid authorization token
5+
| **When** the request is submitted
6+
| **Then** the response is a 401 access denied error
7+
8+
9+
**Asserts**
10+
- Response returns a 401 'Access Denied' error
11+
- Response returns the expected error message body
12+
13+
.. include:: /partials/methods.rst
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**Methods**
2+
3+
This test makes use of different HTTP methods, if the method is either HEAD or OPTIONS the test will not assert against the body of the response as none is returned.
4+
5+
.. list-table::
6+
:widths: 50
7+
:header-rows: 7
8+
9+
* - Value
10+
* - GET
11+
* - POST
12+
* - PUT
13+
* - PATCH
14+
* - DELETE
15+
* - HEAD
16+
* - OPTIONS

0 commit comments

Comments
 (0)