diff --git a/tests/e2e_automation/.env.example.static b/tests/e2e_automation/.env.example.static index ec373c1b4..96466dd79 100644 --- a/tests/e2e_automation/.env.example.static +++ b/tests/e2e_automation/.env.example.static @@ -1,60 +1,60 @@ -aws_token_refresh=True -USE_STATIC_APPS=True - -########## INT env variables -# baseUrl=https://int.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4 -# auth_url=https://int.api.service.nhs.uk/oauth2-mock/authorize -# token_url=https://int.api.service.nhs.uk/oauth2-mock/token -# callback_url=https://oauth.pstmn.io/v1/callback -# S3_env=int -# aws_profile_name={your-aws-profile} -# PROXY_NAME=immunisation-fhir-api-int -## Id/Secret values - please contact Dev or Test team to get these values -# username= -# scope= -# STATUS_API_KEY= -# AWS_DOMAIN_NAME= -# Postman_Auth_client_Id= -# Postman_Auth_client_Secret= -# RAVS_client_Id= -# RAVS_client_Secret= -# MAVIS_client_Id= -# MAVIS_client_Secret= -# EMIS_client_Id= -# EMIS_client_Secret= -# SONAR_client_Id= -# SONAR_client_Secret= -# TPP_client_Id= -# TPP_client_Secret= -# MEDICUS_client_Id= -# MEDICUS_client_Secret= - -########## Internal-QA env variables -baseUrl=https://internal-qa.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4 -auth_url=https://internal-qa.api.service.nhs.uk/oauth2-mock/authorize -token_url=https://internal-qa.api.service.nhs.uk/oauth2-mock/token -callback_url=https://oauth.pstmn.io/v1/callback -S3_env=internal-qa -aws_profile_name={your-aws-profile} -PROXY_NAME=immunisation-fhir-api-internal-qa -# This will only not match S3_env in preprod, where we have a blue/green environment -SUB_ENVIRONMENT=internal-qa -## Id/Secret values - please contact Dev or Test team to get these values -username= -scope= -STATUS_API_KEY= -AWS_DOMAIN_NAME= -Postman_Auth_client_Id= -Postman_Auth_client_Secret= -RAVS_client_Id= -RAVS_client_Secret= -MAVIS_client_Id= -MAVIS_client_Secret= -EMIS_client_Id= -EMIS_client_Secret= -SONAR_client_Id= -SONAR_client_Secret= -TPP_client_Id= -TPP_client_Secret= -MEDICUS_client_Id= -MEDICUS_client_Secret= +aws_token_refresh=True +USE_STATIC_APPS=True + +########## INT env variables +# baseUrl=https://int.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4 +# auth_url=https://int.api.service.nhs.uk/oauth2-mock/authorize +# token_url=https://int.api.service.nhs.uk/oauth2-mock/token +# callback_url=https://oauth.pstmn.io/v1/callback +# S3_env=int +# aws_profile_name={your-aws-profile} +# PROXY_NAME=immunisation-fhir-api-int +## Id/Secret values - please contact Dev or Test team to get these values +# username= +# scope= +# STATUS_API_KEY= +# AWS_DOMAIN_NAME= +# Postman_Auth_client_Id= +# Postman_Auth_client_Secret= +# RAVS_client_Id= +# RAVS_client_Secret= +# MAVIS_client_Id= +# MAVIS_client_Secret= +# EMIS_client_Id= +# EMIS_client_Secret= +# SONAR_client_Id= +# SONAR_client_Secret= +# TPP_client_Id= +# TPP_client_Secret= +# MEDICUS_client_Id= +# MEDICUS_client_Secret= + +########## Internal-QA env variables +baseUrl=https://internal-qa.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4 +auth_url=https://internal-qa.api.service.nhs.uk/oauth2-mock/authorize +token_url=https://internal-qa.api.service.nhs.uk/oauth2-mock/token +callback_url=https://oauth.pstmn.io/v1/callback +S3_env=internal-qa +aws_profile_name={your-aws-profile} +PROXY_NAME=immunisation-fhir-api-internal-qa +# This will only not match S3_env in preprod, where we have a blue/green environment +SUB_ENVIRONMENT=internal-qa +## Id/Secret values - please contact Dev or Test team to get these values +username= +scope= +STATUS_API_KEY= +AWS_DOMAIN_NAME= +Postman_Auth_client_Id= +Postman_Auth_client_Secret= +RAVS_client_Id= +RAVS_client_Secret= +MAVIS_client_Id= +MAVIS_client_Secret= +EMIS_client_Id= +EMIS_client_Secret= +SONAR_client_Id= +SONAR_client_Secret= +TPP_client_Id= +TPP_client_Secret= +MEDICUS_client_Id= +MEDICUS_client_Secret= diff --git a/tests/e2e_automation/features/APITests/search.feature b/tests/e2e_automation/features/APITests/search.feature index 5a760147e..92ed31cc9 100644 --- a/tests/e2e_automation/features/APITests/search.feature +++ b/tests/e2e_automation/features/APITests/search.feature @@ -4,7 +4,7 @@ Feature: Search the immunization of a patient @Delete_cleanUp @supplier_name_TPP Scenario Outline: Verify that the GET method of Search API will be successful with all the valid parameters Given Valid vaccination record is created with Patient '' and vaccine_type '' - When Send a search request with GET method for Immunization event created + When Send a search request with 'GET' method for Immunization event created Then The request will be successful with the status code '200' And The Search Response JSONs should contain the detail of the immunization events created above And The Search Response JSONs field values should match with the input JSONs field values for resourceType Immunization @@ -28,7 +28,7 @@ Feature: Search the immunization of a patient @Delete_cleanUp @supplier_name_EMIS Scenario Outline: Verify that the POST method of Search API will be successful with all the valid parameters Given Valid vaccination record is created with Patient '' and vaccine_type '' - When Send a search request with POST method for Immunization event created + When Send a search request with 'POST' method for Immunization event created Then The request will be successful with the status code '200' And The Search Response JSONs should contain the detail of the immunization events created above And The Search Response JSONs field values should match with the input JSONs field values for resourceType Immunization @@ -49,10 +49,10 @@ Feature: Search the immunization of a patient @Delete_cleanUp @supplier_name_Postman_Auth Scenario Outline: Verify that the immunization events retrieved in the response of Search API should be within Date From and Date To range Given Valid vaccination record is created for '' and Disease Type '' with recorded date as '' - When Send a search request with GET method with valid NHS Number '' and Disease Type '' and Date From '' and Date To '' + When Send a search request with 'GET' method with valid NHS Number '' and Disease Type '' and Date From '' and Date To '' Then The request will be successful with the status code '200' And The occurrenceDateTime of the immunization events should be within the Date From and Date To range - When Send a search request with POST method with valid NHS Number '' and Disease Type '' and Date From '' and Date To '' + When Send a search request with 'POST' method with valid NHS Number '' and Disease Type '' and Date From '' and Date To '' Then The request will be successful with the status code '200' And The occurrenceDateTime of the immunization events should be within the Date From and Date To range Examples: @@ -62,10 +62,10 @@ Feature: Search the immunization of a patient # Negative Scenarios @supplier_name_Postman_Auth Scenario Outline: Verify that Search API will throw error if NHS Number is invalid - When Send a search request with GET method with invalid NHS Number '' and valid Disease Type '' + When Send a search request with 'GET' method with invalid NHS Number '' and valid Disease Type '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid NHS Number - When Send a search request with POST method with invalid NHS Number '' and valid Disease Type '' + When Send a search request with 'POST' method with invalid NHS Number '' and valid Disease Type '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid NHS Number Examples: @@ -78,10 +78,10 @@ Feature: Search the immunization of a patient @smoke @supplier_name_Postman_Auth Scenario Outline: Verify that Search API will throw error if include is invalid - When Send a search request with GET method with valid NHS Number '' and valid Disease Type '' and invalid include '' + When Send a search request with 'GET' method with valid NHS Number '' and valid Disease Type '' and invalid include '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid include - When Send a search request with POST method with valid NHS Number '' and valid Disease Type '' and invalid include '' + When Send a search request with 'POST' method with valid NHS Number '' and valid Disease Type '' and invalid include '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid include Examples: @@ -91,10 +91,10 @@ Feature: Search the immunization of a patient @smoke @supplier_name_Postman_Auth Scenario Outline: Verify that Search API will throw error if both different combination of dates and include is invalid - When Send a search request with GET method with valid NHS Number '' and valid Disease Type '' and Date From '' and Date To '' and include '' + When Send a search request with 'GET' method with valid NHS Number '' and valid Disease Type '' and Date From '' and Date To '' and include '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date From, Date To and include - When Send a search request with POST method with valid NHS Number '' and valid Disease Type '' and Date From '' and Date To '' and include '' + When Send a search request with 'POST' method with valid NHS Number '' and valid Disease Type '' and Date From '' and Date To '' and include '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date From, Date To and include Examples: @@ -107,10 +107,10 @@ Feature: Search the immunization of a patient @smoke @supplier_name_Postman_Auth Scenario Outline: Verify that Search API will throw error if Disease Type is invalid - When Send a search request with GET method with valid NHS Number '' and invalid Disease Type '' + When Send a search request with 'GET' method with valid NHS Number '' and invalid Disease Type '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Disease Type - When Send a search request with POST method with valid NHS Number '' and invalid Disease Type '' + When Send a search request with 'POST' method with valid NHS Number '' and invalid Disease Type '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Disease Type Examples: @@ -121,10 +121,10 @@ Feature: Search the immunization of a patient @supplier_name_Postman_Auth Scenario Outline: Verify that Search API will throw error if both NHS Number and Disease Type are invalid - When Send a search request with GET method with invalid NHS Number '' and invalid Disease Type '' + When Send a search request with 'GET' method with invalid NHS Number '' and invalid Disease Type '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid NHS Number as higher priority - When Send a search request with POST method with invalid NHS Number '' and invalid Disease Type '' + When Send a search request with 'POST' method with invalid NHS Number '' and invalid Disease Type '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid NHS Number as higher priority Examples: @@ -136,19 +136,31 @@ Feature: Search the immunization of a patient @Delete_cleanUp @supplier_name_Postman_Auth Scenario: Verify that Search API returns 200 with results and OperationOutcome when both valid and invalid Disease Type are provided Given Valid vaccination record is created with Patient 'Random' and vaccine_type 'COVID' - When Send a search request with GET method with valid NHS Number and mixed valid and invalid Disease Type + When Send a search request with 'GET' method with valid NHS Number and mixed valid and invalid Disease Type Then The request will be successful with the status code '200' And The Search Response should contain search results and OperationOutcome for invalid immunization targets - When Send a search request with POST method with valid NHS Number and mixed valid and invalid Disease Type + When Send a search request with 'POST' method with valid NHS Number and mixed valid and invalid Disease Type Then The request will be successful with the status code '200' And The Search Response should contain search results and OperationOutcome for invalid immunization targets + @smoke + @Delete_cleanUp @supplier_name_MAVIS + Scenario: Verify that Search API returns 200 with results and OperationOutcome with authorized and unauthorized Disease Type for the supplier + Given Valid vaccination record is created with Patient 'Random' and vaccine_type 'FLU' + When Send a search request with 'GET' method with valid NHS Number and multiple Disease Type + Then The request will be successful with the status code '200' + And The Search Response should contain search results and OperationOutcome for unauthorized immunization targets + When Send a search request with 'POST' method with valid NHS Number and multiple Disease Type + Then The request will be successful with the status code '200' + And The Search Response should contain search results and OperationOutcome for unauthorized immunization targets + + @supplier_name_MAVIS @vaccine_type_RSV Scenario Outline: Verify that Search API will throw error if date from is invalid - When Send a search request with GET method with invalid Date From '' and valid Date To '' + When Send a search request with 'GET' method with invalid Date From '' and valid Date To '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date From - When Send a search request with POST method with invalid Date From '' and valid Date To '' + When Send a search request with 'POST' method with invalid Date From '' and valid Date To '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date From Examples: @@ -159,10 +171,10 @@ Feature: Search the immunization of a patient @supplier_name_RAVS @vaccine_type_RSV Scenario Outline: Verify that Search API will throw error if date to is invalid - When Send a search request with GET method with valid Date From '' and invalid Date To '' + When Send a search request with 'GET' method with valid Date From '' and invalid Date To '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date To - When Send a search request with POST method with valid Date From '' and invalid Date To '' + When Send a search request with 'POST' method with valid Date From '' and invalid Date To '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date To Examples: @@ -173,10 +185,10 @@ Feature: Search the immunization of a patient @supplier_name_MAVIS @vaccine_type_RSV Scenario Outline: Verify that Search API will throw error if both date from and date to are invalid - When Send a search request with GET method with invalid Date From '' and invalid Date To '' + When Send a search request with 'GET' method with invalid Date From '' and invalid Date To '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date From - When Send a search request with POST method with invalid Date From '' and invalid Date To '' + When Send a search request with 'POST' method with invalid Date From '' and invalid Date To '' Then The request will be unsuccessful with the status code '400' And The Search Response JSONs should contain correct error message for invalid Date From Examples: @@ -188,10 +200,10 @@ Feature: Search the immunization of a patient @smoke @supplier_name_SONAR Scenario Outline: Verify that Search API will throw error supplier is not authorized to make Search - When Send a search request with GET method with invalid NHS Number '' and valid Disease Type '' + When Send a search request with 'GET' method with invalid NHS Number '' and valid Disease Type '' Then The request will be unsuccessful with the status code '403' And The Response JSONs should contain correct error message for 'unauthorized_access' access - When Send a search request with POST method with invalid NHS Number '' and valid Disease Type '' + When Send a search request with 'POST' method with invalid NHS Number '' and valid Disease Type '' Then The request will be unsuccessful with the status code '403' And The Response JSONs should contain correct error message for 'unauthorized_access' access Examples: @@ -203,7 +215,7 @@ Feature: Search the immunization of a patient Scenario: Flu event is created and updated twice and search request fetch the latest meta version and Etag Given I have created a valid vaccination record And created event is being updated twice - When Send a search request with GET method for Immunization event created + When Send a search request with 'GET' method for Immunization event created Then The request will be successful with the status code '200' And The Search Response JSONs should contain the detail of the immunization events created above And The Search Response JSONs field values should match with the input JSONs field values for resourceType Immunization diff --git a/tests/e2e_automation/features/APITests/steps/test_delete_steps.py b/tests/e2e_automation/features/APITests/steps/test_delete_steps.py index e2a36a862..f9deed5f2 100644 --- a/tests/e2e_automation/features/APITests/steps/test_delete_steps.py +++ b/tests/e2e_automation/features/APITests/steps/test_delete_steps.py @@ -6,7 +6,10 @@ fetch_immunization_int_delta_detail_by_immsID, validate_imms_delta_record_with_created_event, ) -from utilities.api_fhir_immunization_helper import find_entry_by_Imms_id, parse_FHIR_immunization_response +from utilities.api_fhir_immunization_helper import ( + find_entry_by_Imms_id, + parse_FHIR_immunization_response, +) from utilities.api_get_header import get_delete_url_header from utilities.enums import ActionFlag, Operation from utilities.http_requests_session import http_requests_session @@ -16,7 +19,7 @@ send_delete_for_immunization_event_created, valid_token_is_generated, ) -from .test_search_steps import TriggerSearchGetRequest, TriggerSearchPostRequest +from .test_search_steps import trigger_search_request logging.basicConfig(filename="debugLog.log", level=logging.INFO) logger = logging.getLogger(__name__) @@ -53,13 +56,17 @@ def validate_imms_delta_table_by_deleted_ImmsID(context): latest_delta_record = max(deleted_items, key=lambda x: x.get("timestamp", 0)) validate_imms_delta_record_with_created_event( - context, create_obj, latest_delta_record, Operation.deleted.value, ActionFlag.deleted.value + context, + create_obj, + latest_delta_record, + Operation.deleted.value, + ActionFlag.deleted.value, ) @then("Deleted Immunization event will not be present in Get method Search API response") def validate_deleted_immunization_event_not_present(context): - TriggerSearchGetRequest(context) + trigger_search_request(context, httpMethod="GET") The_request_will_have_status_code(context, "200") data = context.response.json() @@ -74,7 +81,7 @@ def validate_deleted_immunization_event_not_present(context): @then("Deleted Immunization event will not be present in Post method Search API response") def validate_deleted_immunization_event_not_present_using_post(context): - TriggerSearchPostRequest(context) + trigger_search_request(context, httpMethod="POST") The_request_will_have_status_code(context, "200") data = context.response.json() diff --git a/tests/e2e_automation/features/APITests/steps/test_search_steps.py b/tests/e2e_automation/features/APITests/steps/test_search_steps.py index c4d1de802..919f735d8 100644 --- a/tests/e2e_automation/features/APITests/steps/test_search_steps.py +++ b/tests/e2e_automation/features/APITests/steps/test_search_steps.py @@ -22,263 +22,156 @@ @when("I send a search request with Post method using identifier parameter for Immunization event created") def send_search_post_request_with_identifier_header(context): - get_search_post_url_header(context) context.request = { "identifier": f"{context.create_object.identifier[0].system}|{context.create_object.identifier[0].value}" } - print(f"\n Search Post Request - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) + trigger_search_request_by_httpMethod(context, httpMethod="POST") @when( "I send a search request with Post method using identifier and _elements parameters for Immunization event created" ) def send_search_post_request_with_identifier_and_elements_header(context): - get_search_post_url_header(context) context.request = { "identifier": f"{context.create_object.identifier[0].system}|{context.create_object.identifier[0].value}", "_elements": "meta,id", } - print(f"\n Search Post Request - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) + trigger_search_request_by_httpMethod(context, httpMethod="POST") @when("I send a search request with Post method using an invalid identifier header for Immunization event created") def send_search_post_request_with_invalid_identifier_header(context): - get_search_post_url_header(context) - context.request = {"identifier": f"https://www.ieds.england.nhs.uk/|{str(uuid.uuid4())}", "_elements": "meta,id"} - print(f"\n Search Post Request - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) + context.request = { + "identifier": f"https://www.ieds.england.nhs.uk/|{str(uuid.uuid4())}", + "_elements": "meta,id", + } + trigger_search_request_by_httpMethod(context, httpMethod="POST") -@when("Send a search request with GET method for Immunization event created") -def TriggerSearchGetRequest(context): - get_search_get_url_header(context) - context.params = convert_to_form_data( +@when(parsers.parse("Send a search request with '{httpMethod}' method for Immunization event created")) +def trigger_search_request(context, httpMethod): + context.params = context.request = convert_to_form_data( set_request_data( - context.patient.identifier[0].value, context.vaccine_type, datetime.today().strftime("%Y-%m-%d") + context.patient.identifier[0].value, + context.vaccine_type, + datetime.today().strftime("%Y-%m-%d"), ) ) - print(f"\n Search Get Parameters - \n {context.params}") - context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) - print(f"\n Search Get Response - \n {context.response.json()}") + trigger_search_request_by_httpMethod(context, httpMethod=httpMethod) -@when("Send a search request with POST method for Immunization event created") -def TriggerSearchPostRequest(context): - get_search_post_url_header(context) - context.request = convert_to_form_data( - set_request_data( - context.patient.identifier[0].value, context.vaccine_type, datetime.today().strftime("%Y-%m-%d") - ) +@when( + parsers.parse( + "Send a search request with '{httpMethod}' method with valid NHS Number and mixed valid and invalid Disease Type" ) - print(f"\n Search Post Request - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) - print(f"\n Search Post Response - \n {context.response.json()}") - - -@when("Send a search request with GET method with valid NHS Number and mixed valid and invalid Disease Type") -def send_search_get_with_mixed_targets(context): - get_search_get_url_header(context) +) +def send_search_request_with_mixed_targets(context, httpMethod): mixed_target = f"{context.vaccine_type},INVALID_TYPE" - context.params = convert_to_form_data( + context.params = context.request = convert_to_form_data( set_request_data( context.patient.identifier[0].value, mixed_target, datetime.today().strftime("%Y-%m-%d"), ) ) - print(f"\n Search Get Parameters (mixed targets) - \n {context.params}") - context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) + trigger_search_request_by_httpMethod(context, httpMethod) -@when("Send a search request with POST method with valid NHS Number and mixed valid and invalid Disease Type") -def send_search_post_with_mixed_targets(context): - get_search_post_url_header(context) - mixed_target = f"{context.vaccine_type},INVALID_TYPE" - context.request = convert_to_form_data( +@when(parsers.parse("Send a search request with '{httpMethod}' method with valid NHS Number and multiple Disease Type")) +def send_search_post_with_mixed_valid_unauthorized_targets(context, httpMethod): + mixed_target = f"{context.vaccine_type},6IN1" + context.params = context.request = convert_to_form_data( set_request_data( context.patient.identifier[0].value, mixed_target, datetime.today().strftime("%Y-%m-%d"), ) ) - print(f"\n Search Post Request (mixed targets) - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) + trigger_search_request_by_httpMethod(context, httpMethod) @when( parsers.parse( - "Send a search request with GET method with invalid NHS Number '{NHSNumber}' and valid Disease Type '{DiseaseType}'" + "Send a search request with '{httpMethod}' method with invalid NHS Number '{NHSNumber}' and valid Disease Type '{DiseaseType}'" ) ) @when( parsers.parse( - "Send a search request with GET method with valid NHS Number '{NHSNumber}' and invalid Disease Type '{DiseaseType}'" + "Send a search request with '{httpMethod}' method with valid NHS Number '{NHSNumber}' and invalid Disease Type '{DiseaseType}'" ) ) @when( parsers.parse( - "Send a search request with GET method with invalid NHS Number '{NHSNumber}' and invalid Disease Type '{DiseaseType}'" + "Send a search request with '{httpMethod}' method with invalid NHS Number '{NHSNumber}' and invalid Disease Type '{DiseaseType}'" ) ) -def send_invalid_param_get_request(context, NHSNumber, DiseaseType): - get_search_get_url_header(context) +def send_invalid_param_get_request(context, httpMethod, NHSNumber, DiseaseType): NHSNumber = normalize_param(NHSNumber) DiseaseType = normalize_param(DiseaseType) - context.params = convert_to_form_data( + context.params = context.request = convert_to_form_data( set_request_data(NHSNumber, DiseaseType, datetime.today().strftime("%Y-%m-%d")) ) - print(f"\n Search Get parameters - \n {context.params}") - context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) - - -@when( - parsers.parse( - "Send a search request with POST method with invalid NHS Number '{NHSNumber}' and valid Disease Type '{DiseaseType}'" - ) -) -@when( - parsers.parse( - "Send a search request with POST method with valid NHS Number '{NHSNumber}' and invalid Disease Type '{DiseaseType}'" - ) -) -@when( - parsers.parse( - "Send a search request with POST method with invalid NHS Number '{NHSNumber}' and invalid Disease Type '{DiseaseType}'" - ) -) -def send_invalid_param_post_request(context, NHSNumber, DiseaseType): - get_search_post_url_header(context) - - NHSNumber = normalize_param(NHSNumber) - DiseaseType = normalize_param(DiseaseType) - - context.request = convert_to_form_data( - set_request_data(NHSNumber, DiseaseType, datetime.today().strftime("%Y-%m-%d")) - ) - print(f"\n Search Post request - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) - - -@when( - parsers.parse( - "Send a search request with GET method with invalid Date From '{DateFrom}' and valid Date To '{DateTo}'" - ) -) -@when( - parsers.parse( - "Send a search request with GET method with valid Date From '{DateFrom}' and invalid Date To '{DateTo}'" - ) -) -@when( - parsers.parse( - "Send a search request with GET method with invalid Date From '{DateFrom}' and invalid Date To '{DateTo}'" - ) -) -def send_invalid_date_get_request(context, DateFrom, DateTo): - get_search_get_url_header(context) - context.params = convert_to_form_data(set_request_data(9001066569, context.vaccine_type, DateFrom, DateTo)) - print(f"\n Search Get parameters - \n {context.params}") - context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) + trigger_search_request_by_httpMethod(context, httpMethod) @when( parsers.parse( - "Send a search request with POST method with invalid Date From '{DateFrom}' and valid Date To '{DateTo}'" + "Send a search request with '{httpMethod}' method with invalid Date From '{DateFrom}' and valid Date To '{DateTo}'" ) ) @when( parsers.parse( - "Send a search request with POST method with valid Date From '{DateFrom}' and invalid Date To '{DateTo}'" + "Send a search request with '{httpMethod}' method with valid Date From '{DateFrom}' and invalid Date To '{DateTo}'" ) ) @when( parsers.parse( - "Send a search request with POST method with invalid Date From '{DateFrom}' and invalid Date To '{DateTo}'" + "Send a search request with '{httpMethod}' method with invalid Date From '{DateFrom}' and invalid Date To '{DateTo}'" ) ) -def send_invalid_param_post_request_with_dates(context, DateFrom, DateTo): - get_search_post_url_header(context) - context.request = convert_to_form_data(set_request_data(9001066569, context.vaccine_type, DateFrom, DateTo)) - print(f"\n Search Post request - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) - - -@when( - parsers.parse( - "Send a search request with GET method with valid NHS Number '{NHSNumber}' and Disease Type '{vaccine_type}' and Date From '{DateFrom}' and Date To '{DateTo}'" +def send_invalid_date_get_request(context, httpMethod, DateFrom, DateTo): + context.params = context.request = convert_to_form_data( + set_request_data(9001066569, context.vaccine_type, DateFrom, DateTo) ) -) -def send_valid_param_get_request(context, NHSNumber, vaccine_type, DateFrom, DateTo): - get_search_get_url_header(context) - context.params = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, DateFrom, DateTo)) - print(f"\n Search Get parameters - \n {context.params}") - context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) + trigger_search_request_by_httpMethod(context, httpMethod) @when( parsers.parse( - "Send a search request with POST method with valid NHS Number '{NHSNumber}' and Disease Type '{vaccine_type}' and Date From '{DateFrom}' and Date To '{DateTo}'" + "Send a search request with '{httpMethod}' method with valid NHS Number '{NHSNumber}' and Disease Type '{vaccine_type}' and Date From '{DateFrom}' and Date To '{DateTo}'" ) ) -def send_valid_param_post_request(context, NHSNumber, vaccine_type, DateFrom, DateTo): - get_search_post_url_header(context) - context.request = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, DateFrom, DateTo)) - print(f"\n Search Get parameters - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) +def send_valid_param_get_request(context, httpMethod, NHSNumber, vaccine_type, DateFrom, DateTo): + context.params = context.request = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, DateFrom, DateTo)) + trigger_search_request_by_httpMethod(context, httpMethod) @when( parsers.parse( - "Send a search request with GET method with valid NHS Number '{NHSNumber}' and valid Disease Type '{vaccine_type}' and invalid include '{include}'" + "Send a search request with '{httpMethod}' method with valid NHS Number '{NHSNumber}' and valid Disease Type '{vaccine_type}' and invalid include '{include}'" ) ) -def send_valid_param_get_request_with_include(context, NHSNumber, vaccine_type, include): - get_search_get_url_header(context) - context.params = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, include=include)) - print(f"\n Search Get parameters - \n {context.params}") - context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) +def send_valid_param_get_request_with_include(context, httpMethod, NHSNumber, vaccine_type, include): + context.params = context.request = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, include=include)) + trigger_search_request_by_httpMethod(context, httpMethod) @when( parsers.parse( - "Send a search request with POST method with valid NHS Number '{NHSNumber}' and valid Disease Type '{vaccine_type}' and invalid include '{include}'" + "Send a search request with '{httpMethod}' method with valid NHS Number '{NHSNumber}' and valid Disease Type '{vaccine_type}' and Date From '{DateFrom}' and Date To '{DateTo}' and include '{include}'" ) ) -def send_valid_param_post_request_with_include(context, NHSNumber, vaccine_type, include): - get_search_post_url_header(context) - context.request = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, include=include)) - print(f"\n Search Post parameters - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) - - -@when( - parsers.parse( - "Send a search request with POST method with valid NHS Number '{NHSNumber}' and valid Disease Type '{vaccine_type}' and Date From '{DateFrom}' and Date To '{DateTo}' and include '{include}'" +def send_valid_param_get_request_with_include_and_dates( + context, httpMethod, NHSNumber, vaccine_type, DateFrom, DateTo, include +): + context.params = context.request = convert_to_form_data( + set_request_data(NHSNumber, vaccine_type, DateFrom, DateTo, include) ) -) -def send_valid_param_post_request_with_include_and_dates(context, NHSNumber, vaccine_type, DateFrom, DateTo, include): - get_search_post_url_header(context) - context.request = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, DateFrom, DateTo, include)) - print(f"\n Search Post parameters - \n {context.request}") - context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) - - -@when( - parsers.parse( - "Send a search request with GET method with valid NHS Number '{NHSNumber}' and valid Disease Type '{vaccine_type}' and Date From '{DateFrom}' and Date To '{DateTo}' and include '{include}'" - ) -) -def send_valid_param_get_request_with_include_and_dates(context, NHSNumber, vaccine_type, DateFrom, DateTo, include): - get_search_get_url_header(context) - context.params = convert_to_form_data(set_request_data(NHSNumber, vaccine_type, DateFrom, DateTo, include)) - print(f"\n Search Get parameters - \n {context.params}") - context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) + trigger_search_request_by_httpMethod(context, httpMethod) @then("The occurrenceDateTime of the immunization events should be within the Date From and Date To range") -def validateDateRange(context): +def validate_date_range(context): data = context.response.json() context.parsed_search_object = parse_FHIR_immunization_response(data) params = getattr(context, "params", getattr(context, "request", {})) @@ -304,7 +197,7 @@ def validateDateRange(context): @then("The Search Response JSONs should contain the detail of the immunization events created above") -def validateImmsID(context): +def validate_imms_id(context): data = context.response.json() context.parsed_search_object = parse_FHIR_immunization_response(data) assert context.parsed_search_object.resourceType == "Bundle", ( @@ -334,14 +227,14 @@ def validateImmsID(context): @then( "The Search Response JSONs field values should match with the input JSONs field values for resourceType Immunization" ) -def validateJsonImms(context): +def validate_json_imms(context): create_obj = context.create_object created_event = context.created_event.resource validate_to_compare_request_and_response(context, create_obj, created_event) @then("The Search Response JSONs field values should match with the input JSONs field values for resourceType Patient") -def validateJsonPat(context): +def validate_json_patient(context): response_patient_entry = find_patient_by_fullurl(context.parsed_search_object) assert response_patient_entry is not None, f"No Patient found with fullUrl {context.Patient_fullUrl}" response_patient = response_patient_entry.resource @@ -367,7 +260,7 @@ def validate_correct_immunization_event(context): context.created_event = context.parsed_search_object.entry[0] if context.parsed_search_object.entry else None if context.created_event is None: raise AssertionError(f"No object found with Immunisation ID {context.ImmsID} in the search response.") - validateJsonImms(context) + validate_json_imms(context) assert context.parsed_search_object.resourceType == "Bundle", ( f"expected resourceType to be 'Bundle' but got {context.parsed_search_object.resourceType}" ) @@ -423,9 +316,23 @@ def validate_empty_immunization_event(context): @then("The Search Response should contain search results and OperationOutcome for invalid immunization targets") def validate_search_response_with_invalid_targets_operation_outcome(context): + issue = read_issue_from_response(context) + expected_diagnostics = "Your search included invalid -immunization.target value(s) that were ignored: INVALID_TYPE. The search was performed using the valid value(s) only." + validate_issue(issue, expected_code="invalid", expected_diag=expected_diagnostics) + + +@then("The Search Response should contain search results and OperationOutcome for unauthorized immunization targets") +def validate_search_response_with_unauthorized_targets_operation_outcome(context): + issue = read_issue_from_response(context) + expected_diagnostics = "Your search contains details that you are not authorised to request" + validate_issue(issue, expected_code="unauthorized", expected_diag=expected_diagnostics) + + +def read_issue_from_response(context): response = context.response.json() assert response.get("resourceType") == "Bundle", "resourceType should be 'Bundle'" assert response.get("type") == "searchset", "type should be 'searchset'" + entries = response.get("entry", []) assert len(entries) >= 1, "Bundle should contain at least one entry" @@ -438,14 +345,32 @@ def validate_search_response_with_invalid_targets_operation_outcome(context): ), None, ) - assert imms_entry is not None, f"Expected to find Immunization entry with id {context.ImmsID} in search response" + assert imms_entry is not None, f"Expected Immunization entry with id {context.ImmsID} in search response" oo_entries = [e for e in entries if e.get("resource", {}).get("resourceType") == "OperationOutcome"] - assert len(oo_entries) >= 1, "Bundle should contain at least one OperationOutcome entry for invalid targets" - diagnostics = oo_entries[0].get("resource", {}).get("issue", [{}])[0].get("diagnostics", "") - assert "invalid -immunization.target value(s) that were ignored" in diagnostics, ( - f"Expected OperationOutcome diagnostics to mention invalid targets, got: {diagnostics}" - ) - assert "INVALID_TYPE" in diagnostics, ( - f"Expected OperationOutcome diagnostics to mention INVALID_TYPE, got: {diagnostics}" - ) + assert len(oo_entries) >= 1, "Bundle should contain at least one OperationOutcome entry" + + issue = oo_entries[0].get("resource", {}).get("issue", [{}])[0] + + assert issue is not None, "OperationOutcome issue is missing" + + return issue + + +def validate_issue(issue, expected_code, expected_diag): + assert issue.get("severity") == "warning", "issue severity should be 'warning'" + assert issue.get("code") == expected_code, f"issue code should be '{expected_code}'" + assert issue.get("diagnostics") == expected_diag, f"issue diagnostics should be '{expected_diag}'" + + +def trigger_search_request_by_httpMethod(context, httpMethod="GET"): + if httpMethod == "POST": + get_search_post_url_header(context) + print(f"\n Search Post Request - \n {context.request}") + context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) + + else: + get_search_get_url_header(context) + print(f"\n Search {httpMethod} Request - \n {context.params}") + context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) + print(f"\n Search {httpMethod} Response - \n {context.response.json()}")