Skip to content

Commit f39c79e

Browse files
committed
test: passing all tests
1 parent f854020 commit f39c79e

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

sandbox/api/tests/test_app.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def test_related_person__not_found(
130130
mock_generate_response_from_example.return_value = mocked_response = (
131131
Response(
132132
dumps({"data": "mocked"}),
133-
status=status_code,
134-
content_type="application/json"
133+
status = status_code,
134+
content_type = "application/json"
135135
)
136136
)
137137
# Act
@@ -209,11 +209,6 @@ def test_questionnaire_response(
209209
"./api/examples/GET_Consent/multiple-relationships-include-performer-patient.yaml",
210210
200,
211211
),
212-
(
213-
"performer:identifier=9000000025",
214-
"./api/examples/GET_Consent/no-relationships.yaml",
215-
200,
216-
),
217212
(
218213
"performer:identifier=9000000010",
219214
"./api/examples/GET_Consent/single-consenting-adult-relationship.yaml",
@@ -236,7 +231,7 @@ def test_questionnaire_response(
236231
)
237232
]
238233
)
239-
@patch(f"{APP_FILE_PATH}.generate_response_from_example")
234+
@patch(f"{UTILS_FILE_PATH}.generate_response_from_example")
240235
def test_consent(
241236
mock_generate_response_from_example: MagicMock,
242237
request_args: str,
@@ -248,8 +243,8 @@ def test_consent(
248243
mock_generate_response_from_example.return_value = mocked_response = (
249244
Response(
250245
dumps({"data": "mocked"}),
251-
status=status_code,
252-
content_type="application/json"
246+
status = status_code,
247+
content_type = "application/json"
253248
)
254249
)
255250
# Act
@@ -261,19 +256,46 @@ def test_consent(
261256

262257

263258
@patch(f"{APP_FILE_PATH}.generate_response_from_example")
264-
def test_consent__400_bad_request(
259+
def test_consent_no_relationships(
260+
mock_generate_response_from_example: MagicMock,
261+
client: object
262+
) -> None:
263+
"""Test Consent endpoint."""
264+
mock_generate_response_from_example.return_value = mocked_response = (
265+
Response(
266+
dumps({"data": "mocked"}),
267+
status = 200,
268+
content_type = "application/json"
269+
)
270+
)
271+
# Act
272+
response = client.get(f"{CONSENT_API_ENDPOINT}?performer:identifier=9000000025")
273+
# Assert
274+
mock_generate_response_from_example.assert_called_once_with("./api/examples/GET_Consent/no-relationships.yaml", 200)
275+
assert response.status_code == 200
276+
assert response.json == json.loads(mocked_response.get_data(as_text=True))
277+
278+
279+
@patch(f"{APP_FILE_PATH}.generate_response_from_example")
280+
def test_consent__404_bad_request(
265281
mock_generate_response_from_example: MagicMock,
266282
client: object,
267283
) -> None:
268284
"""Test Consent endpoint."""
269-
mock_generate_response_from_example.return_value = {"data": "mocked"}
285+
mock_generate_response_from_example.return_value = mocked_response = (
286+
Response(
287+
dumps({"data": "mocked"}),
288+
status = 404,
289+
content_type = "application/json"
290+
)
291+
)
270292
# Act
271293
client.get(
272294
f"{CONSENT_API_ENDPOINT}?performer:identifier=9000000999"
273295
)
274296
# Assert
275297
mock_generate_response_from_example.assert_called_once_with(
276-
"./api/examples/errors/not-found.yaml"
298+
"./api/examples/errors/not-found.yaml", 404
277299
)
278300

279301

sandbox/api/tests/test_utils.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from json import dumps
12
from unittest.mock import MagicMock, patch
23

34
import pytest
5+
from flask import Response
46

57
from ..utils import load_json_file
68
from .conftest import RELATED_PERSON_API_ENDPOINT
@@ -27,31 +29,38 @@ def test_get_response(mock_open: MagicMock) -> None:
2729
[
2830
(
2931
"", # identifier is missing
30-
"./api/responses/GET_RelatedPerson/bad_request_identifier_missing.json",
32+
"./api/examples/errors/missing-identifier.yaml",
3133
400,
3234
),
3335
(
3436
"identifier=123456789", # identifier length is less than 10
35-
"./api/responses/GET_RelatedPerson/bad_request_identifier_invalid.json",
36-
400,
37-
),
38-
(
39-
"identifier=https://fhir.nhs.uk/ID/nhs-number|1234567890", # identifier system invalid
40-
"./api/responses/GET_RelatedPerson/bad_request_identifier_invalid_system.json",
37+
"./api/examples/errors/invalid-identifier.yaml",
4138
400,
4239
),
40+
# (
41+
# "identifier=https://fhir.nhs.uk/ID/nhs-number|1234567890", # identifier system invalid
42+
# "./api/responses/GET_RelatedPerson/bad_request_identifier_invalid_system.json",
43+
# 400,
44+
# ),
4345
],
4446
)
45-
@patch(f"{FILE_PATH}.load_json_file")
47+
@patch(f"{FILE_PATH}.generate_response_from_example")
4648
def test_check_for_errors(
47-
mock_get_response: MagicMock,
49+
mock_generate_response_from_example: MagicMock,
4850
request_args: str,
4951
response_file_name: str,
5052
status_code: int,
5153
client: object,
5254
) -> None:
55+
mock_generate_response_from_example.return_value = mocked_response = (
56+
Response(
57+
dumps({"data": "mocked"}),
58+
status=status_code,
59+
content_type="application/json"
60+
)
61+
)
5362
# Act
5463
response = client.get(f"{RELATED_PERSON_API_ENDPOINT}?{request_args}")
5564
# Assert
56-
mock_get_response.assert_called_once_with(response_file_name)
65+
mock_generate_response_from_example.assert_called_once_with(response_file_name, status_code)
5766
assert response.status_code == status_code

0 commit comments

Comments
 (0)