generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
CCM-12963 E2E Tests #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Namitha-Prabhu
wants to merge
3
commits into
main
Choose a base branch
from
feature/CCM-12963-E2ETests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
CCM-12963 E2E Tests #340
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [pytest] | ||
| pythonpath = | ||
| tests/e2e-tests/api | ||
| python_files = *_tests.py test_*.py | ||
| addopts = --strict-markers | ||
| markers = | ||
| smoketest: suitable to run against all environments even production | ||
| mtlstest: suitable to run against periodically against environments | ||
| sandboxtest: suitable to run against sandbox environment | ||
| devtest: suitable to run against internal-dev environments | ||
| inttest: suitable to run against integration environment | ||
| prodtest: suitable to run against production environment | ||
| uattest: suitable to run against uat environment | ||
| test: suitable to run against all environments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # E2E Tests | ||
|
|
||
| ## Generate An Apigee Access Token | ||
|
|
||
| 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. | ||
|
|
||
| **Tokens expire once per day and require refreshing.** | ||
|
|
||
| * Install [`get_token`](https://docs.apigee.com/api-platform/system-administration/auth-tools#install) | ||
| * Run the following command and log in with your Apigee credentials when prompted: | ||
|
|
||
| ```shell | ||
| export APIGEE_ACCESS_TOKEN=$(SSO_LOGIN_URL=https://login.apigee.com get_token) | ||
| ``` | ||
|
|
||
| * If your token does not refresh, try clearing the cache: | ||
|
|
||
| ```shell | ||
| export APIGEE_ACCESS_TOKEN=$(SSO_LOGIN_URL=https://login.apigee.com get_token --clear-sso-cache) | ||
| ``` | ||
|
|
||
| ### Set Proxy Name | ||
|
|
||
| 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'. | ||
|
|
||
| ```shell | ||
| export PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier | ||
| ``` | ||
|
|
||
| Available values for `PROXY_NAME` include: | ||
|
|
||
| * `nhs-notify-supplier--internal-dev--nhs-notify-supplier` | ||
| * `nhs-notify-supplier--internal-dev--nhs-notify-supplier-pr<num>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import requests | ||
| import pytest | ||
| from lib.constants import METHODS, VALID_ENDPOINT_LETTERS | ||
| from lib.fixtures import * | ||
| from lib.errorhandler import ErrorHandler | ||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| @pytest.mark.parametrize("method", METHODS) | ||
| @pytest.mark.parametrize("endpoints", VALID_ENDPOINT_LETTERS) | ||
| def test_401_invalid(url, method, endpoints): | ||
|
|
||
| resp = getattr(requests, method)(f"{url}{endpoints}", headers={ | ||
| "Authorization": "invalid", | ||
| }) | ||
|
|
||
| ErrorHandler.handle_retry(resp) | ||
| assert resp.status_code == 401, f"Response: {resp.status_code}: {resp.text}" | ||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.nhsd_apim_authorization({"access": "application", "level": "level0"}) | ||
| @pytest.mark.parametrize("method", METHODS) | ||
| @pytest.mark.parametrize("endpoints", VALID_ENDPOINT_LETTERS) | ||
| def test_401_invalid_level(nhsd_apim_proxy_url, nhsd_apim_auth_headers, method, endpoints): | ||
| print(nhsd_apim_proxy_url) | ||
|
|
||
| resp = getattr(requests, method)(f"{nhsd_apim_proxy_url}{endpoints}", headers={ | ||
| **nhsd_apim_auth_headers | ||
| }) | ||
|
|
||
| ErrorHandler.handle_retry(resp) | ||
| assert resp.status_code == 401, f"Response: {resp.status_code}: {resp.text}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import uuid | ||
| import requests | ||
| import pytest | ||
| from lib.fixtures import * # NOSONAR | ||
| from lib.constants import LETTERS_ENDPOINT | ||
| from lib.generators import Generators | ||
| from lib.errorhandler import ErrorHandler | ||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
|
|
||
| def test_200_get_letter_status(url, bearer_token): | ||
|
|
||
| headers = Generators.generate_valid_headers(bearer_token.value) | ||
| get_letter_id = requests.get(f"{url}/{LETTERS_ENDPOINT}/", headers=headers) | ||
|
|
||
| letter_id = get_letter_id.json().get("data")[0].get("id") | ||
| get_letter_data = requests.get(f"{url}/{LETTERS_ENDPOINT}/{letter_id}/data", headers=headers) | ||
|
|
||
| ErrorHandler.handle_retry(get_letter_data) | ||
| assert get_letter_data.status_code == 200, f"Response: {get_letter_data.status_code}: {get_letter_data.text}" | ||
| assert get_letter_data.headers.get("Content-Type") == "application/pdf" | ||
|
|
||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| def test_404_letter_does_not_exist(url, bearer_token): | ||
|
|
||
| headers = Generators.generate_valid_headers(bearer_token.value) | ||
| get_message_response = requests.get(f"{url}/{LETTERS_ENDPOINT}/xx", headers=headers) | ||
|
|
||
| ErrorHandler.handle_retry(get_message_response) | ||
| assert get_message_response.status_code == 404 | ||
| assert get_message_response.json().get("errors")[0].get("detail") == "No resource found with that ID" | ||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| def test_404_letter_does_not_exist(url, bearer_token): | ||
|
|
||
| letter_id = uuid.uuid4().hex | ||
| headers = Generators.generate_valid_headers(bearer_token.value) | ||
| get_message_response = requests.get(f"{url}/{LETTERS_ENDPOINT}/{letter_id}/data", headers=headers) | ||
|
|
||
| ErrorHandler.handle_retry(get_message_response) | ||
| assert get_message_response.status_code == 404 | ||
| assert get_message_response.json().get("errors")[0].get("detail") == "No resource found with that ID" | ||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| def test_500_letter_does_not_exist(url, bearer_token): | ||
|
|
||
| letter_id = "00000000-0000-0000-0000-000000000000" | ||
| headers = Generators.generate_valid_headers(bearer_token.value) | ||
| get_message_response = requests.get(f"{url}/{LETTERS_ENDPOINT}/{letter_id}/data", headers=headers) | ||
|
|
||
| ErrorHandler.handle_retry(get_message_response) | ||
| assert get_message_response.status_code == 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import requests | ||
| import pytest | ||
| from lib.fixtures import * # NOSONAR | ||
| from lib.constants import VALID_ENDPOINT_LETTERS, MI_ENDPOINT | ||
| from lib.generators import Generators | ||
|
|
||
| METHODS = ["get", "post"] | ||
|
|
||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| @pytest.mark.parametrize("method", METHODS) | ||
| @pytest.mark.parametrize("endpoints", VALID_ENDPOINT_LETTERS) | ||
| def test_header_letters_endpoint( | ||
| url, | ||
| method, | ||
| endpoints, | ||
| bearer_token | ||
| ): | ||
| resp = getattr(requests, method)(f"{url}/{endpoints}", headers={ | ||
| "Authorization": bearer_token.value, | ||
| "X-Request-ID": None | ||
| }) | ||
|
|
||
| assert resp.status_code == 500 | ||
|
|
||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| def test_header_mi_endpoint( | ||
| url, | ||
| bearer_token | ||
| ): | ||
| resp = getattr(requests, "post")(f"{url}/{MI_ENDPOINT}", headers={ | ||
| "Authorization": bearer_token.value, | ||
| "X-Request-ID": "" | ||
| }) | ||
|
|
||
| assert resp.status_code == 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import requests | ||
| import pytest | ||
| from lib.fixtures import * # NOSONAR | ||
| from lib.constants import LETTERS_ENDPOINT | ||
| from lib.generators import Generators | ||
| from lib.errorhandler import ErrorHandler | ||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
|
|
||
| def test_200_get_letter_status(url, bearer_token): | ||
|
|
||
| headers = Generators.generate_valid_headers(bearer_token.value) | ||
| get_letters = requests.get(f"{url}/{LETTERS_ENDPOINT}/", headers=headers) | ||
|
|
||
| letter_id = get_letters.json().get("data")[0].get("id") | ||
| get_message_response = requests.get(f"{url}/{LETTERS_ENDPOINT}/{letter_id}", headers=headers) | ||
|
|
||
| ErrorHandler.handle_retry(get_message_response) | ||
| assert get_message_response.status_code == 200, f"Response: {get_message_response.status_code}: {get_message_response.text}" | ||
|
|
||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| def test_404_letter_does_not_exist(url, bearer_token): | ||
|
|
||
| headers = Generators.generate_valid_headers(bearer_token.value) | ||
| get_message_response = requests.get(f"{url}/{LETTERS_ENDPOINT}/xx", headers=headers) | ||
|
|
||
| ErrorHandler.handle_retry(get_message_response) | ||
| assert get_message_response.status_code == 404, f"Response: {get_message_response.status_code}: {get_message_response.text}" | ||
| assert get_message_response.json().get("errors")[0].get("detail") == "No resource found with that ID" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import requests | ||
| import pytest | ||
| from lib.fixtures import * # NOSONAR | ||
| from lib.constants import LETTERS_ENDPOINT | ||
| from lib.generators import Generators | ||
| from lib.errorhandler import ErrorHandler | ||
|
|
||
| @pytest.mark.test | ||
| @pytest.mark.devtest | ||
| @pytest.mark.inttest | ||
| @pytest.mark.prodtest | ||
| def test_200_get_letters(url, bearer_token): | ||
|
|
||
| headers = Generators.generate_valid_headers(bearer_token.value) | ||
|
|
||
| get_message_response = requests.get(f"{url}/{LETTERS_ENDPOINT}?limit=1", headers=headers) | ||
|
|
||
| ErrorHandler.handle_retry(get_message_response) | ||
| assert get_message_response.status_code == 200, f"Response: {get_message_response.status_code}: {get_message_response.text}" | ||
| assert get_message_response.json().get("data")[0].get("attributes").get("status") == "PENDING" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can get access to Prod APIGEE (certainly easy) so for INT and higher, I've been using hte developer onboarding portal: https://identity.prod.api.platform.nhs.uk/ covers like like environment like INT and PROD