Skip to content

Commit 580d2ed

Browse files
NPA-5357: Update formatting and API sandbox test
1 parent 55d55af commit 580d2ed

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

sandbox/api/post_questionnaire_response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
)
1111
from .utils import generate_response_from_example
1212

13-
QUESTIONNAIRE_RESPONSE_APP_BASE_PATH = "https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/QuestionnaireResponse"
13+
QUESTIONNAIRE_RESPONSE_APP_BASE_PATH = (
14+
"https://sandbox.api.service.nhs.uk/validated-relationships/FHIR/R4/QuestionnaireResponse"
15+
)
1416
basicConfig(level=INFO, format="%(asctime)s - %(message)s")
1517
logger = getLogger(__name__)
1618

sandbox/api/tests/test_post_questionnaire_response.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,44 @@
1010
INTERNAL_SERVER_ERROR_EXAMPLE,
1111
)
1212

13+
SANDBOX_API_URL = "https://sandbox.api.service.nhs.uk/validated-relationships"
1314
QUESTIONNAIRE_RESPONSE_API_ENDPOINT = "/FHIR/R4/QuestionnaireResponse"
1415

1516

1617
@pytest.mark.parametrize(
17-
("nhs_num", "response_file_name", "status_code"),
18+
("nhs_num", "response_file_name", "status_code", "id"),
1819
[
1920
(
2021
"9000000009",
2122
POST_QUESTIONNAIRE_RESPONSE__SUCCESS,
2223
200,
24+
"156e1560-e532-4e2a-85ad-5aeff03dc43e",
2325
),
2426
(
2527
"9000000017",
2628
POST_QUESTIONNAIRE_RESPONSE__SUCCESS,
2729
200,
30+
"156e1560-e532-4e2a-85ad-5aeff03dc43e",
2831
),
2932
(
3033
"9000000049",
3134
POST_QUESTIONNAIRE_RESPONSE__DUPLICATE_RELATIONSHIP_ERROR,
3235
409,
36+
None,
3337
),
3438
(
3539
"INVALID_NHS_NUMBER",
3640
INTERNAL_SERVER_ERROR_EXAMPLE,
3741
500,
42+
None,
3843
),
3944
],
4045
)
4146
@patch("sandbox.api.post_questionnaire_response.generate_response_from_example")
4247
def test_post_questionnaire_response(
4348
mock_generate_response_from_example: MagicMock,
4449
nhs_num: str,
50+
id: str,
4551
response_file_name: str,
4652
status_code: int,
4753
client: object,
@@ -57,6 +63,13 @@ def test_post_questionnaire_response(
5763
# Act
5864
response = client.post(QUESTIONNAIRE_RESPONSE_API_ENDPOINT, json=json)
5965
# Assert
60-
mock_generate_response_from_example.assert_called_once_with(response_file_name, status_code)
66+
if id is not None:
67+
mock_generate_response_from_example.assert_called_once_with(
68+
response_file_name,
69+
status_code,
70+
headers={"location": f"{SANDBOX_API_URL}{QUESTIONNAIRE_RESPONSE_API_ENDPOINT}?ID={id}"},
71+
)
72+
else:
73+
mock_generate_response_from_example.assert_called_once_with(response_file_name, status_code)
6174
assert response.status_code == status_code
6275
assert response.json == loads(mocked_response.get_data(as_text=True))

0 commit comments

Comments
 (0)