|
12 | 12 | release_signed_prescription, |
13 | 13 | return_prescription, |
14 | 14 | withdraw_dispense_notification, |
| 15 | + call_validator, |
15 | 16 | ) |
16 | 17 | from methods.shared.common import assert_that, get_auth |
17 | 18 | from utils.random_nhs_number_generator import generate_single |
| 19 | +from messages.eps_fhir.prescription import Prescription |
18 | 20 |
|
19 | 21 |
|
20 | 22 | @given("I successfully prepare and sign a prescription") |
@@ -166,3 +168,43 @@ def i_can_see_an_informational_operation_outcome_in_the_response(context): |
166 | 168 | assert_that(json_response["resourceType"]).is_equal_to("OperationOutcome") |
167 | 169 | assert_that(json_response["issue"][0]["code"]).is_equal_to("informational") |
168 | 170 | 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) |
0 commit comments