Skip to content

Commit 68ab5c9

Browse files
committed
more tests
1 parent 4d83b76 commit 68ab5c9

File tree

5 files changed

+83
-11
lines changed

5 files changed

+83
-11
lines changed

features/eps_fhir/validator.feature

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Feature: I can call the validator endpoint
44

55
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
66
Given I am an authorised prescriber
7-
When I make a request to the eps_fhir validator endpoint
7+
When I make a valid request to the eps_fhir validator endpoint with show validation set to false
88
Then the response indicates a success
99
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 success
15+
And the validator response has many information issue
16+
17+
Scenario: I can call the validator endpoint with invalid fhir
18+
Given I am an authorised prescriber
19+
When I make a invalid request to the eps_fhir validator endpoint with show validation set to false
20+
Then the response indicates a bad request
21+
And the validator response has many error issue
22+
And the validator response has error with diagnostic "HAPI-1861: Failed to parse JSON encoded FHIR content: HAPI-1859: Content does not appear to be FHIR JSON, first non-whitespace character was: '\"' (must be '{')"

features/eps_fhir_dispensing/validator.feature

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Feature: I can call the validator endpoint
44

55
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
66
Given I am an authorised dispenser
7-
When I make a request to the eps_fhir_dispensing validator endpoint
7+
When I make a valid request to the eps_fhir validator endpoint with show validation set to false
88
Then the response indicates a success
99
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 validator endpoint with show validation set to true
14+
Then the response indicates a success
15+
And the validator response has many information issue
16+
17+
Scenario: I can call the validator endpoint with invalid fhir
18+
Given I am an authorised dispenser
19+
When I make a invalid request to the eps_fhir validator endpoint with show validation set to false
20+
Then the response indicates a bad request
21+
And the validator response has many error issue
22+
And the validator response has error with diagnostic "HAPI-1861: Failed to parse JSON encoded FHIR content: HAPI-1859: Content does not appear to be FHIR JSON, first non-whitespace character was: '\"' (must be '{')"

features/eps_fhir_prescribing/validator.feature

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ Feature: I can call the validator endpoint
44

55
Scenario: I can call the validator endpoint with valid fhir with x-show-validation-warnings set to false
66
Given I am an authorised prescriber
7-
When I make a request to the eps_fhir_prescribing validator endpoint
7+
When I make a valid request to the eps_fhir validator endpoint with show validation set to false
88
Then the response indicates a success
99
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 success
15+
And the validator response has many information issue
16+
17+
Scenario: I can call the validator endpoint with invalid fhir
18+
Given I am an authorised prescriber
19+
When I make a invalid request to the eps_fhir validator endpoint with show validation set to false
20+
Then the response indicates a bad request
21+
And the validator response has many error issue
22+
And the validator response has error with diagnostic "HAPI-1861: Failed to parse JSON encoded FHIR content: HAPI-1859: Content does not appear to be FHIR JSON, first non-whitespace character was: '\"' (must be '{')"

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: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,12 @@ def i_can_see_an_informational_operation_outcome_in_the_response(context):
171171
assert_that(json_response["issue"][0]["severity"]).is_equal_to("information")
172172

173173

174-
@when("I make a request to the {product} validator endpoint")
175-
def i_make_a_request_to_the_validator_endpoint(context, product):
174+
@when(
175+
"I make a {validity} request to the {product} validator endpoint with show validation set to {show_validation}"
176+
)
177+
def i_make_a_request_to_the_validator_endpoint(
178+
context, validity, product, show_validation
179+
):
176180
base_url = None
177181
if product == "eps_fhir":
178182
base_url = context.eps_fhir_base_url
@@ -182,20 +186,42 @@ def i_make_a_request_to_the_validator_endpoint(context, product):
182186
base_url = context.eps_fhir_dispensing_base_url
183187
if base_url is not None:
184188
url = f"{base_url}/FHIR/R4/$validate"
185-
additional_headers = {"Content-Type": "application/json"}
189+
additional_headers = {
190+
"Content-Type": "application/json",
191+
"x-show-validation-warnings": show_validation,
192+
}
186193
headers = get_headers(context, additional_headers)
187194

188195
context.nhs_number = generate_single()
189196
context.nomination_code = "0004"
190-
context.prepare_body = Prescription(context).body
197+
if validity == "valid":
198+
context.prepare_body = Prescription(context).body
199+
else:
200+
context.prepare_body = "foo"
191201
post(data=context.prepare_body, url=url, context=context, headers=headers)
192202
else:
193203
raise ValueError(f"unable to find base url for '{product}'")
194204

195205

196-
@then("the validator response has {issue_count} {issue_type} issue")
197-
def validator_response_has_n_issues_of_type(context, issue_count, issue_type):
206+
@then("the validator response has {expected_issue_count} {issue_type} issue")
207+
def validator_response_has_n_issues_of_type(context, expected_issue_count, issue_type):
198208
json_response = json.loads(context.response.content)
199209
assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome")
200-
assert_that(json_response["issue"][0]["code"]).is_equal_to("informational")
201-
assert_that(json_response["issue"][0]["severity"]).is_equal_to("information")
210+
actual_issue_count = sum(
211+
p["severity"] == issue_type for p in json_response["issue"]
212+
)
213+
if expected_issue_count == "many":
214+
assert_that(expected_issue_count).is_greater_than(0)
215+
else:
216+
assert_that(expected_issue_count).is_equal_to(actual_issue_count)
217+
218+
219+
@then("the validator response has error with diagnostic {diagnostic}")
220+
def validator_response_has_error_issue_with_diagnostic(context, diagnostic):
221+
json_response = json.loads(context.response.content)
222+
assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome")
223+
actual_issue_count = sum(
224+
p["severity"] == "error" and p["diagnostics"] == diagnostic
225+
for p in json_response["issue"]
226+
)
227+
assert_that(actual_issue_count).is_equal_to(1)

0 commit comments

Comments
 (0)