Skip to content

Commit e1bf8ee

Browse files
authored
VED-1013 Part 2: Add status and ping tests to new automation test framework (#1133)
1 parent 800a275 commit e1bf8ee

5 files changed

Lines changed: 84 additions & 2 deletions

File tree

tests/e2e_automation/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ callback_url=https://oauth.pstmn.io/v1/callback
3131
S3_env=internal-qa
3232
aws_profile_name={your-aws-profile}
3333
## Id/Secret values - please contact Dev or Test team to get these values
34+
STATUS_API_KEY=
35+
AWS_DOMAIN_NAME=
3436
Postman_Auth_client_Id=
3537
Postman_Auth_client_Secret=
3638
RAVS_client_Id=

tests/e2e_automation/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ This directory contains End-to-end Automation Tests for the Immunisation FHIR AP
3131
```
3232
username
3333
scope
34+
STATUS_API_KEY
35+
AWS_DOMAIN_NAME
3436
Postman_Auth_client_Id
3537
Postman_Auth_client_Secret
3638
RAVS_client_Id
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@Status_feature @functional
2+
Feature: Get the API status
3+
4+
@smoke @sandbox @supplier_name_Postman_Auth
5+
Scenario: Verify that the /ping endpoint works
6+
When I send a request to the ping endpoint
7+
Then The request will be successful with the status code '200'
8+
9+
@smoke @sandbox @supplier_name_Postman_Auth
10+
Scenario: Verify that the /status endpoint works
11+
When I send a request to the status endpoint
12+
Then The request will be successful with the status code '200'
13+
And The status response will contain a passing healthcheck
14+
15+
@smoke @supplier_name_Postman_Auth
16+
Scenario: Verify that clients cannot make a direct connection without mTLS to AWS backend
17+
When I send a direct request to the AWS backend
18+
Then The request is rejected
19+
20+
@smoke @supplier_name_Postman_Auth
21+
Scenario: Verify that unauthenticated clients cannot get a successful response from the API
22+
When I send an unauthenticated request to the API
23+
Then The request will be unsuccessful with the status code '401'
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
3+
import pytest
4+
import requests
5+
from pytest_bdd import scenarios, then, when
6+
from utilities.context import ScenarioContext
7+
from utilities.http_requests_session import http_requests_session
8+
9+
scenarios("APITests/status.feature")
10+
11+
CONNECTION_ABORTED_ERROR_MSG = "<ExceptionInfo ConnectionError(ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))) tblen=6>"
12+
13+
14+
@when("I send a request to the ping endpoint")
15+
def send_request_to_ping_endpoint(context: ScenarioContext) -> None:
16+
context.response = http_requests_session.get(context.baseUrl + "/_ping")
17+
18+
19+
@when("I send a request to the status endpoint")
20+
def send_request_status_endpoint(context: ScenarioContext) -> None:
21+
# Let exception be raised if expected env var is not present
22+
status_api_key: str = os.environ["STATUS_API_KEY"]
23+
context.response = http_requests_session.get(context.baseUrl + "/_status", headers={"apikey": status_api_key})
24+
25+
26+
@when("I send a direct request to the AWS backend")
27+
def send_request_to_aws_backend(context: ScenarioContext) -> None:
28+
# Let exception be raised if expected env var is not present
29+
aws_domain_name: str = os.environ["AWS_DOMAIN_NAME"]
30+
backend_status_url = aws_domain_name + "/status"
31+
32+
with pytest.raises(requests.exceptions.ConnectionError) as e:
33+
requests.get(backend_status_url)
34+
35+
context.response = str(e)
36+
37+
38+
@when("I send an unauthenticated request to the API")
39+
def send_unauthenticated_request_to_api(context: ScenarioContext) -> None:
40+
context.response = http_requests_session.get(context.baseUrl + "/Immunization")
41+
42+
43+
@then("The status response will contain a passing healthcheck")
44+
def check_status_response_healthy(context: ScenarioContext) -> None:
45+
status_response = context.response.json()
46+
assertion_failure_msg = f"Status response assertions failed. Res: {status_response}"
47+
48+
assert status_response.get("status") == "pass", assertion_failure_msg
49+
assert status_response.get("checks", {}).get("healthcheck", {}).get("status") == "pass", assertion_failure_msg
50+
51+
52+
@then("The request is rejected")
53+
def check_the_direct_req_is_rejected(context: ScenarioContext) -> None:
54+
assert context.response == CONNECTION_ABORTED_ERROR_MSG, f"got unexpected mTLS error msg: {context.response}"

tests/e2e_automation/pytest.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ addopts = --alluredir output/allure-results
99
markers =
1010
allure.suite: Assigns test to a suite in Allure reports
1111
Create_Feature: tag for create feature tests
12-
Search_Feature: tag for search feature tests
12+
Search_Feature: tag for search feature tests
1313
Delete_Feature: tag for delete feature tests
14+
Read_Feature: tag for read feature tests
15+
Status_Feature: tag for status feature tests
1416
Update_Feature: tag for update feature tests
1517
Create_Batch_Feature: tag for create batch feature tests
1618
Update_Batch_Feature: tag for update batch feature tests
1719
Delete_Batch_Feature: tag for delete batch feature tests
18-
Read_Feature: tag for read feature tests
1920
Delete_cleanUp: tag for scenarios that require cleanup after execution
2021
delete_cleanup_batch: tag for batch scenarios that require cleanup after execution
2122
patient_id_OldNHS: tag for old NHS patient ID scenarios

0 commit comments

Comments
 (0)