Skip to content

Commit f285193

Browse files
committed
VED-746: e2e for search for identifier and _elements
1 parent d776cc8 commit f285193

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

e2e/test_search_by_identifier_elements.py

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from utils.base_test import ImmunizationBaseTest
2-
from utils.resource import generate_imms_resource
32
from lib.env import get_service_base_path
3+
import pprint
4+
import uuid
5+
from utils.constants import valid_nhs_number1
6+
from utils.resource import generate_imms_resource
7+
from utils.mappings import VaccineTypes
8+
from typing import NamedTuple, Literal, Optional
49

510

611
class TestSearchImmunizationByIdentifier(ImmunizationBaseTest):
@@ -42,3 +47,85 @@ def test_search_imms(self):
4247
self.assertEqual(
4348
entries[0]["fullUrl"], f"{get_service_base_path()}/Immunization/{covid_ids}"
4449
)
50+
51+
def test_search_imms_no_match_returns_empty_bundle(self):
52+
for imms_api in self.imms_apis:
53+
with self.subTest(imms_api):
54+
resp = imms_api.search_immunization_by_identifier_and_elements(
55+
"http://example.org/sys", "does-not-exist-123"
56+
)
57+
self.assertEqual(resp.status_code, 200, resp.text)
58+
bundle = resp.json()
59+
self.assertEqual(bundle.get("resourceType"), "Bundle", bundle)
60+
self.assertEqual(bundle.get("type"), "searchset")
61+
self.assertEqual(bundle.get("total", 0), 0)
62+
self.assertFalse(bundle.get("entry"))
63+
64+
def test_search_immunization_parameter_smoke_tests(self):
65+
stored_records = generate_imms_resource(
66+
valid_nhs_number1, VaccineTypes.covid_19,
67+
imms_identifier_value=str(uuid.uuid4()))
68+
69+
imms_id = self.store_records(stored_records)
70+
# Retrieve the resources to get the identifier system and value via read API
71+
covid_resource = self.default_imms_api.get_immunization_by_id(imms_id).json()
72+
73+
# Extract identifier components safely for covid resource
74+
identifiers = covid_resource.get("identifier", [])
75+
identifier_system = identifiers[0].get("system")
76+
identifier_value = identifiers[0].get("value")
77+
78+
# created_resource_ids = [result["id"] for result in stored_records]
79+
80+
class SearchTestParams(NamedTuple):
81+
method: Literal["POST", "GET"]
82+
query_string: Optional[str]
83+
body: Optional[str]
84+
should_be_success: bool
85+
expected_status_code: int = 200
86+
87+
searches = [
88+
SearchTestParams(
89+
"GET",
90+
"",
91+
None,
92+
False,
93+
400
94+
),
95+
# No results.
96+
SearchTestParams(
97+
"GET",
98+
f"identifier={identifier_system}|{identifier_value}",
99+
None,
100+
True,
101+
200
102+
),
103+
SearchTestParams(
104+
"POST",
105+
f"identifier={identifier_system}|{identifier_value}&_elements=id,meta",
106+
None,
107+
True,
108+
200
109+
)
110+
]
111+
for search in searches:
112+
pprint.pprint(search)
113+
response = self.default_imms_api.search_immunizations_full(
114+
search.method, search.query_string,
115+
body=search.body,
116+
expected_status_code=search.expected_status_code)
117+
118+
# Then
119+
assert response.ok == search.should_be_success, response.text
120+
121+
results: dict = response.json()
122+
if search.should_be_success:
123+
assert "entry" in results.keys()
124+
assert response.status_code == 200
125+
assert results["resourceType"] == "Bundle"
126+
127+
# result_ids = [result["resource"]["id"] for result in results["entry"]]
128+
# created_and_returned_ids = list(set(result_ids) & set(created_resource_ids))
129+
# assert len(created_and_returned_ids) == len(search.expected_indexes)
130+
# for expected_index in search.expected_indexes:
131+
# assert created_resource_ids[expected_index] in result_ids

0 commit comments

Comments
 (0)