Skip to content

Commit e5d7f3b

Browse files
committed
NPA-3899 Fix Unit Tests
1 parent 07e580f commit e5d7f3b

File tree

11 files changed

+192
-116
lines changed

11 files changed

+192
-116
lines changed

sandbox/README.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22

33
This folder contains a sandbox API for initial development
44

5-
6-
For more information about building sandbox APIs see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Setting+up+your+API+sandbox ).
5+
For more information about building sandbox APIs see the [API Producer Zone confluence](https://nhsd-confluence.digital.nhs.uk/display/APM/Setting+up+your+API+sandbox).
76

87
## Table of Contents
98

10-
- [Sandbox](#sandbox)
11-
- [Table of Contents](#table-of-contents)
12-
- [Prerequisites](#prerequisites)
13-
- [Quick Start](#quick-start)
14-
- [Installing dependencies](#installing-dependencies)
15-
- [Starting the API](#starting-the-api)
16-
- [Development](#development)
17-
- [Starting the API with Hot Reloading](#starting-the-api-with-hot-reloading)
18-
- [Testing](#testing)
19-
- [Unit Tests](#unit-tests)
20-
- [Useful commands](#useful-commands)
9+
- [Sandbox](#sandbox)
10+
- [Table of Contents](#table-of-contents)
11+
- [Prerequisites](#prerequisites)
12+
- [Quick Start](#quick-start)
13+
- [Installing dependencies](#installing-dependencies)
14+
- [Starting the API](#starting-the-api)
15+
- [Development](#development)
16+
- [Starting the API with Hot Reloading](#starting-the-api-with-hot-reloading)
17+
- [Testing](#testing)
18+
- [Unit Tests](#unit-tests)
19+
- [Useful commands](#useful-commands)
2120

2221
## Prerequisites
2322

24-
- Python 3.8
25-
- [Poetry](https://python-poetry.org/docs/)
26-
- [Docker](https://docs.docker.com/get-docker/)
23+
- Python 3.8
24+
- [Poetry](https://python-poetry.org/docs/)
25+
- [Docker](https://docs.docker.com/get-docker/)
2726

2827
## Quick Start
2928

@@ -53,7 +52,6 @@ To run the API with hot reloading use `make start-dev`
5352

5453
Unit tests can be run using `make test`
5554

56-
5755
### Useful commands
5856

5957
For more useful development commands review the [Makefile](Makefile) or run `make list`

sandbox/api/app.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@
33

44
from flask import Flask, request
55

6-
from .utils import (
7-
check_for_empty,
8-
check_for_errors,
9-
check_for_list,
10-
check_for_validate,
11-
generate_response,
12-
load_json_file,
13-
remove_system,
14-
generate_response_from_example,
15-
)
166
from .constants import (
7+
CONSENT__ADULT_CONSENTING_EXAMPLE,
8+
CONSENT__MIXED_EXAMPLE,
9+
CONSENT__MOTHER_CHILD_EXAMPLE,
10+
CONSENT_PERFORMER,
1711
INTERNAL_ERROR_RESPONSE,
12+
INTERNAL_SERVER_ERROR_EXAMPLE,
1813
LIST_RELATIONSHIP,
1914
LIST_RELATIONSHIP_INCLUDE,
15+
NOT_FOUND,
2016
QUESTIONNAIRE_RESPONSE_SUCCESS,
2117
VALIDATE_RELATIONSHIP_009,
2218
VALIDATE_RELATIONSHIP_025,
2319
VALIDATE_RELATIONSHIP_INCLUDE_009,
2420
VALIDATE_RELATIONSHIP_INCLUDE_025,
25-
INTERNAL_SERVER_ERROR_EXAMPLE,
26-
CONSENT__ADULT_CONSENTING_EXAMPLE,
27-
CONSENT__MIXED_EXAMPLE,
28-
CONSENT__MOTHER_CHILD_EXAMPLE,
29-
CONSENT_PERFORMER,
21+
)
22+
from .utils import (
23+
check_for_empty,
24+
check_for_errors,
25+
check_for_list,
26+
check_for_validate,
27+
generate_response,
28+
generate_response_from_example,
29+
load_json_file,
30+
remove_system,
3031
)
3132

3233
app = Flask(__name__)
@@ -150,10 +151,8 @@ def get_consent() -> Union[dict, tuple]:
150151
and _include == CONSENT_PERFORMER
151152
):
152153
return generate_response_from_example(CONSENT__MOTHER_CHILD_EXAMPLE, 200)
153-
# else:
154-
# logger.error(e)
155-
# return generate_response(load_json_file(ERROR_RESPONSE), 400)
156-
154+
else:
155+
return generate_response(load_json_file(NOT_FOUND), 400)
157156
except Exception as e:
158157
logger.error(e)
159158
return generate_response_from_example(INTERNAL_SERVER_ERROR_EXAMPLE, 500)
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"issue": [
3-
{
4-
"code": "invalid",
5-
"details": {
6-
"coding": [
7-
{
8-
"code": "INVALID_IDENTIFIER_SYSTEM",
9-
"display": "Invalid identifier system.",
10-
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
11-
"version": "1"
12-
}
13-
]
14-
},
15-
"diagnostics": "The identifier system is not valid.",
16-
"severity": "error"
17-
}
3+
{
4+
"code": "invalid",
5+
"details": {
6+
"coding": [
7+
{
8+
"code": "INVALID_IDENTIFIER_SYSTEM",
9+
"display": "Invalid identifier system.",
10+
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
11+
"version": "1"
12+
}
13+
]
14+
},
15+
"diagnostics": "The identifier system is not valid.",
16+
"severity": "error"
17+
}
1818
],
1919
"resourceType": "OperationOutcome"
2020
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
21
{
32
"issue": [
4-
{
5-
"code": "invalid",
6-
"details": {
7-
"coding": [
8-
{
9-
"code": "MISSING_IDENTIFIER_VALUE",
10-
"display": "Missing RelatedPerson NHS number.",
11-
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
12-
"version": "1"
13-
}
14-
]
15-
},
16-
"diagnostics": "The 'identifier' parameter is required",
17-
"severity": "error"
18-
}
3+
{
4+
"code": "invalid",
5+
"details": {
6+
"coding": [
7+
{
8+
"code": "MISSING_IDENTIFIER_VALUE",
9+
"display": "Missing RelatedPerson NHS number.",
10+
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
11+
"version": "1"
12+
}
13+
]
14+
},
15+
"diagnostics": "The 'identifier' parameter is required",
16+
"severity": "error"
17+
}
1918
],
2019
"resourceType": "OperationOutcome"
2120
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"link": [
3-
{
4-
"relation": "self",
5-
"url": "https://sandbox.api.service.nhs.uk/validated-relationships-service-api/FHIR/R4/RelatedPerson?identifier=9000000033"
6-
}
7-
],
8-
"timestamp": "2024-01-01T00:00:00+00:00",
9-
"total": 0,
10-
"type": "searchset",
11-
"resourceType": "Bundle"
12-
}
2+
"link": [
3+
{
4+
"relation": "self",
5+
"url": "https://sandbox.api.service.nhs.uk/validated-relationships-service-api/FHIR/R4/RelatedPerson?identifier=9000000033"
6+
}
7+
],
8+
"timestamp": "2024-01-01T00:00:00+00:00",
9+
"total": 0,
10+
"type": "searchset",
11+
"resourceType": "Bundle"
12+
}

sandbox/api/responses/GET_RelatedPerson/list_relationship_9000000017.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@
7575
"total": 2,
7676
"type": "searchset",
7777
"resourceType": "Bundle"
78-
}
78+
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"issue": [
3-
{
4-
"code": "exception",
5-
"details": {
6-
"coding": [
7-
{
8-
"code": "SERVER_ERROR",
9-
"display": "Failed to generate response",
10-
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
11-
"version": "1"
12-
}
13-
]
14-
},
15-
"diagnostics": "Internal Server Error - Failed to generate response",
16-
"severity": "error"
17-
}
3+
{
4+
"code": "exception",
5+
"details": {
6+
"coding": [
7+
{
8+
"code": "SERVER_ERROR",
9+
"display": "Failed to generate response",
10+
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
11+
"version": "1"
12+
}
13+
]
14+
},
15+
"diagnostics": "Internal Server Error - Failed to generate response",
16+
"severity": "error"
17+
}
1818
],
1919
"resourceType": "OperationOutcome"
2020
}
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"issue": [
3-
{
4-
"code": "processing",
5-
"details": {
6-
"coding": [
7-
{
8-
"code": "INVALIDATED_RESOURCE",
9-
"display": "Resource that has been marked as invalid was requested - invalid resources cannot be retrieved",
10-
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
11-
"version": "1"
12-
}
13-
]
14-
},
15-
"severity": "error"
16-
}
17-
],
18-
"resourceType": "OperationOutcome"
19-
}
2+
"issue": [
3+
{
4+
"code": "processing",
5+
"details": {
6+
"coding": [
7+
{
8+
"code": "INVALIDATED_RESOURCE",
9+
"display": "Resource that has been marked as invalid was requested - invalid resources cannot be retrieved",
10+
"system": "https://fhir.nhs.uk/R4/CodeSystem/ValidatedRelationships-ErrorOrWarningCode",
11+
"version": "1"
12+
}
13+
]
14+
},
15+
"severity": "error"
16+
}
17+
],
18+
"resourceType": "OperationOutcome"
19+
}

sandbox/api/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
FHIR_PATH = "/FHIR/R4"
66
RELATED_PERSON_API_ENDPOINT = f"{FHIR_PATH}/RelatedPerson"
77
QUESTIONNAIRE_RESPONSE_API_ENDPOINT = f"{FHIR_PATH}/QuestionnaireResponse"
8+
CONSENT_API_ENDPOINT = f"{FHIR_PATH}/Consent"
89

910

1011
@pytest.fixture()

0 commit comments

Comments
 (0)