Skip to content

Commit 7a2a83a

Browse files
authored
Enhance Search API tests by including patient identifier and target-disease system in scenarios (#1312)
- Updated scenarios in search.feature to specify patient identifier system and target-disease system for clarity. - Modified test_search_steps.py to accept parameters for patient identifier and target-disease system in relevant step definitions, improving flexibility and maintainability of the tests.
1 parent 7697e82 commit 7a2a83a

2 files changed

Lines changed: 28 additions & 21 deletions

File tree

tests/e2e_automation/features/APITests/search.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,26 +328,26 @@ Feature: Search the immunization of a patient
328328

329329
@supplier_name_SONAR
330330
Scenario: Verify that Search API returns 403 when target-disease resolves only to vaccine types supplier is not authorised for
331-
When Send a search request with GET method using target-disease for Immunization event created with valid NHS Number
331+
When Send a search request with GET method using target-disease for Immunization event created with valid NHS Number and patient identifier system 'https://fhir.nhs.uk/Id/nhs-number' and target-disease system 'http://snomed.info/sct'
332332
Then The request will be unsuccessful with the status code '403'
333333
And The Response JSONs should contain correct error message for 'unauthorized_access' access
334334

335335
@supplier_name_Postman_Auth
336336
Scenario: Verify that Search API returns 400 when all target-disease values are invalid SNOMED codes
337-
When Send a search request with 'GET' method with valid NHS Number and all invalid target-disease codes
337+
When Send a search request with 'GET' method with valid NHS Number and all invalid target-disease codes using patient identifier system 'https://fhir.nhs.uk/Id/nhs-number'
338338
Then The request will be unsuccessful with the status code '400'
339339
And The Response JSONs should contain correct error message for invalid target-disease codes
340-
When Send a search request with 'POST' method with valid NHS Number and all invalid target-disease codes
340+
When Send a search request with 'POST' method with valid NHS Number and all invalid target-disease codes using patient identifier system 'https://fhir.nhs.uk/Id/nhs-number'
341341
Then The request will be unsuccessful with the status code '400'
342342
And The Response JSONs should contain correct error message for invalid target-disease codes
343343

344344
@smoke
345345
@Delete_cleanUp @supplier_name_Postman_Auth
346346
Scenario: Verify that Search API returns 200 with results and OperationOutcome when some target-disease values are invalid
347347
Given Valid vaccination record is created with Patient 'Random' and vaccine_type '6IN1'
348-
When Send a search request with 'GET' method using mixed valid and invalid target-disease codes for Immunization event created
348+
When Send a search request with 'GET' method using mixed valid and invalid target-disease codes for Immunization event created with target-disease system 'http://snomed.info/sct' and invalid target-disease code '99999'
349349
Then The request will be successful with the status code '200'
350350
And The Search Response should contain search results and OperationOutcome for invalid target-disease codes
351-
When Send a search request with 'POST' method using mixed valid and invalid target-disease codes for Immunization event created
351+
When Send a search request with 'POST' method using mixed valid and invalid target-disease codes for Immunization event created with target-disease system 'http://snomed.info/sct' and invalid target-disease code '99999'
352352
Then The request will be successful with the status code '200'
353353
And The Search Response should contain search results and OperationOutcome for invalid target-disease codes

tests/e2e_automation/features/APITests/steps/test_search_steps.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424

2525
scenarios("APITests/search.feature")
2626

27-
TARGET_DISEASE_SYSTEM = "http://snomed.info/sct"
28-
INVALID_TARGET_DISEASE_CODE = "99999"
29-
PATIENT_IDENTIFIER_SYSTEM = "https://fhir.nhs.uk/Id/nhs-number"
30-
3127

3228
@when("I send a search request with Post method using identifier parameter for Immunization event created")
3329
def send_search_post_request_with_identifier_header(context):
@@ -144,40 +140,47 @@ def send_search_post_with_target_disease_and_dates(context):
144140
trigger_search_request_by_httpMethod(context, httpMethod="POST")
145141

146142

147-
@when("Send a search request with GET method using target-disease for Immunization event created with valid NHS Number")
148-
def send_search_get_with_target_disease_unauthorised_supplier(context):
143+
@when(
144+
parsers.parse(
145+
"Send a search request with GET method using target-disease for Immunization event created with valid NHS Number and patient identifier system '{patient_identifier_system}' and target-disease system '{target_disease_system}'"
146+
)
147+
)
148+
def send_search_get_with_target_disease_unauthorised_supplier(context, patient_identifier_system, target_disease_system):
149149
nhs_number = "9000000009"
150150
context.params = {
151-
"patient.identifier": f"{PATIENT_IDENTIFIER_SYSTEM}|{nhs_number}",
152-
"target-disease": f"{TARGET_DISEASE_SYSTEM}|14189004",
151+
"patient.identifier": f"{patient_identifier_system}|{nhs_number}",
152+
"target-disease": f"{target_disease_system}|14189004",
153153
}
154154
trigger_search_request_by_httpMethod(context, httpMethod="GET")
155155

156156

157157
@when(
158158
parsers.parse(
159-
"Send a search request with '{httpMethod}' method with valid NHS Number and all invalid target-disease codes"
159+
"Send a search request with '{httpMethod}' method with valid NHS Number and all invalid target-disease codes using patient identifier system '{patient_identifier_system}'"
160160
)
161161
)
162-
def send_search_request_with_all_invalid_target_disease_codes(context, httpMethod):
162+
def send_search_request_with_all_invalid_target_disease_codes(context, httpMethod, patient_identifier_system):
163163
context.params = context.request = {
164-
"patient.identifier": f"{PATIENT_IDENTIFIER_SYSTEM}|9000000009",
164+
"patient.identifier": f"{patient_identifier_system}|9000000009",
165165
"target-disease": "invalid-no-pipe,wrong_system|123",
166166
}
167167
trigger_search_request_by_httpMethod(context, httpMethod=httpMethod)
168168

169169

170170
@when(
171171
parsers.parse(
172-
"Send a search request with '{httpMethod}' method using mixed valid and invalid target-disease codes for Immunization event created"
172+
"Send a search request with '{httpMethod}' method using mixed valid and invalid target-disease codes for Immunization event created with target-disease system '{target_disease_system}' and invalid target-disease code '{invalid_target_disease_code}'"
173173
)
174174
)
175-
def send_search_post_with_mixed_valid_and_invalid_target_disease_codes(context, httpMethod):
175+
def send_search_post_with_mixed_valid_and_invalid_target_disease_codes(
176+
context, httpMethod, target_disease_system, invalid_target_disease_code
177+
):
176178
patient_ident = context.create_object.contained[1].identifier[0]
177179
target = context.create_object.protocolApplied[0].targetDisease[0].coding[0]
180+
context.invalid_target_disease_code = invalid_target_disease_code
178181
context.params = context.request = {
179182
"patient.identifier": f"{patient_ident.system}|{patient_ident.value}",
180-
"target-disease": f"{target.system}|{target.code},{TARGET_DISEASE_SYSTEM}|{INVALID_TARGET_DISEASE_CODE}",
183+
"target-disease": f"{target.system}|{target.code},{target_disease_system}|{invalid_target_disease_code}",
181184
}
182185
trigger_search_request_by_httpMethod(context, httpMethod=httpMethod)
183186

@@ -499,15 +502,19 @@ def validate_invalid_target_disease_codes_error(context):
499502
def validate_search_response_with_invalid_target_disease_operation_outcome(context):
500503
issue = read_issue_from_response(context)
501504
diagnostics = issue.get("diagnostics", "")
505+
invalid_target_disease_code = getattr(context, "invalid_target_disease_code", None)
502506
assert issue.get("code") == "invalid", f"issue code should be 'invalid', got '{issue.get('code')}'"
503507
assert "Target disease code" in diagnostics, (
504508
f"issue diagnostics should mention 'Target disease code', got '{diagnostics}'"
505509
)
506510
assert "not a supported target disease in this service" in diagnostics, (
507511
f"issue diagnostics should mention unsupported target disease, got '{diagnostics}'"
508512
)
509-
assert INVALID_TARGET_DISEASE_CODE in diagnostics, (
510-
f"issue diagnostics should contain invalid target disease code '{INVALID_TARGET_DISEASE_CODE}', got '{diagnostics}'"
513+
assert invalid_target_disease_code is not None, (
514+
"invalid target disease code was not set by the scenario step before assertion"
515+
)
516+
assert invalid_target_disease_code in diagnostics, (
517+
f"issue diagnostics should contain invalid target disease code '{invalid_target_disease_code}', got '{diagnostics}'"
511518
)
512519

513520

0 commit comments

Comments
 (0)