Skip to content

Commit bc614a4

Browse files
committed
VED-746: e2e for post path
1 parent f285193 commit bc614a4

File tree

2 files changed

+101
-11
lines changed

2 files changed

+101
-11
lines changed

e2e/test_search_by_identifier.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

22
from decimal import Decimal
3+
import pprint
4+
from typing import NamedTuple, Literal, Optional
5+
import uuid
36
from utils.base_test import ImmunizationBaseTest
47
from utils.constants import valid_nhs_number1
58

@@ -132,3 +135,81 @@ def test_search_backwards_compatible(self):
132135
self.assertEqual(response_imm["search"], {"mode": "match"})
133136
expected_imms_resource["patient"]["reference"] = response_imm["resource"]["patient"]["reference"]
134137
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"

e2e/test_search_by_identifier_elements.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_search_imms_no_match_returns_empty_bundle(self):
6161
self.assertEqual(bundle.get("total", 0), 0)
6262
self.assertFalse(bundle.get("entry"))
6363

64-
def test_search_immunization_parameter_smoke_tests(self):
64+
def test_search_by_identifier_parameter_smoke_tests(self):
6565
stored_records = generate_imms_resource(
6666
valid_nhs_number1, VaccineTypes.covid_19,
6767
imms_identifier_value=str(uuid.uuid4()))
@@ -102,16 +102,24 @@ class SearchTestParams(NamedTuple):
102102
),
103103
SearchTestParams(
104104
"POST",
105-
f"identifier={identifier_system}|{identifier_value}&_elements=id,meta",
106-
None,
105+
"",
106+
f"identifier={identifier_system}|{identifier_value}",
107107
True,
108108
200
109-
)
109+
),
110+
SearchTestParams(
111+
"POST",
112+
f"identifier={identifier_system}|{identifier_value}",
113+
f"identifier={identifier_system}|{identifier_value}",
114+
False,
115+
400
116+
),
110117
]
111118
for search in searches:
112119
pprint.pprint(search)
113120
response = self.default_imms_api.search_immunizations_full(
114-
search.method, search.query_string,
121+
search.method,
122+
search.query_string,
115123
body=search.body,
116124
expected_status_code=search.expected_status_code)
117125

@@ -123,9 +131,10 @@ class SearchTestParams(NamedTuple):
123131
assert "entry" in results.keys()
124132
assert response.status_code == 200
125133
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
134+
assert results["type"] == "searchset"
135+
assert results["total"] == 1
136+
assert isinstance(results["entry"], list)
137+
else:
138+
assert "entry" not in results.keys()
139+
assert response.status_code != 200
140+
assert results["resourceType"] == "OperationOutcome"

0 commit comments

Comments
 (0)