|
4 | 4 |
|
5 | 5 | import pytest_check as check |
6 | 6 | from pytest_bdd import parsers, scenarios, then, when |
| 7 | + |
7 | 8 | from src.objectModels.api_search_object import convert_to_form_data, set_request_data |
8 | 9 | from utilities.api_fhir_immunization_helper import ( |
9 | 10 | find_entry_by_Imms_id, |
@@ -77,6 +78,36 @@ def TriggerSearchPostRequest(context): |
77 | 78 | print(f"\n Search Post Response - \n {context.response.json()}") |
78 | 79 |
|
79 | 80 |
|
| 81 | +@when("Send a search request with GET method with valid NHS Number and mixed valid and invalid Disease Type") |
| 82 | +def send_search_get_with_mixed_targets(context): |
| 83 | + get_search_get_url_header(context) |
| 84 | + mixed_target = f"{context.vaccine_type},INVALID_TYPE" |
| 85 | + context.params = convert_to_form_data( |
| 86 | + set_request_data( |
| 87 | + context.patient.identifier[0].value, |
| 88 | + mixed_target, |
| 89 | + datetime.today().strftime("%Y-%m-%d"), |
| 90 | + ) |
| 91 | + ) |
| 92 | + print(f"\n Search Get Parameters (mixed targets) - \n {context.params}") |
| 93 | + context.response = http_requests_session.get(context.url, params=context.params, headers=context.headers) |
| 94 | + |
| 95 | + |
| 96 | +@when("Send a search request with POST method with valid NHS Number and mixed valid and invalid Disease Type") |
| 97 | +def send_search_post_with_mixed_targets(context): |
| 98 | + get_search_post_url_header(context) |
| 99 | + mixed_target = f"{context.vaccine_type},INVALID_TYPE" |
| 100 | + context.request = convert_to_form_data( |
| 101 | + set_request_data( |
| 102 | + context.patient.identifier[0].value, |
| 103 | + mixed_target, |
| 104 | + datetime.today().strftime("%Y-%m-%d"), |
| 105 | + ) |
| 106 | + ) |
| 107 | + print(f"\n Search Post Request (mixed targets) - \n {context.request}") |
| 108 | + context.response = http_requests_session.post(context.url, headers=context.headers, data=context.request) |
| 109 | + |
| 110 | + |
80 | 111 | @when( |
81 | 112 | parsers.parse( |
82 | 113 | "Send a search request with GET method with invalid NHS Number '{NHSNumber}' and valid Disease Type '{DiseaseType}'" |
@@ -389,3 +420,33 @@ def validate_empty_immunization_event(context): |
389 | 420 | f"link[0].url should be '{context.baseUrl}/Immunization?identifier=None', got '{link_url}'" |
390 | 421 | ) |
391 | 422 | assert response.get("total") == 0, "total should be 0" |
| 423 | + |
| 424 | + |
| 425 | +@then("The Search Response should contain search results and OperationOutcome for invalid immunization targets") |
| 426 | +def validate_search_response_with_invalid_targets_operation_outcome(context): |
| 427 | + response = context.response.json() |
| 428 | + assert response.get("resourceType") == "Bundle", "resourceType should be 'Bundle'" |
| 429 | + assert response.get("type") == "searchset", "type should be 'searchset'" |
| 430 | + entries = response.get("entry", []) |
| 431 | + assert len(entries) >= 1, "Bundle should contain at least one entry" |
| 432 | + |
| 433 | + imms_entry = next( |
| 434 | + ( |
| 435 | + e |
| 436 | + for e in entries |
| 437 | + if e.get("resource", {}).get("resourceType") == "Immunization" |
| 438 | + and e.get("resource", {}).get("id") == context.ImmsID |
| 439 | + ), |
| 440 | + None, |
| 441 | + ) |
| 442 | + assert imms_entry is not None, f"Expected to find Immunization entry with id {context.ImmsID} in search response" |
| 443 | + |
| 444 | + oo_entries = [e for e in entries if e.get("resource", {}).get("resourceType") == "OperationOutcome"] |
| 445 | + assert len(oo_entries) >= 1, "Bundle should contain at least one OperationOutcome entry for invalid targets" |
| 446 | + diagnostics = oo_entries[0].get("resource", {}).get("issue", [{}])[0].get("diagnostics", "") |
| 447 | + assert "invalid -immunization.target value(s) that were ignored" in diagnostics, ( |
| 448 | + f"Expected OperationOutcome diagnostics to mention invalid targets, got: {diagnostics}" |
| 449 | + ) |
| 450 | + assert "INVALID_TYPE" in diagnostics, ( |
| 451 | + f"Expected OperationOutcome diagnostics to mention INVALID_TYPE, got: {diagnostics}" |
| 452 | + ) |
0 commit comments