|
1 | 1 |
|
2 | 2 | from decimal import Decimal |
| 3 | +import pprint |
| 4 | +from typing import NamedTuple, Literal, Optional |
| 5 | +import uuid |
3 | 6 | from utils.base_test import ImmunizationBaseTest |
4 | 7 | from utils.constants import valid_nhs_number1 |
5 | 8 |
|
@@ -132,3 +135,81 @@ def test_search_backwards_compatible(self): |
132 | 135 | self.assertEqual(response_imm["search"], {"mode": "match"}) |
133 | 136 | expected_imms_resource["patient"]["reference"] = response_imm["resource"]["patient"]["reference"] |
134 | 137 | self.assertEqual(response_imm["resource"], expected_imms_resource) |
| 138 | + |
| 139 | + def test_search_immunization_parameter_smoke_tests(self): |
| 140 | + stored_records = generate_imms_resource( |
| 141 | + valid_nhs_number1, VaccineTypes.covid_19, |
| 142 | + imms_identifier_value=str(uuid.uuid4())) |
| 143 | + |
| 144 | + imms_id = self.store_records(stored_records) |
| 145 | + # Retrieve the resources to get the identifier system and value via read API |
| 146 | + covid_resource = self.default_imms_api.get_immunization_by_id(imms_id).json() |
| 147 | + |
| 148 | + # Extract identifier components safely for covid resource |
| 149 | + identifiers = covid_resource.get("identifier", []) |
| 150 | + identifier_system = identifiers[0].get("system") |
| 151 | + identifier_value = identifiers[0].get("value") |
| 152 | + |
| 153 | + # created_resource_ids = [result["id"] for result in stored_records] |
| 154 | + |
| 155 | + class SearchTestParams(NamedTuple): |
| 156 | + method: Literal["POST", "GET"] |
| 157 | + query_string: Optional[str] |
| 158 | + body: Optional[str] |
| 159 | + should_be_success: bool |
| 160 | + expected_status_code: int = 200 |
| 161 | + |
| 162 | + searches = [ |
| 163 | + SearchTestParams( |
| 164 | + "GET", |
| 165 | + "", |
| 166 | + None, |
| 167 | + False, |
| 168 | + 400 |
| 169 | + ), |
| 170 | + # No results. |
| 171 | + SearchTestParams( |
| 172 | + "GET", |
| 173 | + f"identifier={identifier_system}|{identifier_value}", |
| 174 | + None, |
| 175 | + True, |
| 176 | + 200 |
| 177 | + ), |
| 178 | + SearchTestParams( |
| 179 | + "POST", |
| 180 | + "", |
| 181 | + f"identifier={identifier_system}|{identifier_value}", |
| 182 | + True, |
| 183 | + 200 |
| 184 | + ), |
| 185 | + SearchTestParams( |
| 186 | + "POST", |
| 187 | + f"identifier={identifier_system}|{identifier_value}", |
| 188 | + f"identifier={identifier_system}|{identifier_value}", |
| 189 | + False, |
| 190 | + 400 |
| 191 | + ), |
| 192 | + ] |
| 193 | + for search in searches: |
| 194 | + pprint.pprint(search) |
| 195 | + response = self.default_imms_api.search_immunizations_full( |
| 196 | + search.method, |
| 197 | + search.query_string, |
| 198 | + body=search.body, |
| 199 | + expected_status_code=search.expected_status_code) |
| 200 | + |
| 201 | + # Then |
| 202 | + assert response.ok == search.should_be_success, response.text |
| 203 | + |
| 204 | + results: dict = response.json() |
| 205 | + if search.should_be_success: |
| 206 | + assert "entry" in results.keys() |
| 207 | + assert response.status_code == 200 |
| 208 | + assert results["resourceType"] == "Bundle" |
| 209 | + assert results["type"] == "searchset" |
| 210 | + assert results["total"] == 1 |
| 211 | + assert isinstance(results["entry"], list) |
| 212 | + else: |
| 213 | + assert "entry" not in results.keys() |
| 214 | + assert response.status_code != 200 |
| 215 | + assert results["resourceType"] == "OperationOutcome" |
0 commit comments