def test_transform_event_to_sirius_request( default_supporting_doc_request_body, default_request_case_ref, default_request_report_id, default_sirius_supporting_docs_request, default_sirius_supporting_docs_request_with_parent_id, ): path_params = { "caseref": default_request_case_ref, "id": default_request_report_id } event = build_aws_event( event_body=json.dumps(default_supporting_doc_request_body), event_path_parementers=path_params, as_json=False, ) payload = transform_event_to_sirius_post_request(event) assert is_valid_schema(json.loads(payload), "sirius_documents_payload_schema.json") assert payload == json.dumps(default_sirius_supporting_docs_request) payload2 = transform_event_to_sirius_post_request( event, parent_id="5783a7ad-9251-4cc7-80e3-c411c3bd87e0") assert is_valid_schema(json.loads(payload2), "sirius_documents_payload_schema.json") assert payload2 == json.dumps( default_sirius_supporting_docs_request_with_parent_id)
def test_validate_payload(case_data: CaseDataGetter): body, case_ref, report_id, expected_result = case_data.get() path_params = {"caseref": case_ref, "id": report_id} event = build_aws_event(event_body=json.dumps(body), event_path_parementers=path_params, as_json=False) valid_event, errors = validate_event(event) assert valid_event == expected_result[0] assert sorted(errors) == sorted(expected_result[1])
def test_sirius_request_has_and_submission_id( default_report_request_body, default_request_case_ref, default_sirius_reports_request, ): path_params = {"caseref": default_request_case_ref} event = build_aws_event( event_body=json.dumps(default_report_request_body), event_path_parementers=path_params, as_json=False, ) payload = transform_event_to_sirius_request(event) assert json.loads(payload)["metadata"]["submission_id"]
def test_transform_event_to_sirius_request( default_report_request_body, default_request_case_ref, default_sirius_reports_request, ): path_params = {"caseref": default_request_case_ref} event = build_aws_event( event_body=json.dumps(default_report_request_body), event_path_parementers=path_params, as_json=False, ) payload = transform_event_to_sirius_request(event) assert is_valid_schema(json.loads(payload), "sirius_documents_payload_schema.json") assert payload == json.dumps(default_sirius_reports_request)
def test_sirius_request_has_report_id_from_path( default_supporting_doc_request_body, default_request_case_ref, default_request_report_id, default_sirius_supporting_docs_request, ): default_supporting_doc_request_body["supporting_document"]["data"][ "attributes"]["report_id"] = "uuid_from_attributes" path_params = {"caseref": default_request_case_ref, "id": "uuid_from_path"} event = build_aws_event( event_body=json.dumps(default_supporting_doc_request_body), event_path_parementers=path_params, as_json=False, ) payload = transform_event_to_sirius_post_request(event) assert json.loads(payload)["metadata"]["report_id"] == "uuid_from_path"
def test_lambda_handler_invalid_event( patched_requests, patched_get_secret, patched_validate_event_fail, default_request_case_ref, default_report_request_body, ): path_params = {"caseref": default_request_case_ref} event = build_aws_event( event_body=json.dumps(default_report_request_body), event_path_parementers=path_params, as_json=False, ) context = None result = lambda_handler(event=event, context=context) assert is_valid_schema(result, "standard_lambda_response_schema.json") assert result["statusCode"] == 400
def test_transform_event_to_sirius_request_with_no_report_submission( default_request_case_ref, nondigital_request_report_id, checklists_request_body_with_no_report_submission, sirius_checklists_request_with_no_report_submission, ): path_params = { "caseref": default_request_case_ref, "id": nondigital_request_report_id, } event = build_aws_event( event_body=json.dumps( checklists_request_body_with_no_report_submission), event_path_parementers=path_params, as_json=False, ) payload = transform_event_to_sirius_payload(event) assert is_valid_schema(json.loads(payload), "sirius_documents_payload_schema.json") assert payload == json.dumps( sirius_checklists_request_with_no_report_submission)