Skip to content

Commit a6b3892

Browse files
tests
1 parent 2981235 commit a6b3892

7 files changed

Lines changed: 88 additions & 22 deletions

File tree

pytest.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
[pytest]
22
pythonpath =
33
tests/e2e-tests
4+
python_files = *_tests.py test-*.py
5+
addopts = --strict-markers
6+
markers =
7+
smoketest: suitable to run against all environments even production
8+
mtlstest: suitable to run against periodically against environments
9+
sandboxtest: suitable to run against sandbox environment
10+
devtest: suitable to run against dev like environments
11+
devtestonly: suitable to run against internal-dev only
12+
devperftest: rate limiting tests suitable to run against dev like environments
13+
inttest: suitable to run against integration environment
14+
prodtest: suitable to run against production environment
15+
uattest: suitable to run against uat environment
16+
test: suitable to run against all environments

tests/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ node_modules/
1111
/allure-report
1212
*/__pycache__/
1313
**/__pycache__/
14+
__pycache__/
15+
*/__pycache__/
16+
**/__pycache__/
1417
*.pyc

tests/e2e-tests/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
11
# E2E Tests
2+
3+
## Generate An Apigee Access Token
4+
5+
To generate authentication using Apigee, you must have access to an Apigee account and use `get_token` via the command line and generate an Apigee access token.
6+
7+
**Tokens expire once per day and require refreshing.**
8+
9+
* Install [`get_token`](https://docs.apigee.com/api-platform/system-administration/auth-tools#install)
10+
* Run the following command and log in with your Apigee credentials when prompted:
11+
12+
```shell
13+
export APIGEE_ACCESS_TOKEN=$(SSO_LOGIN_URL=https://login.apigee.com get_token)
14+
```
15+
16+
* If your token does not refresh, try clearing the cache:
17+
18+
```shell
19+
export APIGEE_ACCESS_TOKEN=$(SSO_LOGIN_URL=https://login.apigee.com get_token --clear-sso-cache)
20+
```
21+
22+
### Set Proxy Name
23+
24+
Set the `PROXY_NAME` environment variable to specify the environment for test execution. You can find the proxy name by logging into [Apigee](https://apigee.com/edge), navigating to 'API Proxies' and searching for 'supplier-api'.
25+
26+
```shell
27+
export PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
28+
```
29+
30+
Available values for `PROXY_NAME` include:
31+
32+
* `nhs-notify-supplier--internal-dev--nhs-notify-supplier`
33+
* `nhs-notify-supplier--internal-dev--nhs-notify-supplier-pr<num>`
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
import requests
2-
import pytest
3-
from lib.constants import VALID_ENDPOINTS
4-
5-
METHODS = ["get", "post"]
6-
CORRELATION_IDS = [None, "76491414-d0cf-4655-ae20-a4d1368472f3"]
7-
8-
9-
@pytest.mark.test
10-
@pytest.mark.nhsd_apim_authorization({"access": "application", "level": "level0"})
11-
@pytest.mark.parametrize("method", METHODS)
12-
@pytest.mark.parametrize("endpoints", VALID_ENDPOINTS)
13-
def test_user_token_get(nhsd_apim_proxy_url, nhsd_apim_auth_headers, method, endpoints):
14-
print(nhsd_apim_proxy_url)
15-
16-
resp = getattr(requests, method)(f"{nhsd_apim_proxy_url}{endpoints}", headers={
17-
**nhsd_apim_auth_headers
18-
})
19-
20-
print("Status:", resp.status_code)
21-
22-
assert(resp.status_code == 401)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import requests
2+
import pytest
3+
from lib.fixtures import * # NOSONAR
4+
from lib.constants import DEFAULT_CONTENT_TYPE, VALID_ENDPOINTS
5+
6+
HEADER_NAME = ["accept", "ACCEPT"]
7+
HEADER_VALUE = ["", "application/xml", "application/json; charset=utf-9"]
8+
METHODS = ["get", "post"]
9+
CORRELATION_IDS = [None, "88b10816-5d45-4992-bed0-ea685aaa0e1f"]
10+
11+
12+
@pytest.mark.test
13+
@pytest.mark.devtest
14+
@pytest.mark.inttest
15+
@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)
19+
@pytest.mark.parametrize("method", METHODS)
20+
@pytest.mark.parametrize("endpoints", VALID_ENDPOINTS)
21+
def test_406(
22+
url,
23+
accept_header_name,
24+
accept_header_value,
25+
correlation_id,
26+
method,
27+
endpoints
28+
):
29+
resp = getattr(requests, method)(f"{url}/{endpoints}", headers={
30+
"Authorization": "Bearer v2tQ9ez4uiEIcEm1fapYN0DrVYyL",
31+
accept_header_name: accept_header_value,
32+
"X-Correlation-Id": correlation_id
33+
})
34+
35+
assert resp.status_code == 406
36+
assert resp.headers.get("Content-Type") == DEFAULT_CONTENT_TYPE

tests/e2e-tests/lib/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
VALID_ENDPOINTS = ["/letters"]
22
METHODS = ["get", "post"]
3+
DEFAULT_CONTENT_TYPE = "application/vnd.api+json"

tests/e2e-tests/lib/fixtures.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pytest
22
import os
33
import re
4+
5+
46
# for now this is the same as PROXY_NAME
57
# this is here to illustrate how these can be decoupled
68
@pytest.fixture(scope='session')
79
def api_product_name():
10+
print("PROXY_NAME =", os.environ.get("PROXY_NAME"))
811
api_proxy = os.environ.get("API_PROXY")
912
proxy_name = os.environ.get("PROXY_NAME")
1013

0 commit comments

Comments
 (0)