|
12 | 12 | release_signed_prescription, |
13 | 13 | return_prescription, |
14 | 14 | withdraw_dispense_notification, |
| 15 | + get_headers, |
| 16 | + post, |
15 | 17 | ) |
16 | 18 | from methods.shared.common import assert_that, get_auth |
17 | 19 | from utils.random_nhs_number_generator import generate_single |
| 20 | +from messages.eps_fhir.prescription import Prescription |
18 | 21 |
|
19 | 22 |
|
20 | 23 | @given("I successfully prepare and sign a prescription") |
@@ -166,3 +169,31 @@ def i_can_see_an_informational_operation_outcome_in_the_response(context): |
166 | 169 | assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome") |
167 | 170 | assert_that(json_response["issue"][0]["code"]).is_equal_to("informational") |
168 | 171 | assert_that(json_response["issue"][0]["severity"]).is_equal_to("information") |
| 172 | + |
| 173 | + |
| 174 | +@when("I make a request to the {product} validator endpoint") |
| 175 | +def i_make_a_request_to_the_validator_endpoint(context, product): |
| 176 | + base_url = None |
| 177 | + if product == "eps_fhir": |
| 178 | + base_url = context.eps_fhir_base_url |
| 179 | + if product == "eps_fhir_prescribing": |
| 180 | + base_url = context.eps_fhir_prescribing_base_url |
| 181 | + if product == "eps_fhir_dispensing": |
| 182 | + base_url = context.eps_fhir_dispensing_base_url |
| 183 | + if base_url is not None: |
| 184 | + url = f"{base_url}/FHIR/R4/$validate" |
| 185 | + additional_headers = {"Content-Type": "application/json"} |
| 186 | + headers = get_headers(context, additional_headers) |
| 187 | + |
| 188 | + context.prepare_body = Prescription(context).body |
| 189 | + post(data=context.prepare_body, url=url, context=context, headers=headers) |
| 190 | + else: |
| 191 | + raise ValueError(f"unable to find base url for '{product}'") |
| 192 | + |
| 193 | + |
| 194 | +@then("the validator response has {issue_count} {issue_type} issue") |
| 195 | +def validator_response_has_n_issues_of_type(context, issue_count, issue_type): |
| 196 | + json_response = json.loads(context.response.content) |
| 197 | + assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome") |
| 198 | + assert_that(json_response["issue"][0]["code"]).is_equal_to("informational") |
| 199 | + assert_that(json_response["issue"][0]["severity"]).is_equal_to("information") |
0 commit comments