Skip to content

Commit 827eeff

Browse files
committed
tests: updated postman collection and tests
1 parent 732d85f commit 827eeff

10 files changed

+184
-159
lines changed

postman/Validate_Relationship_Service_Sandbox.postman_collection.json

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,25 +1012,24 @@
10121012
"script": {
10131013
"exec": [
10141014
"var expectedResponseBody = {",
1015-
" \"resourceType\": \"OperationOutcome\",",
1016-
" \"issue\": [",
1017-
" {",
1018-
" \"severity\": \"error\",",
1019-
" \"code\": \"invalid\",",
1020-
" \"diagnostics\": \"Not a valid NHS Number provided for the 'identifier' parameter\",",
1021-
" \"expression\": \"RelatedPerson.identifier\",",
1022-
" \"details\": {",
1023-
" \"coding\": [",
1024-
" {",
1025-
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
1026-
" \"version\": \"1\",",
1027-
" \"code\": \"INVALID_IDENTIFIER_VALUE\",",
1028-
" \"display\": \"Provided value is invalid\"",
1029-
" }",
1030-
" ]",
1031-
" }",
1032-
" }",
1033-
" ]",
1015+
" \"issue\": [",
1016+
" {",
1017+
" \"code\": \"invalid\",",
1018+
" \"details\": {",
1019+
" \"coding\": [",
1020+
" {",
1021+
" \"code\": \"INVALID_IDENTIFIER_VALUE\",",
1022+
" \"display\": \"Provided value is invalid\",",
1023+
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
1024+
" \"version\": \"1\"",
1025+
" }",
1026+
" ]",
1027+
" },",
1028+
" \"diagnostics\": \"Not a valid NHS Number provided for the 'identifier' parameter\",",
1029+
" \"severity\": \"error\"",
1030+
" }",
1031+
" ],",
1032+
" \"resourceType\": \"OperationOutcome\"",
10341033
"}",
10351034
"",
10361035
"const responseJson = pm.response.json();",
@@ -4230,24 +4229,24 @@
42304229
"script": {
42314230
"exec": [
42324231
"const expectedResponseBody = {",
4233-
" \"resourceType\": \"OperationOutcome\",",
4234-
" \"issue\": [",
4235-
" {",
4236-
" \"severity\": \"error\",",
4237-
" \"code\": \"invalid\",",
4238-
" \"diagnostics\": \"Invalid request with error - _include parameter is invalid.\",",
4239-
" \"details\": {",
4240-
" \"coding\": [",
4241-
" {",
4242-
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
4243-
" \"version\": \"1\",",
4244-
" \"code\": \"INVALID_VALUE\",",
4245-
" \"display\": \"Required parameter(s) are invalid.\"",
4246-
" }",
4247-
" ]",
4248-
" }",
4249-
" }",
4250-
" ]",
4232+
" \"resourceType\": \"OperationOutcome\",",
4233+
" \"issue\": [",
4234+
" {",
4235+
" \"code\": \"invalid\",",
4236+
" \"details\": {",
4237+
" \"coding\": [",
4238+
" {",
4239+
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
4240+
" \"version\": \"1\",",
4241+
" \"code\": \"INVALID_VALUE\",",
4242+
" \"display\": \"Required parameter(s) are invalid.\"",
4243+
" }",
4244+
" ]",
4245+
" },",
4246+
" \"severity\": \"error\"",
4247+
" }",
4248+
" ],",
4249+
" \"diagnostics\": \"Invalid request with error - _include parameter is invalid.\"",
42514250
"}",
42524251
"",
42534252
"const responseJson = pm.response.json();",
@@ -4367,25 +4366,24 @@
43674366
"script": {
43684367
"exec": [
43694368
"const expectedResponseBody = {",
4370-
" \"resourceType\": \"OperationOutcome\",",
43714369
" \"issue\": [",
43724370
" {",
4373-
" \"severity\": \"error\",",
43744371
" \"code\": \"invalid\",",
4375-
" \"diagnostics\": \"Not a valid NHS Number provided for the 'identifier' parameter\",",
4376-
" \"expression\": \"RelatedPerson.identifier\",",
4372+
" \"diagnostics\": \"Invalid request with error - performer:identifier parameter is invalid.\",",
43774373
" \"details\": {",
43784374
" \"coding\": [",
43794375
" {",
4380-
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
4381-
" \"version\": \"1\",",
43824376
" \"code\": \"INVALID_IDENTIFIER_VALUE\",",
4383-
" \"display\": \"Provided value is invalid\"",
4377+
" \"display\": \"Required parameter(s) are invalid.\",",
4378+
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
4379+
" \"version\": \"1\"",
43844380
" }",
43854381
" ]",
4386-
" }",
4382+
" },",
4383+
" \"severity\": \"error\"",
43874384
" }",
4388-
" ]",
4385+
" ],",
4386+
" \"resourceType\": \"OperationOutcome\"",
43894387
"}",
43904388
"",
43914389
"const responseJson = pm.response.json();",
@@ -4438,17 +4436,17 @@
44384436
" \"issue\": [",
44394437
" {",
44404438
" \"code\": \"invalid\",",
4439+
" \"diagnostics\": \"Invalid request with error - performer:identifier system parameter is invalid.\",",
44414440
" \"details\": {",
44424441
" \"coding\": [",
44434442
" {",
44444443
" \"code\": \"INVALID_IDENTIFIER_SYSTEM\",",
4445-
" \"display\": \"Invalid identifier system.\",",
4444+
" \"display\": \"Required parameter(s) are invalid.\",",
44464445
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
44474446
" \"version\": \"1\"",
44484447
" }",
44494448
" ]",
44504449
" },",
4451-
" \"diagnostics\": \"The identifier system is not valid.\",",
44524450
" \"severity\": \"error\"",
44534451
" }",
44544452
" ],",
@@ -4502,24 +4500,24 @@
45024500
"script": {
45034501
"exec": [
45044502
"const expectedResponseBody = {",
4505-
" \"resourceType\": \"OperationOutcome\",",
4506-
" \"issue\": [",
4507-
" {",
4508-
" \"severity\": \"error\",",
4509-
" \"code\": \"invalid\",",
4510-
" \"diagnostics\": \"The 'identifier' parameter is required\",",
4511-
" \"details\": {",
4512-
" \"coding\": [",
4513-
" {",
4514-
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
4515-
" \"version\": \"1\",",
4516-
" \"code\": \"MISSING_IDENTIFIER_VALUE\",",
4517-
" \"display\": \"Missing RelatedPerson NHS number.\"",
4518-
" }",
4519-
" ]",
4520-
" }",
4521-
" }",
4522-
" ]",
4503+
" \"issue\": [",
4504+
" {",
4505+
" \"code\": \"invalid\",",
4506+
" \"diagnostics\": \"Invalid request with error - performer:identifier parameter not found.\",",
4507+
" \"details\": {",
4508+
" \"coding\": [",
4509+
" {",
4510+
" \"code\": \"MISSING_IDENTIFIER_VALUE\",",
4511+
" \"display\": \"Required parameter(s) are missing.\",",
4512+
" \"system\": \"https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode\",",
4513+
" \"version\": \"1\"",
4514+
" }",
4515+
" ]",
4516+
" },",
4517+
" \"severity\": \"error\"",
4518+
" }",
4519+
" ],",
4520+
" \"resourceType\": \"OperationOutcome\"",
45234521
"}",
45244522
"",
45254523
"const responseJson = pm.response.json();",

sandbox/api/app.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
INTERNAL_SERVER_ERROR_EXAMPLE,
99
LIST_RELATIONSHIP,
1010
LIST_RELATIONSHIP_INCLUDE,
11-
NOT_FOUND,
11+
INVALIDATED_RESOURCE,
1212
QUESTIONNAIRE_RESPONSE_SUCCESS,
1313
VALIDATE_RELATIONSHIP_009,
1414
VALIDATE_RELATIONSHIP_025,
@@ -29,7 +29,8 @@
2929
)
3030
from .utils import (
3131
check_for_empty,
32-
check_for_errors,
32+
check_for_consent_errors,
33+
check_for_related_person_errors,
3334
check_for_list,
3435
check_for_validate,
3536
generate_response,
@@ -67,7 +68,7 @@ def get_related_persons() -> Union[dict, tuple]:
6768

6869
try:
6970
# Check Headers
70-
if errors := check_for_errors(request, "identifier"):
71+
if errors := check_for_related_person_errors(request):
7172
return errors
7273

7374
identifier = remove_system(request.args.get("identifier"))
@@ -138,7 +139,7 @@ def get_consent() -> Union[dict, tuple]:
138139
"""
139140
try:
140141
# Check Headers
141-
if errors := check_for_errors(request, "performer:identifier"):
142+
if errors := check_for_consent_errors(request):
142143
return errors
143144

144145
performer_identifier = remove_system(request.args.get("performer:identifier"))
@@ -149,15 +150,13 @@ def get_consent() -> Union[dict, tuple]:
149150
if performer_identifier == "9000000010":
150151
return check_for_consent_include_params(
151152
_include,
152-
logger,
153153
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP,
154154
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH,
155155
)
156156
# Single mother child relationship
157157
elif performer_identifier == "9000000019":
158158
return check_for_consent_include_params(
159159
_include,
160-
logger,
161160
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP,
162161
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH,
163162
)
@@ -172,7 +171,6 @@ def get_consent() -> Union[dict, tuple]:
172171
elif performer_identifier == "9000000022":
173172
return check_for_consent_include_params(
174173
_include,
175-
logger,
176174
CONSENT__MULTIPLE_RELATIONSHIPS,
177175
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_BOTH,
178176
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PATIENT,
@@ -183,7 +181,7 @@ def get_consent() -> Union[dict, tuple]:
183181
return generate_response_from_example(CONSENT__NO_RELATIONSHIPS, 200)
184182
else:
185183
logger.error("Performer identifier does not match examples")
186-
return generate_response_from_example(NOT_FOUND, 404)
184+
return generate_response_from_example(INVALIDATED_RESOURCE, 404)
187185

188186
except Exception as e:
189187
logger.error(e)

sandbox/api/constants.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,42 @@
3737
BAD_REQUEST_INCLUDE_PARAM_INVALID = (
3838
"./api/examples/errors/invalid-include-parameter.yaml"
3939
)
40-
NOT_FOUND = "./api/examples/errors/not-found.yaml"
40+
INVALIDATED_RESOURCE = "./api/examples/errors/invalidated-resource.yaml"
4141
MISSING_IDENTIFIER = "./api/examples/errors/missing-identifier.yaml"
4242
INVALID_IDENTIFIER = "./api/examples/errors/invalid-identifier.yaml"
4343

4444
# Consent examples
45-
consent_dir = "./api/examples/GET_Consent/"
45+
CONSENT__DIRECTORY = "./api/examples/GET_Consent/"
4646
CONSENT__FILTERED_RELATIONSHIPS_STATUS_ACTIVE = (
47-
consent_dir + "filtered-relationships-status-active.yaml"
47+
f"{CONSENT__DIRECTORY}filtered-relationships-status-active.yaml"
4848
)
4949
CONSENT__FILTERED_RELATIONSHIPS_STATUS_INACTIVE = (
50-
consent_dir + "filtered-relationships-status-inactive.yaml"
50+
f"{CONSENT__DIRECTORY}filtered-relationships-status-inactive.yaml"
5151
)
5252
CONSENT__FILTERED_RELATIONSHIPS_STATUS_PROPOSED_ACTIVE = (
53-
consent_dir + "filtered-relationships-status-proposed-active.yaml"
53+
f"{CONSENT__DIRECTORY}filtered-relationships-status-proposed-active.yaml"
5454
)
55-
CONSENT__MULTIPLE_RELATIONSHIPS = consent_dir + "multiple-relationships.yaml"
55+
CONSENT__MULTIPLE_RELATIONSHIPS = f"{CONSENT__DIRECTORY}multiple-relationships.yaml"
5656
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_BOTH = (
57-
consent_dir + "multiple-relationships-include-performer-patient.yaml"
57+
f"{CONSENT__DIRECTORY}multiple-relationships-include-performer-patient.yaml"
5858
)
5959
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PATIENT = (
60-
consent_dir + "multiple-relationships-include-patient.yaml"
60+
f"{CONSENT__DIRECTORY}multiple-relationships-include-patient.yaml"
6161
)
6262
CONSENT__MULTIPLE_RELATIONSHIPS_INCLUDE_PERFORMER = (
63-
consent_dir + "multiple-relationships-include-performer.yaml"
63+
f"{CONSENT__DIRECTORY}multiple-relationships-include-performer.yaml"
6464
)
65-
CONSENT__NO_RELATIONSHIPS = consent_dir + "no-relationships.yaml"
65+
CONSENT__NO_RELATIONSHIPS = f"{CONSENT__DIRECTORY}no-relationships.yaml"
6666
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP = (
67-
consent_dir + "single-consenting-adult-relationship.yaml"
67+
f"{CONSENT__DIRECTORY}single-consenting-adult-relationship.yaml"
6868
)
6969
CONSENT__SINGLE_CONSENTING_ADULT_RELATIONSHIP_INCLUDE_BOTH = (
70-
consent_dir + "single-consenting-adult-relationship-include-performer-patient.yaml"
70+
f"{CONSENT__DIRECTORY}single-consenting-adult-relationship-include-performer-patient.yaml"
7171
)
7272
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP = (
73-
consent_dir + "single-mother-child-relationship.yaml"
73+
f"{CONSENT__DIRECTORY}single-mother-child-relationship.yaml"
7474
)
7575
CONSENT__SINGLE_MOTHER_CHILD_RELATIONSHIP_INCLUDE_BOTH = (
76-
consent_dir + "single-mother-child-relationship-include-performer-patient.yaml"
76+
f"{CONSENT__DIRECTORY}single-mother-child-relationship-include-performer-patient.yaml"
7777
)
78-
CONSENT__STATUS_PARAM_INVALID = consent_dir + "errors/invalid-status-parameter.yaml"
78+
CONSENT__STATUS_PARAM_INVALID = f"{CONSENT__DIRECTORY}errors/invalid-status-parameter.yaml"

sandbox/api/responses/bad_request_identifier_invalid.json renamed to sandbox/api/responses/GET_RelatedPerson/bad_request_identifier_invalid.json

File renamed without changes.

sandbox/api/responses/bad_request_identifier_invalid_system.json renamed to sandbox/api/responses/GET_RelatedPerson/bad_request_identifier_invalid_system.json

File renamed without changes.

sandbox/api/responses/bad_request_identifier_missing.json renamed to sandbox/api/responses/GET_RelatedPerson/bad_request_identifier_missing.json

File renamed without changes.

sandbox/api/responses/bad_request_include_param_invalid.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

sandbox/api/tests/test_app.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import json
2-
from json import dumps
1+
from json import dumps, loads
32
from unittest.mock import MagicMock, patch
43

54
import pytest
@@ -141,13 +140,13 @@ def test_questionnaire_response(
141140
),
142141
(
143142
"performer:identifier=9000000999", # No performer record found error
144-
"./api/examples/errors/not-found.yaml",
143+
"./api/examples/errors/invalidated-resource.yaml",
145144
404,
146145
),
147146
],
148147
)
149148
@patch(f"{APP_FILE_PATH}.generate_response_from_example")
150-
def test_consent_from_app(
149+
def test_consent(
151150
mock_generate_response_from_example: MagicMock,
152151
request_args: str,
153152
response_file_name: str,
@@ -165,7 +164,7 @@ def test_consent_from_app(
165164
response_file_name, status_code
166165
)
167166
assert response.status_code == status_code
168-
assert response.json == json.loads(mocked_response.get_data(as_text=True))
167+
assert response.json == loads(mocked_response.get_data(as_text=True))
169168

170169

171170
@patch(f"{APP_FILE_PATH}.remove_system")

0 commit comments

Comments
 (0)