Skip to content

Commit a021ef0

Browse files
authored
New: [AEA-4985] - add validator tests (#219)
## Summary - Routine Change ### Details - add tests for validator in fhir facade
1 parent 800b280 commit a021ef0

File tree

6 files changed

+157
-0
lines changed

6 files changed

+157
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@eps_fhir @smoke @regression @blocker @validator
2+
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4895
3+
Feature: I can call the validator endpoint
4+
5+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
6+
Given I am an authorised prescriber
7+
When I make a valid request to the eps_fhir validator endpoint with show validation set to false
8+
Then the response indicates a success
9+
And the validator response has 1 information issue
10+
11+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to true
12+
Given I am an authorised prescriber
13+
When I make a valid request to the eps_fhir validator endpoint with show validation set to true
14+
Then the response indicates a bad request
15+
And the validator response has many information issue
16+
And the validator response has 0 error issue
17+
18+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
19+
Given I am an authorised prescriber
20+
When I make a valid request to the eps_fhir validator endpoint with show validation set to unset
21+
Then the response indicates a success
22+
And the validator response has 1 information issue
23+
24+
Scenario: I can call the validator endpoint with invalid fhir
25+
Given I am an authorised prescriber
26+
When I make a invalid request to the eps_fhir validator endpoint with show validation set to false
27+
Then the response indicates a bad request
28+
And the validator response has many error issue
29+
And the validator response has error with diagnostic containing Failed to parse JSON encoded FHIR content
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@eps_fhir_dispensing @smoke @regression @validator
2+
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4895
3+
Feature: I can call the validator endpoint
4+
5+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
6+
Given I am an authorised dispenser
7+
When I make a valid request to the eps_fhir_dispensing validator endpoint with show validation set to false
8+
Then the response indicates a success
9+
And the validator response has 1 information issue
10+
11+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to true
12+
Given I am an authorised dispenser
13+
When I make a valid request to the eps_fhir_dispensing validator endpoint with show validation set to true
14+
Then the response indicates a bad request
15+
And the validator response has many information issue
16+
And the validator response has 0 error issue
17+
18+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to unset
19+
Given I am an authorised dispenser
20+
When I make a valid request to the eps_fhir_dispensing validator endpoint with show validation set to unset
21+
Then the response indicates a success
22+
And the validator response has 1 information issue
23+
24+
Scenario: I can call the validator endpoint with invalid fhir
25+
Given I am an authorised dispenser
26+
When I make a invalid request to the eps_fhir_dispensing validator endpoint with show validation set to false
27+
Then the response indicates a bad request
28+
And the validator response has many error issue
29+
And the validator response has error with diagnostic containing Failed to parse JSON encoded FHIR content
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@eps_fhir_prescribing @smoke @regression @validator
2+
@allure.tms:https://nhsd-jira.digital.nhs.uk/browse/AEA-4895
3+
Feature: I can call the validator endpoint
4+
5+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
6+
Given I am an authorised prescriber
7+
When I make a valid request to the eps_fhir_prescribing validator endpoint with show validation set to false
8+
Then the response indicates a success
9+
And the validator response has 1 information issue
10+
11+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to true
12+
Given I am an authorised prescriber
13+
When I make a valid request to the eps_fhir_prescribing validator endpoint with show validation set to true
14+
Then the response indicates a bad request
15+
And the validator response has many information issue
16+
And the validator response has 0 error issue
17+
18+
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
19+
Given I am an authorised prescriber
20+
When I make a valid request to the eps_fhir_prescribing validator endpoint with show validation set to unset
21+
Then the response indicates a success
22+
And the validator response has 1 information issue
23+
24+
Scenario: I can call the validator endpoint with invalid fhir
25+
Given I am an authorised prescriber
26+
When I make a invalid request to the eps_fhir_prescribing validator endpoint with show validation set to false
27+
Then the response indicates a bad request
28+
And the validator response has many error issue
29+
And the validator response has error with diagnostic containing Failed to parse JSON encoded FHIR content

features/steps/common_steps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def indicate_record_created(context):
3434
common.the_expected_response_code_is_returned(context, 201)
3535

3636

37+
@then("the response indicates a bad request")
38+
def indicate_bad_request_response(context):
39+
if "sandbox" in context.config.userdata["env"].lower():
40+
return
41+
common.the_expected_response_code_is_returned(context, 400)
42+
43+
3744
@then("I can see the version information in the response")
3845
def i_see_version_in_response(context):
3946
response = context.response.json()

features/steps/eps_api_steps.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
release_signed_prescription,
1313
return_prescription,
1414
withdraw_dispense_notification,
15+
call_validator,
1516
)
1617
from methods.shared.common import assert_that, get_auth
1718
from utils.random_nhs_number_generator import generate_single
19+
from messages.eps_fhir.prescription import Prescription
1820

1921

2022
@given("I successfully prepare and sign a prescription")
@@ -166,3 +168,43 @@ def i_can_see_an_informational_operation_outcome_in_the_response(context):
166168
assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome")
167169
assert_that(json_response["issue"][0]["code"]).is_equal_to("informational")
168170
assert_that(json_response["issue"][0]["severity"]).is_equal_to("information")
171+
172+
173+
@when(
174+
"I make a {validity} request to the {product} validator endpoint with show validation set to {show_validation}"
175+
)
176+
def i_make_a_request_to_the_validator_endpoint(
177+
context, validity, product, show_validation
178+
):
179+
if validity == "valid":
180+
context.nhs_number = generate_single()
181+
context.nomination_code = "0004"
182+
validate_body = Prescription(context).body
183+
else:
184+
validate_body = "foo"
185+
call_validator(context, product, show_validation, validate_body)
186+
187+
188+
@then("the validator response has {expected_issue_count} {issue_type} issue")
189+
def validator_response_has_n_issues_of_type(context, expected_issue_count, issue_type):
190+
json_response = json.loads(context.response.content)
191+
assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome")
192+
actual_issue_count = sum(
193+
p["severity"] == issue_type for p in json_response["issue"]
194+
)
195+
if expected_issue_count == "many":
196+
assert_that(actual_issue_count).is_greater_than(0)
197+
else:
198+
assert_that(int(expected_issue_count)).is_equal_to(actual_issue_count)
199+
200+
201+
@then("the validator response has error with diagnostic containing {diagnostic}")
202+
def validator_response_has_error_issue_with_diagnostic(context, diagnostic):
203+
json_response = json.loads(context.response.content)
204+
assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome")
205+
print(f"expected diagnostic: {diagnostic}")
206+
actual_issue_count = sum(
207+
p["severity"] == "error" and diagnostic in p["diagnostics"]
208+
for p in json_response["issue"]
209+
)
210+
assert_that(actual_issue_count).is_equal_to(1)

methods/api/eps_api_methods.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,24 @@ def return_prescription(context):
110110

111111
context.return_body = Return(context).body
112112
post(data=context.return_body, url=url, context=context, headers=headers)
113+
114+
115+
def call_validator(context, product, show_validation, validate_body):
116+
if product == "eps_fhir_dispensing":
117+
base_url = context.eps_fhir_dispensing_base_url
118+
elif product == "eps_fhir_prescribing":
119+
base_url = context.eps_fhir_prescribing_base_url
120+
else:
121+
base_url = context.eps_fhir_base_url
122+
url = f"{base_url}/FHIR/R4/$validate"
123+
if show_validation == "false" or show_validation == "true":
124+
additional_headers = {
125+
"Content-Type": "application/json",
126+
"x-show-validation-warnings": show_validation,
127+
}
128+
else:
129+
additional_headers = {"Content-Type": "application/json"}
130+
headers = get_headers(context, additional_headers)
131+
132+
context.validate_body = validate_body
133+
post(data=context.validate_body, url=url, context=context, headers=headers)

0 commit comments

Comments
 (0)