Skip to content

Commit 1cd60bd

Browse files
committed
NPA-5534: sandbox formatting update
1 parent 7935c83 commit 1cd60bd

15 files changed

+247
-99
lines changed

sandbox/api/constants.py

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
# Common examples
1212
INTERNAL_SERVER_ERROR_EXAMPLE = "./api/examples/errors/internal-server-error.yaml"
13-
BAD_REQUEST_INCLUDE_PARAM_INVALID = "./api/examples/errors/invalid-include-parameter.yaml"
13+
BAD_REQUEST_INCLUDE_PARAM_INVALID = (
14+
"./api/examples/errors/invalid-include-parameter.yaml"
15+
)
1416
INVALIDATED_RESOURCE = "./api/examples/errors/invalidated-resource.yaml"
1517
MISSING_IDENTIFIER = "./api/examples/errors/missing-identifier.yaml"
1618
INVALID_IDENTIFIER = "./api/examples/errors/invalid-identifier.yaml"
@@ -27,7 +29,9 @@
2729
GET_CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE = (
2830
f"{GET_CONSENT__DIRECTORY}filtered-relationships-status-proposed-active.yaml"
2931
)
30-
GET_CONSENT__MULTIPLE_RELATIONSHIPS = f"{GET_CONSENT__DIRECTORY}multiple-relationships.yaml"
32+
GET_CONSENT__MULTIPLE_RELATIONSHIPS = (
33+
f"{GET_CONSENT__DIRECTORY}multiple-relationships.yaml"
34+
)
3135
GET_CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_BOTH = (
3236
f"{GET_CONSENT__DIRECTORY}multiple-relationships-include-performer-patient.yaml"
3337
)
@@ -38,88 +42,124 @@
3842
f"{GET_CONSENT__DIRECTORY}multiple-relationships-include-performer.yaml"
3943
)
4044
GET_CONSENT__NO_RELATIONSHIPS = f"{GET_CONSENT__DIRECTORY}no-relationships.yaml"
41-
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP = f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship.yaml"
42-
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH = (
43-
f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-performer-patient.yaml"
45+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP = (
46+
f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship.yaml"
4447
)
48+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH = f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-performer-patient.yaml"
4549
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PATIENT = (
4650
f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-patient.yaml"
4751
)
48-
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PERFORMER = (
49-
f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-performer.yaml"
50-
)
51-
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP = f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship.yaml"
52-
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH = (
53-
f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship-include-performer-patient.yaml"
52+
GET_CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_PERFORMER = f"{GET_CONSENT__DIRECTORY}single-consenting-adult-relationship-include-performer.yaml"
53+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP = (
54+
f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship.yaml"
5455
)
56+
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH = f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship-include-performer-patient.yaml"
5557
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PATIENT = (
5658
f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship-include-patient.yaml"
5759
)
5860
GET_CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_PERFORMER = (
5961
f"{GET_CONSENT__DIRECTORY}single-mother-child-relationship-include-performer.yaml"
6062
)
61-
GET_CONSENT__STATUS_PARAM_INVALID = f"{GET_CONSENT__DIRECTORY}errors/invalid-status-parameter.yaml"
63+
GET_CONSENT__STATUS_PARAM_INVALID = (
64+
f"{GET_CONSENT__DIRECTORY}errors/invalid-status-parameter.yaml"
65+
)
6266
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT = (
6367
f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient.yaml"
6468
)
65-
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT_INCLUDE_PERFORMER = (
66-
f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient-include-performer.yaml"
67-
)
68-
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT_INCLUDE_PATIENT = (
69-
f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient-include-patient.yaml"
70-
)
71-
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT_INCLUDE_BOTH = (
72-
f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient-include-performer-patient.yaml"
73-
)
69+
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT_INCLUDE_PERFORMER = f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient-include-performer.yaml"
70+
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT_INCLUDE_PATIENT = f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient-include-patient.yaml"
71+
GET_CONSENT__MULTIPLE_RELATIONSHIPS_SINGLE_PATIENT_INCLUDE_BOTH = f"{GET_CONSENT__DIRECTORY}multiple-relationships-single-patient-include-performer-patient.yaml"
7472

7573
# GET Consent by ID
76-
GET_CONSENT_BY_ID__INVALID_ID_ERROR = f"{GET_CONSENT__DIRECTORY}ID/errors/invalid-id.yaml"
74+
GET_CONSENT_BY_ID__INVALID_ID_ERROR = (
75+
f"{GET_CONSENT__DIRECTORY}ID/errors/invalid-id.yaml"
76+
)
7777

7878
# POST Consent
7979
POST_CONSENT__DIRECTORY = "./api/examples/POST_Consent/"
8080
POST_CONSENT__SUCCESS = f"{POST_CONSENT__DIRECTORY}success.yaml"
81-
POST_CONSENT__DUPLICATE_RELATIONSHIP_ERROR = f"{POST_CONSENT__DIRECTORY}errors/duplicate_relationship_error.yaml"
82-
POST_CONSENT__PERFORMER_IDENTIFIER_ERROR = f"{POST_CONSENT__DIRECTORY}errors/invalid_performer_identifier_error.yaml"
81+
POST_CONSENT__DUPLICATE_RELATIONSHIP_ERROR = (
82+
f"{POST_CONSENT__DIRECTORY}errors/duplicate_relationship_error.yaml"
83+
)
84+
POST_CONSENT__PERFORMER_IDENTIFIER_ERROR = (
85+
f"{POST_CONSENT__DIRECTORY}errors/invalid_performer_identifier_error.yaml"
86+
)
8387

8488
# PATCH Consent
8589
PATCH_CONSENT__DIRECTORY = "./api/examples/PATCH_Consent/"
8690
PATCH_CONSENT__SUCCESS = f"{PATCH_CONSENT__DIRECTORY}success.yaml"
87-
PATCH_CONSENT__INVALID_PATCH_FORMAT = f"{PATCH_CONSENT__DIRECTORY}errors/invalid_patch_format.yaml"
91+
PATCH_CONSENT__INVALID_PATCH_FORMAT = (
92+
f"{PATCH_CONSENT__DIRECTORY}errors/invalid_patch_format.yaml"
93+
)
8894
PATCH_CONSENT__INVALID_PATH = f"{PATCH_CONSENT__DIRECTORY}errors/invalid_path.yaml"
89-
PATCH_CONSENT__INVALID_STATUS_CODE = f"{PATCH_CONSENT__DIRECTORY}errors/invalid_status_code.yaml"
90-
PATCH_CONSENT__INVALID_STATUS_REASON = f"{PATCH_CONSENT__DIRECTORY}errors/invalid_status_reason.yaml"
91-
PATCH_CONSENT__RESOURCE_NOT_FOUND = f"{PATCH_CONSENT__DIRECTORY}errors/resource_not_found.yaml"
92-
PATCH_CONSENT__INVALID_STATE_TRANSITION = f"{PATCH_CONSENT__DIRECTORY}errors/invalid_state_transition.yaml"
95+
PATCH_CONSENT__INVALID_STATUS_CODE = (
96+
f"{PATCH_CONSENT__DIRECTORY}errors/invalid_status_code.yaml"
97+
)
98+
PATCH_CONSENT__INVALID_STATUS_REASON = (
99+
f"{PATCH_CONSENT__DIRECTORY}errors/invalid_status_reason.yaml"
100+
)
101+
PATCH_CONSENT__RESOURCE_NOT_FOUND = (
102+
f"{PATCH_CONSENT__DIRECTORY}errors/resource_not_found.yaml"
103+
)
104+
PATCH_CONSENT__INVALID_STATE_TRANSITION = (
105+
f"{PATCH_CONSENT__DIRECTORY}errors/invalid_state_transition.yaml"
106+
)
93107

94108
# POST QuestionnaireResponse
95109
POST_QUESTIONNAIRE_RESPONSE_DIRECTORY = "./api/examples/POST_QuestionnaireResponse/"
96-
POST_QUESTIONNAIRE_RESPONSE__SUCCESS = f"{POST_QUESTIONNAIRE_RESPONSE_DIRECTORY}success.yaml"
110+
POST_QUESTIONNAIRE_RESPONSE__SUCCESS = (
111+
f"{POST_QUESTIONNAIRE_RESPONSE_DIRECTORY}success.yaml"
112+
)
97113
POST_QUESTIONNAIRE_RESPONSE__DUPLICATE_RELATIONSHIP_ERROR = (
98114
f"{POST_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/duplicate_relationship_error.yaml"
99115
)
100116

101117
# GET QuestionnaireResponse
102118
GET_QUESTIONNAIRE_RESPONSE_DIRECTORY = "./api/examples/GET_QuestionnaireResponse/"
103-
GET_QUESTIONNAIRE_RESPONSE__SUCCESS = f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}success.yaml"
104-
GET_QUESTIONNAIRE_RESPONSE__INVALID = f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/invalid_access_request_id.yaml"
105-
GET_QUESTIONNAIRE_RESPONSE__MISSING = f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/missing_access_request_id.yaml"
106-
GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND = (
107-
f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/questionnaire_response_not_found.yaml"
119+
GET_QUESTIONNAIRE_RESPONSE__SUCCESS = (
120+
f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}success.yaml"
121+
)
122+
GET_QUESTIONNAIRE_RESPONSE__INVALID = (
123+
f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/invalid_access_request_id.yaml"
124+
)
125+
GET_QUESTIONNAIRE_RESPONSE__MISSING = (
126+
f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/missing_access_request_id.yaml"
108127
)
128+
GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND = f"{GET_QUESTIONNAIRE_RESPONSE_DIRECTORY}errors/questionnaire_response_not_found.yaml"
109129

110130
# GET RelatedPerson
111131
RELATED_DIRECTORY = "./api/examples/GET_RelatedPerson/"
112-
RELATED__ERROR_IDENTIFIER_MISSING = f"{RELATED_DIRECTORY}errors/invalid-identifier-missing.yaml"
113-
RELATED__ERROR_IDENTIFIER_SYSTEM = f"{RELATED_DIRECTORY}errors/invalid-identifier-system.yaml"
132+
RELATED__ERROR_IDENTIFIER_MISSING = (
133+
f"{RELATED_DIRECTORY}errors/invalid-identifier-missing.yaml"
134+
)
135+
RELATED__ERROR_IDENTIFIER_SYSTEM = (
136+
f"{RELATED_DIRECTORY}errors/invalid-identifier-system.yaml"
137+
)
114138
RELATED__ERROR_IDENTIFIER = f"{RELATED_DIRECTORY}errors/invalid-identifier.yaml"
115-
RELATED__ERROR_PATIENT_IDENTIFIER = f"{RELATED_DIRECTORY}errors/invalid-patient-identifier.yaml"
139+
RELATED__ERROR_PATIENT_IDENTIFIER = (
140+
f"{RELATED_DIRECTORY}errors/invalid-patient-identifier.yaml"
141+
)
116142
RELATED__EMPTY_RESPONSE = f"{RELATED_DIRECTORY}empty_response.yaml"
117143
RELATED__LIST_RELATIONSHIP = f"{RELATED_DIRECTORY}list_relationship_9000000017.yaml"
118-
RELATED__LIST_RELATIONSHIP_WITH_INCLUDE = f"{RELATED_DIRECTORY}list_relationship_9000000017_include.yaml"
119-
RELATED__LIST_CHILD_RELATIONSHIP = f"{RELATED_DIRECTORY}list_relationship_9000000042.yaml"
120-
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE = f"{RELATED_DIRECTORY}list_relationship_9000000042_include.yaml"
121-
RELATED__VERIFY_RELATIONSHIP_09 = f"{RELATED_DIRECTORY}verify_relationship_9000000009.yaml"
122-
RELATED__VERIFY_RELATIONSHIP_09_WITH_INCLUDE = f"{RELATED_DIRECTORY}verify_relationship_9000000009_include.yaml"
123-
RELATED__VERIFY_RELATIONSHIP_25 = f"{RELATED_DIRECTORY}verify_relationship_9000000025.yaml"
124-
RELATED__VERIFY_RELATIONSHIP_25_WITH_INCLUDE = f"{RELATED_DIRECTORY}verify_relationship_9000000025_include.yaml"
144+
RELATED__LIST_RELATIONSHIP_WITH_INCLUDE = (
145+
f"{RELATED_DIRECTORY}list_relationship_9000000017_include.yaml"
146+
)
147+
RELATED__LIST_CHILD_RELATIONSHIP = (
148+
f"{RELATED_DIRECTORY}list_relationship_9000000042.yaml"
149+
)
150+
RELATED__LIST_CHILD_RELATIONSHIP_WITH_INCLUDE = (
151+
f"{RELATED_DIRECTORY}list_relationship_9000000042_include.yaml"
152+
)
153+
RELATED__VERIFY_RELATIONSHIP_09 = (
154+
f"{RELATED_DIRECTORY}verify_relationship_9000000009.yaml"
155+
)
156+
RELATED__VERIFY_RELATIONSHIP_09_WITH_INCLUDE = (
157+
f"{RELATED_DIRECTORY}verify_relationship_9000000009_include.yaml"
158+
)
159+
RELATED__VERIFY_RELATIONSHIP_25 = (
160+
f"{RELATED_DIRECTORY}verify_relationship_9000000025.yaml"
161+
)
162+
RELATED__VERIFY_RELATIONSHIP_25_WITH_INCLUDE = (
163+
f"{RELATED_DIRECTORY}verify_relationship_9000000025_include.yaml"
164+
)
125165
RELATED__EMPTY_RESPONSE = f"{RELATED_DIRECTORY}empty_response_9000000033.yaml"

sandbox/api/get_consent_by_id.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def get_consent_by_id_response(identifier: str) -> Union[dict, tuple]:
3131
try:
3232
params = request.args.to_dict()
3333
if "_include" not in params and len(params) > 0:
34-
return generate_response_from_example(BAD_REQUEST_INCLUDE_PARAM_INVALID, 422)
34+
return generate_response_from_example(
35+
BAD_REQUEST_INCLUDE_PARAM_INVALID, 422
36+
)
3537
else:
3638
_include = request.args.getlist("_include")
3739

@@ -54,7 +56,9 @@ def get_consent_by_id_response(identifier: str) -> Union[dict, tuple]:
5456
elif identifier == "a0922245-1072-40c3-8f4e-a7490c10d365":
5557
return generate_response_from_example(INVALIDATED_RESOURCE, 404)
5658
else:
57-
return generate_response_from_example(GET_CONSENT_BY_ID__INVALID_ID_ERROR, 400)
59+
return generate_response_from_example(
60+
GET_CONSENT_BY_ID__INVALID_ID_ERROR, 400
61+
)
5862

5963
except Exception:
6064
logger.exception("An error occurred while processing the request")

sandbox/api/get_questionnaire_response.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND,
99
GET_QUESTIONNAIRE_RESPONSE__SUCCESS,
1010
INTERNAL_SERVER_ERROR_EXAMPLE,
11-
METHOD_NOT_ALLOWED
11+
METHOD_NOT_ALLOWED,
1212
)
1313
from .utils import generate_response_from_example
1414

@@ -24,13 +24,19 @@ def get_questionnaire_response_response(access_request_id: str) -> Union[dict, t
2424
"""
2525
try:
2626
if access_request_id == "156e1560-e532-4e2a-85ad-5aeff03dc43e":
27-
return generate_response_from_example(GET_QUESTIONNAIRE_RESPONSE__SUCCESS, 200)
27+
return generate_response_from_example(
28+
GET_QUESTIONNAIRE_RESPONSE__SUCCESS, 200
29+
)
2830
elif access_request_id == "INVALID":
29-
return generate_response_from_example(GET_QUESTIONNAIRE_RESPONSE__INVALID, 400)
31+
return generate_response_from_example(
32+
GET_QUESTIONNAIRE_RESPONSE__INVALID, 400
33+
)
3034
elif access_request_id == "" or access_request_id is None:
3135
return generate_response_from_example(METHOD_NOT_ALLOWED, 405)
3236
elif access_request_id == "60d09b82-f4bb-41f9-b41e-767999b4ac9b":
33-
return generate_response_from_example(GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND, 404)
37+
return generate_response_from_example(
38+
GET_QUESTIONNAIRE_RESPONSE__NOT_FOUND, 404
39+
)
3440
else:
3541
raise ValueError("Invalid access request ID")
3642
except Exception:

sandbox/api/patch_consent.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,37 @@ def patch_consent_response(id: str) -> Union[dict, tuple]:
4545

4646
elif id == "849ea584-2318-471b-a24c-cee1b5ad0137":
4747
# Invalid patch format
48-
return generate_response_from_example(PATCH_CONSENT__INVALID_PATCH_FORMAT, 400)
48+
return generate_response_from_example(
49+
PATCH_CONSENT__INVALID_PATCH_FORMAT, 400
50+
)
4951

5052
elif id == "01abb0c5-b1ac-499d-9655-9cd0b8d3588f":
5153
# Invalid path
5254
return generate_response_from_example(PATCH_CONSENT__INVALID_PATH, 400)
5355

5456
elif id == "78c35330-fa2f-4934-a5dd-fff847f38de5":
5557
# Invalid status code
56-
return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_CODE, 422)
58+
return generate_response_from_example(
59+
PATCH_CONSENT__INVALID_STATUS_CODE, 422
60+
)
5761

5862
elif id == "51fb4df5-815a-45cd-8427-04d6558336b7":
5963
# Invalid status reason
60-
return generate_response_from_example(PATCH_CONSENT__INVALID_STATUS_REASON, 422)
64+
return generate_response_from_example(
65+
PATCH_CONSENT__INVALID_STATUS_REASON, 422
66+
)
6167

6268
elif id == "7b7f47b8-96e5-43eb-b733-283bf1449f2c":
6369
# Invalid state transition
64-
return generate_response_from_example(PATCH_CONSENT__INVALID_STATE_TRANSITION, 422)
70+
return generate_response_from_example(
71+
PATCH_CONSENT__INVALID_STATE_TRANSITION, 422
72+
)
6573

6674
else:
6775
# Resource not found
68-
return generate_response_from_example(PATCH_CONSENT__RESOURCE_NOT_FOUND, 404)
76+
return generate_response_from_example(
77+
PATCH_CONSENT__RESOURCE_NOT_FOUND, 404
78+
)
6979

7080
except Exception:
7181
# Handle any general error

sandbox/api/post_consent.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
)
1212
from .utils import generate_response_from_example
1313

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

@@ -32,15 +34,23 @@ def post_consent_response() -> Union[dict, tuple]:
3234
# Successful parent-child proxy creation
3335
# Successful adult-adult proxy creation
3436
if patient_identifier == "9000000009" or patient_identifier == "9000000017":
35-
header = {"location": f"{CONSENT_APP_BASE_PATH}/90b9863e-e33c-4895-a333-fd0ea0e23205"}
36-
response = generate_response_from_example(POST_CONSENT__SUCCESS, 201, headers=header)
37+
header = {
38+
"location": f"{CONSENT_APP_BASE_PATH}/90b9863e-e33c-4895-a333-fd0ea0e23205"
39+
}
40+
response = generate_response_from_example(
41+
POST_CONSENT__SUCCESS, 201, headers=header
42+
)
3743

3844
# Duplicate relationship
3945
elif patient_identifier == "9000000049":
40-
response = generate_response_from_example(POST_CONSENT__DUPLICATE_RELATIONSHIP_ERROR, 409)
46+
response = generate_response_from_example(
47+
POST_CONSENT__DUPLICATE_RELATIONSHIP_ERROR, 409
48+
)
4149
# Invalid performer NHS number
4250
elif patient_identifier == "9000000000":
43-
response = generate_response_from_example(POST_CONSENT__PERFORMER_IDENTIFIER_ERROR, 422)
51+
response = generate_response_from_example(
52+
POST_CONSENT__PERFORMER_IDENTIFIER_ERROR, 422
53+
)
4454
else:
4555
# Out of scope errors
4656
raise ValueError("Invalid Request")

sandbox/api/post_questionnaire_response.py

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

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

@@ -32,11 +30,17 @@ def post_questionnaire_response_response() -> Union[dict, tuple]:
3230

3331
# Successful questionnaire response
3432
if source_identifier in ["9000000009", "9000000017"]:
35-
header = {"location": f"{QUESTIONNAIRE_RESPONSE_APP_BASE_PATH}?ID=156e1560-e532-4e2a-85ad-5aeff03dc43e"}
36-
response = generate_response_from_example(POST_QUESTIONNAIRE_RESPONSE__SUCCESS, 200, headers=header)
33+
header = {
34+
"location": f"{QUESTIONNAIRE_RESPONSE_APP_BASE_PATH}?ID=156e1560-e532-4e2a-85ad-5aeff03dc43e"
35+
}
36+
response = generate_response_from_example(
37+
POST_QUESTIONNAIRE_RESPONSE__SUCCESS, 200, headers=header
38+
)
3739
# Duplicate relationship
3840
elif source_identifier == "9000000049":
39-
response = generate_response_from_example(POST_QUESTIONNAIRE_RESPONSE__DUPLICATE_RELATIONSHIP_ERROR, 409)
41+
response = generate_response_from_example(
42+
POST_QUESTIONNAIRE_RESPONSE__DUPLICATE_RELATIONSHIP_ERROR, 409
43+
)
4044
else:
4145
# Out of scope errors
4246
raise ValueError("Invalid Request")

sandbox/api/tests/test_get_consent.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def test_get_consent_returns_expected_responses__mocked_get_consent(
4040
# Act
4141
response = client.get(f"{CONSENT_API_ENDPOINT}?{request_args}")
4242
# Assert
43-
mock_generate_response_from_example.assert_called_once_with(response_file_name, status_code)
43+
mock_generate_response_from_example.assert_called_once_with(
44+
response_file_name, status_code
45+
)
4446
assert response.status_code == status_code
4547
assert response.json == loads(mocked_response.get_data(as_text=True))
4648

@@ -212,7 +214,9 @@ def test_get_consent_returns_expected_responses__mocked_utils(
212214
# Act
213215
response = client.get(f"{CONSENT_API_ENDPOINT}?{request_args}")
214216
# Assert
215-
mock_generate_response_from_example.assert_called_once_with(response_file_name, status_code)
217+
mock_generate_response_from_example.assert_called_once_with(
218+
response_file_name, status_code
219+
)
216220
assert response.status_code == status_code
217221
assert response.json == loads(mocked_response.get_data(as_text=True))
218222

@@ -227,6 +231,10 @@ def test_get_consent__500_internal_server_error(
227231
"""Test Consent endpoint."""
228232
mock_remove_system.side_effect = Exception("Test exception")
229233
# Act
230-
client.get(f"{CONSENT_API_ENDPOINT}?performer:identifier=9000000015&status=active&_include=Consent:performer")
234+
client.get(
235+
f"{CONSENT_API_ENDPOINT}?performer:identifier=9000000015&status=active&_include=Consent:performer"
236+
)
231237
# Assert
232-
mock_generate_response_from_example.assert_called_once_with("./api/examples/errors/internal-server-error.yaml", 500)
238+
mock_generate_response_from_example.assert_called_once_with(
239+
"./api/examples/errors/internal-server-error.yaml", 500
240+
)

0 commit comments

Comments
 (0)