Skip to content

Commit fe92f5e

Browse files
Improve loading expected responses.
1 parent 39d9338 commit fe92f5e

3 files changed

Lines changed: 69 additions & 16 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"resourceType": "Bundle",
3+
"type": "collection",
4+
"meta": {
5+
"profile": [
6+
"https://fhir.nhs.uk/STU3/StructureDefinition/GPConnect-StructuredRecord-Bundle-1"
7+
]
8+
},
9+
"entry": [
10+
{
11+
"resource": {
12+
"resourceType": "Patient",
13+
"id": "9999999999",
14+
"meta": {
15+
"versionId": "1",
16+
"lastUpdated": "2020-01-01T00:00:00Z"
17+
},
18+
"identifier": [
19+
{
20+
"system": "https://fhir.nhs.uk/Id/nhs-number",
21+
"value": "9999999999"
22+
}
23+
],
24+
"name": [
25+
{
26+
"use": "official",
27+
"family": "Jones",
28+
"given": [
29+
"Alice"
30+
],
31+
"period": {
32+
"start": "1900-01-01",
33+
"end": "9999-12-31"
34+
}
35+
}
36+
],
37+
"gender": "female",
38+
"birthDate": "1980-01-01",
39+
"generalPractitioner": [
40+
{
41+
"id": "1",
42+
"type": "Organization",
43+
"identifier": {
44+
"system": "https://fhir.nhs.uk/Id/ods-organization-code",
45+
"value": "A12345",
46+
"period": {
47+
"start": "2020-01-01",
48+
"end": "9999-12-31"
49+
}
50+
}
51+
}
52+
]
53+
}
54+
}
55+
]
56+
}

gateway-api/tests/integration/data/emis_int_test_9692140466.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"resourceType": "Bundle",
3-
"id": "c55adcd2-17e4-4093-8d31-742e54adee5e",
43
"meta": {
54
"profile": [
65
"https://fhir.nhs.uk/STU3/StructureDefinition/GPConnect-StructuredRecord-Bundle-1"

gateway-api/tests/integration/test_get_structured_record.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Integration tests for the gateway API using pytest."""
22

33
import json
4+
import os
45
from collections.abc import Callable
56
from typing import Any, cast
67

78
import pytest
89
from requests import Response
9-
from stubs.data.bundles import Bundles
1010

1111
from tests.conftest import Client
1212

@@ -367,20 +367,18 @@ def requester(nhs_number: str) -> Response:
367367
def expected_response_message_for_simple_request(
368368
self, nhs_number: str
369369
) -> dict[str, Any]:
370-
# TODO: Do this better.
371-
if nhs_number == "9999999999":
372-
return Bundles.ALICE_JONES_9999999999
373-
elif nhs_number == "9692140466":
374-
with open("tests/integration/data/emis_int_test_9692140466.json") as f:
375-
expected_response = cast(
376-
"dict[str, Any]", json.load(f)
377-
) # TODO: Avoid cast here
378-
del expected_response["id"]
379-
return expected_response
380-
else:
381-
raise ValueError(
382-
f"No expected response message defined for nhs_number {nhs_number}"
383-
)
370+
test_patient_file_path = self.find_test_patient_file(nhs_number)
371+
with open(test_patient_file_path) as f:
372+
expected_response = cast("dict[str, Any]", json.load(f))
373+
return expected_response
374+
375+
@staticmethod
376+
def find_test_patient_file(nhs_number: str) -> str:
377+
filenames = os.listdir("tests/integration/data/")
378+
for filename in filenames:
379+
if nhs_number in filename:
380+
return "tests/integration/data/" + filename
381+
raise ValueError(f"No test patient file defined for nhs_number {nhs_number}")
384382

385383
@staticmethod
386384
def strip_randomized_fields(message: dict[str, Any]) -> None:

0 commit comments

Comments
 (0)