@@ -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