Skip to content

Commit aef569c

Browse files
[RAA-6562]-[GC]-[ODS code change to fix int tests]-[EW]
1 parent 8a81c6b commit aef569c

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@ def client():
130130
@pytest_asyncio.fixture
131131
async def user_restricted_product(client, make_product):
132132
# Setup
133+
print("user_restricted_product EUOAllowlistRequired=true")
133134
productName = await make_product(
134135
[
135136
"urn:nhsd:apim:user-nhs-id:aal3:e-referrals-service-api",
136137
"urn:nhsd:apim:user-nhs-id:aal2:e-referrals-service-api",
137138
],
138-
additional_attributes=[{"name": "EUOAllowlistRequired", "value": "false"}],
139+
additional_attributes=[{"name": "EUOAllowlistRequired", "value": "true"}],
139140
)
140141

141142
print(f"product created: {productName}")

tests/integration/test_user_restricted.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ async def test_user_restricted_invalid_ods_code(
113113
f"{service_url}{endpoint_url}", headers=client_request_headers
114114
)
115115
# Verify the status
116-
assert (
117-
response.status_code == 403
118-
), "Expected a 403 when accessing the api but got " + str(response.status_code)
116+
assert response.status_code == 403, (
117+
"Expected a 403 when accessing the api but got "
118+
+ str(response.status_code)
119+
+ "; response body: "
120+
+ response.text
121+
)
119122
# Verify the OperationOutcome payload
120123
response_data = response.json()
121124
assert response_data["resourceType"] == "OperationOutcome"
@@ -181,9 +184,12 @@ async def test_user_restricted_missing_ods_header(
181184
f"{service_url}{endpoint_url}", headers=client_request_headers
182185
)
183186
# Verify the status
184-
assert (
185-
response.status_code == 400
186-
), "Expected a 400 when accessing the api but got " + str(response.status_code)
187+
assert response.status_code == 400, (
188+
"Expected a 400 when accessing the api but got "
189+
+ str(response.status_code)
190+
+ "; response body: "
191+
+ response.text
192+
)
187193
# Verify the OperationOutcome payload
188194
response_data = response.json()
189195
assert response_data["resourceType"] == "OperationOutcome"
@@ -252,7 +258,37 @@ async def test_user_restricted_missing_ods_code(
252258
f"{service_url}{endpoint_url}", headers=client_request_headers
253259
)
254260
# Verify the status
255-
# Empty ODS currently falls through to an allowed request for this configured app.
261+
assert response.status_code == 400, (
262+
"Expected a 400 when accessing the api but got "
263+
+ str(response.status_code)
264+
+ "; response body: "
265+
+ response.text
266+
)
267+
# Verify the OperationOutcome payload
268+
response_data = response.json()
269+
assert response_data["resourceType"] == "OperationOutcome"
270+
assert response_data["meta"]["lastUpdated"] is not None
271+
assert len(response_data["meta"]["profile"]) == 1
272+
assert response_data["meta"]["profile"][0] == (
273+
"https://www.hl7.org/fhir/R4/operationoutcome.html"
274+
if is_fhir_4
275+
else "https://fhir.nhs.uk/STU3/StructureDefinition/eRS-OperationOutcome-1"
276+
)
277+
assert len(response_data["issue"]) == 1
278+
issue = response_data["issue"][0]
279+
assert issue["severity"] == "error"
280+
assert issue["code"] == "required" if is_fhir_4 else "required"
281+
assert issue["diagnostics"] == (
282+
"Missing or Empty NHSD-End-User-Organisation-ODS header."
283+
)
284+
assert len(issue["details"]["coding"]) == 1
285+
issue_details = issue["details"]["coding"][0]
256286
assert (
257-
response.status_code == 200
258-
), "Expected a 200 when accessing the api but got " + str(response.status_code)
287+
issue_details["system"]
288+
== "https://fhir.nhs.uk/CodeSystem/NHSD-API-ErrorOrWarningCode"
289+
if is_fhir_4
290+
else "https://fhir.nhs.uk/STU3/CodeSystem/eRS-APIErrorCode-1"
291+
)
292+
assert (
293+
issue_details["code"] == "MISSING_HEADER" if is_fhir_4 else "MISSING_HEADER"
294+
)

0 commit comments

Comments
 (0)