diff --git a/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_express_message_pattern_tests.py b/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_express_message_pattern_tests.py index a57a179a5..c1ee18929 100644 --- a/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_express_message_pattern_tests.py +++ b/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_express_message_pattern_tests.py @@ -18,24 +18,48 @@ class AsynchronousExpressMssagingPatternTests(unittest.TestCase): They make use of the fake-spine-route-lookup service, which has known responses for certain interaction ids. """ + INTERACTION_ID = 'QUPC_IN160101UK05' + SOAP_FAULT_MESSAGE_ID = 'AD7D39A8-1B6C-4520-8367-6B7BEBD7B842' + EBXML_FAULT_MESSAGE_ID = '7AA57E38-8B20-4AE0-9E73-B9B0C0C42BDA' + def setUp(self): MHS_STATE_TABLE_WRAPPER.clear_all_records_in_table() MHS_SYNC_ASYNC_TABLE_WRAPPER.clear_all_records_in_table() + def _build_message(self, ods_code, message_id=None): + return build_message(self.INTERACTION_ID, ods_code, message_id=message_id) + + def _post_error(self, message_id, message, wait_for_response): + return MhsHttpRequestBuilder() \ + .with_headers( + interaction_id=self.INTERACTION_ID, + message_id=message_id, + wait_for_response=wait_for_response + ) \ + .with_body(message) \ + .execute_post_expecting_error_response() + + def _assert_state(self, message_id, expected_values): + MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ + .assert_single_item_exists_with_key(message_id) \ + .assert_item_contains_values(expected_values) + def test_should_return_information_from_soap_fault_returned_from_spine_in_original_post_request_to_client(self): """ Message ID: AD7D39A8-1B6C-4520-8367-6B7BEBD7B842 configured in fakespine to return a SOAP Fault error. Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='AD7D39A8-1B6C-4520-8367-6B7BEBD7B842' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + message_id, + message, + wait_for_response=False + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -49,25 +73,27 @@ def test_should_record_message_status_as_nackd_when_soap_error_response_returned Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='AD7D39A8-1B6C-4520-8367-6B7BEBD7B842' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + message_id, + message, + wait_for_response=False + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', 'WORKFLOW': 'async-express' - }) + } + ) def test_should_return_information_from_ebxml_fault_returned_from_spine_in_original_post_request(self): """ @@ -75,14 +101,16 @@ def test_should_return_information_from_ebxml_fault_returned_from_spine_in_origi Error found here: fake_spine/fake_spine/configured_responses/ebxml_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='7AA57E38-8B20-4AE0-9E73-B9B0C0C42BDA' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + message_id, + message, + wait_for_response=False + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -96,24 +124,26 @@ def test_should_record_message_status_as_nackd_when_ebxml_error_response_returne Error found here: fake_spine/fake_spine/configured_responses/ebxml_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='7AA57E38-8B20-4AE0-9E73-B9B0C0C42BDA' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + message_id, + message, + wait_for_response=False + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', 'WORKFLOW': 'async-express' - }) + } + ) def test_should_return_information_from_soap_fault_returned_from_spine_in_original_request_to_client_when_wait_for_response_requested(self): """ @@ -121,14 +151,16 @@ def test_should_return_information_from_soap_fault_returned_from_spine_in_origin Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='AD7D39A8-1B6C-4520-8367-6B7BEBD7B842' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + message_id, + message, + wait_for_response=True + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -142,24 +174,26 @@ def test_should_record_message_status_when_soap_error_response_returned_from_spi Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='AD7D39A8-1B6C-4520-8367-6B7BEBD7B842' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + message_id, + message, + wait_for_response=True + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', 'WORKFLOW': 'sync-async' - }) + } + ) def test_should_return_information_in_ebxml_fault_returned_from_spine_in_original_post_request_to_client_when_wait_for_response_requested(self): """ @@ -167,14 +201,16 @@ def test_should_return_information_in_ebxml_fault_returned_from_spine_in_origina Error found here: fake_spine/fake_spine/configured_responses/ebxml_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='7AA57E38-8B20-4AE0-9E73-B9B0C0C42BDA' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + message_id, + message, + wait_for_response=True + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -188,32 +224,34 @@ def test_should_record_message_status_when_ebxml_error_response_returned_from_sp Error found here: fake_spine/fake_spine/configured_responses/ebxml_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689177923', - message_id='7AA57E38-8B20-4AE0-9E73-B9B0C0C42BDA' - ) + message, message_id = self._build_message( + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + message_id, + message, + wait_for_response=True + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', 'WORKFLOW': 'sync-async' - }) + } + ) def test_should_return_bad_request_when_client_sends_invalid_message(self): # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689174606') + message, message_id = build_message(self.INTERACTION_ID, '9689174606') # Act response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=False) \ + .with_headers(interaction_id=self.INTERACTION_ID, message_id=message_id, wait_for_response=False) \ .with_body({'blah': '123'}) \ .execute_post_expecting_bad_request_response() diff --git a/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_reliable_message_pattern_tests.py b/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_reliable_message_pattern_tests.py index f2df0ca25..024081e94 100644 --- a/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_reliable_message_pattern_tests.py +++ b/integration-tests/integration_tests/integration_tests/component_tests/component_asynchronous_reliable_message_pattern_tests.py @@ -18,10 +18,45 @@ class AsynchronousReliableMessagingPatternTests(unittest.TestCase): They make use of the fake-spine-route-lookup service, which has known responses for certain interaction ids. """ + REPC_INTERACTION_ID = 'REPC_IN150016UK05' + QUPC_INTERACTION_ID = 'QUPC_IN160101UK05' + + SOAP_FAULT_MESSAGE_ID = '3771F30C-A231-4D64-A46C-E7FB0D52C27C' + EBXML_FAULT_MESSAGE_ID = 'A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' + BUSINESS_RETRY_MESSAGE_ID = '35586865-45B0-41A5-98F6-817CA6F1F5EF' + def setUp(self): MHS_STATE_TABLE_WRAPPER.clear_all_records_in_table() MHS_SYNC_ASYNC_TABLE_WRAPPER.clear_all_records_in_table() + def _build_message(self, interaction_id, ods_code, message_id=None): + return build_message(interaction_id, ods_code, message_id=message_id) + + def _post_success(self, interaction_id, message_id, message, wait_for_response): + return MhsHttpRequestBuilder() \ + .with_headers( + interaction_id=interaction_id, + message_id=message_id, + wait_for_response=wait_for_response + ) \ + .with_body(message) \ + .execute_post_expecting_success() + + def _post_error(self, interaction_id, message_id, message, wait_for_response): + return MhsHttpRequestBuilder() \ + .with_headers( + interaction_id=interaction_id, + message_id=message_id, + wait_for_response=wait_for_response + ) \ + .with_body(message) \ + .execute_post_expecting_error_response() + + def _assert_state(self, message_id, expected_values): + MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ + .assert_single_item_exists_with_key(message_id) \ + .assert_item_contains_values(expected_values) + def test_should_return_success_response_to_the_client_when_a_business_level_retry_is_required_and_succeeds(self): """ Message ID: '35586865-45B0-41A5-98F6-817CA6F1F5EF' configured in fakespine to return a SOAP Fault error, @@ -29,14 +64,19 @@ def test_should_return_success_response_to_the_client_when_a_business_level_retr """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='35586865-45B0-41A5-98F6-817CA6F1F5EF' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.BUSINESS_RETRY_MESSAGE_ID + ) + # Act: Response should be 202 - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_success() + self._post_success( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=False + ) def test_should_record_message_status_when_a_business_level_retry_is_required_and_succeeds(self): """ @@ -45,24 +85,29 @@ def test_should_record_message_status_when_a_business_level_retry_is_required_an """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='35586865-45B0-41A5-98F6-817CA6F1F5EF' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.BUSINESS_RETRY_MESSAGE_ID + ) + # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_success() + self._post_success( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=False + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_ACKD', 'WORKFLOW': 'async-reliable' - }) + } + ) def test_should_return_information_from_soap_fault_returned_from_spine_in_original_post_request_to_client(self): """ @@ -70,13 +115,19 @@ def test_should_return_information_from_soap_fault_returned_from_spine_in_origin Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9446245796', message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9446245796', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=False + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -90,24 +141,29 @@ def test_should_record_message_status_as_nackd_when_soap_error_response_returned Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9446245796', - message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9446245796', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=False + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', 'WORKFLOW': 'async-reliable' - }) + } + ) def test_should_return_information_in_ebxml_fault_returned_from_spine_in_original_post_request_to_client(self): """ @@ -115,14 +171,19 @@ def test_should_return_information_in_ebxml_fault_returned_from_spine_in_origina """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) + # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=False + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -136,24 +197,29 @@ def test_should_record_message_status_as_nackd_when_ebxml_error_response_returne """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) + # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=False + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', 'WORKFLOW': 'async-reliable' - }) + } + ) def test_should_return_information_from_ebxml_fault_returned_from_spine_in_original_post_request_to_client_when_wait_for_response_requested(self): """ @@ -161,14 +227,19 @@ def test_should_return_information_from_ebxml_fault_returned_from_spine_in_origi """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) + # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=True + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -182,24 +253,29 @@ def test_should_record_message_status_as_nackd_when_ebxml_error_response_returne """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.EBXML_FAULT_MESSAGE_ID + ) + # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=True + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', 'WORKFLOW': 'sync-async' - }) + } + ) def test_should_return_information_from_soap_fault_from_spine_in_original_post_request_to_client_when_wait_for_response_requested(self): """ @@ -207,14 +283,19 @@ def test_should_return_information_from_soap_fault_from_spine_in_original_post_r """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) + # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=True + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -228,32 +309,41 @@ def test_should_record_message_status_when_soap_error_response_returned_from_spi """ # Arrange - message, message_id = build_message('REPC_IN150016UK05', '9689177923', - message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C' - ) + message, message_id = self._build_message( + self.REPC_INTERACTION_ID, + '9689177923', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) + # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='REPC_IN150016UK05 ', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + self.REPC_INTERACTION_ID, + message_id, + message, + wait_for_response=True + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', 'WORKFLOW': 'sync-async' - }) + } + ) def test_should_return_bad_request_when_client_sends_invalid_message(self): # Arrange - message, message_id = build_message('QUPC_IN160101UK05', '9689174606') + message, message_id = build_message(self.QUPC_INTERACTION_ID, '9689174606') # Act response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPC_IN160101UK05', message_id=message_id, wait_for_response=False) \ + .with_headers( + interaction_id=self.QUPC_INTERACTION_ID, + message_id=message_id, + wait_for_response=False + ) \ .with_body(None) \ .execute_post_expecting_bad_request_response() diff --git a/integration-tests/integration_tests/integration_tests/component_tests/component_forward_reliable_message_pattern_tests.py b/integration-tests/integration_tests/integration_tests/component_tests/component_forward_reliable_message_pattern_tests.py index f6f54704f..33d28932d 100644 --- a/integration-tests/integration_tests/integration_tests/component_tests/component_forward_reliable_message_pattern_tests.py +++ b/integration-tests/integration_tests/integration_tests/component_tests/component_forward_reliable_message_pattern_tests.py @@ -27,20 +27,35 @@ def setUp(self): MHS_SYNC_ASYNC_TABLE_WRAPPER.clear_all_records_in_table() MHS_INBOUND_QUEUE.drain() + def _post_inbound_proxy(self, message, expect_success=True): + builder = InboundProxyHttpRequestBuilder().with_body(message) + return builder.execute_post_expecting_success() if expect_success else builder.execute_post_expecting_error_response() + + def _post_to_mhs(self, interaction_id, message_id, message, wait_for_response=False, expect="success", attachments=None): + builder = MhsHttpRequestBuilder().with_headers( + interaction_id=interaction_id, message_id=message_id, wait_for_response=wait_for_response + ).with_body(message, attachments=attachments) + if expect == "success": + return builder.execute_post_expecting_success() + elif expect == "error": + return builder.execute_post_expecting_error_response() + elif expect == "bad_request": + return builder.execute_post_expecting_bad_request_response() + else: + raise ValueError(f"Unknown expect type: {expect}") + def test_should_place_unsolicited_valid_message_onto_queue_for_client_to_receive(self): # Arrange message, message_id = build_message('INBOUND_UNEXPECTED_MESSAGE', '9689177923', to_party_id="test-party-key") # Act - InboundProxyHttpRequestBuilder() \ - .with_body(message) \ - .execute_post_expecting_success() + self._post_inbound_proxy(message) # Assert AMQMessageAssertor(MHS_INBOUND_QUEUE.get_next_message_on_queue()) \ - .assert_property('message-id', message_id)\ - .assert_durable_is(True)\ - .assertor_for_hl7_xml_message()\ + .assert_property('message-id', message_id) \ + .assert_durable_is(True) \ + .assertor_for_hl7_xml_message() \ .assert_element_attribute(".//ControlActEvent//code", "displayName", "GP2GP Large Message Attachment Information") def test_should_return_nack_when_forward_reliable_message_is_not_meant_for_the_mhs_system(self): @@ -48,14 +63,12 @@ def test_should_return_nack_when_forward_reliable_message_is_not_meant_for_the_m message, message_id = build_message('INBOUND_UNEXPECTED_MESSAGE', '9689177923', to_party_id="NOT_THE_MHS") # Act - response = InboundProxyHttpRequestBuilder()\ - .with_body(message)\ - .execute_post_expecting_success() + response = self._post_inbound_proxy(message) # Assert - EbXmlResponseAssertor(response.text)\ - .assert_element_attribute(".//ErrorList//Error", "errorCode", "ValueNotRecognized")\ - .assert_element_attribute(".//ErrorList//Error", "severity", "Error")\ + EbXmlResponseAssertor(response.text) \ + .assert_element_attribute(".//ErrorList//Error", "errorCode", "ValueNotRecognized") \ + .assert_element_attribute(".//ErrorList//Error", "severity", "Error") \ .assert_element_exists_with_value(".//ErrorList//Error//Description", "501314:Invalid To Party Type attribute") def test_should_return_500_response_when_inbound_service_receives_message_in_invalid_format(self): @@ -63,9 +76,7 @@ def test_should_return_500_response_when_inbound_service_receives_message_in_inv message, message_id = build_message('INBOUND_UNEXPECTED_INVALID_MESSAGE', '9689177923') # Act - response = InboundProxyHttpRequestBuilder() \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_inbound_proxy(message, expect_success=False) # Assert self.assertIn('Exception during inbound message parsing', response.text) @@ -75,42 +86,31 @@ def test_should_return_successful_response_to_client_when_a_business_level_retry Message ID: '35586865-45B0-41A5-98F6-817CA6F1F5EF' configured in fakespine to return a SOAP Fault error, after 2 retries fakespine will return a success response. """ - # Arrange message, message_id = build_message('COPC_IN000001UK01', '9689177923', - message_id='35586865-45B0-41A5-98F6-817CA6F1F5EF' - ) + message_id='35586865-45B0-41A5-98F6-817CA6F1F5EF') # Act/Assert: Response should be 202 - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='COPC_IN000001UK01 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_success() + self._post_to_mhs('COPC_IN000001UK01', message_id, message, wait_for_response=False, expect="success") def test_should_record_message_status_when_a_business_level_retry_is_required_and_succeeds(self): """ Message ID: '35586865-45B0-41A5-98F6-817CA6F1F5EF' configured in fakespine to return a SOAP Fault error, after 2 retries fakespine will return a success response. """ - # Arrange message, message_id = build_message('COPC_IN000001UK01', '9689177923', - message_id='35586865-45B0-41A5-98F6-817CA6F1F5EF' - ) + message_id='35586865-45B0-41A5-98F6-817CA6F1F5EF') # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='COPC_IN000001UK01 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_success() + self._post_to_mhs('COPC_IN000001UK01', message_id, message, wait_for_response=False, expect="success") # Assert MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( - { - 'INBOUND_STATUS': None, - 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_ACKD', - 'WORKFLOW': 'forward-reliable' - }) + .assert_item_contains_values({ + 'INBOUND_STATUS': None, + 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_ACKD', + 'WORKFLOW': 'forward-reliable' + }) def test_should_return_information_from_soap_fault_returned_by_spine_in_original_post_request_to_client(self): """ @@ -121,17 +121,14 @@ def test_should_return_information_from_soap_fault_returned_by_spine_in_original message, message_id = build_message('COPC_IN000001UK01', '9446245796', message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='COPC_IN000001UK01', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_to_mhs('COPC_IN000001UK01', message_id, message, wait_for_response=False, expect="error") # Assert JsonErrorResponseAssertor(response.text) \ .assert_error_code(200) \ .assert_code_context('urn:nhs:names:error:tms') \ .assert_severity('Error') - + def test_should_record_message_status_when_soap_fault_returned_from_spine(self): """ Message ID: 3771F30C-A231-4D64-A46C-E7FB0D52C27C configured in fakespine to return a SOAP Fault error. @@ -142,35 +139,27 @@ def test_should_record_message_status_when_soap_fault_returned_from_spine(self): message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='COPC_IN000001UK01', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_to_mhs('COPC_IN000001UK01', message_id, message, wait_for_response=False, expect="error") # Assert MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( - { - 'INBOUND_STATUS': None, - 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', - 'WORKFLOW': 'forward-reliable' - }) + .assert_item_contains_values({ + 'INBOUND_STATUS': None, + 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', + 'WORKFLOW': 'forward-reliable' + }) def test_should_return_information_from_ebxml_fault_returned_by_spine_in_original_post_request_to_client(self): """ Message ID: 'A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' configured in fakespine to return a ebxml fault """ - # Arrange message, message_id = build_message('COPC_IN000001UK01', '9689177923', - message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' - ) + message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D') + # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='COPC_IN000001UK01 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_to_mhs('COPC_IN000001UK01', message_id, message, wait_for_response=False, expect="error") # Assert JsonErrorResponseAssertor(response.text) \ @@ -182,26 +171,21 @@ def test_should_record_message_status_when_ebxml_fault_returned_from_spine(self) """ Message ID: 'A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' configured in fakespine to return a ebxml fault """ - # Arrange message, message_id = build_message('COPC_IN000001UK01', '9689177923', - message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' - ) + message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D') + # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='COPC_IN000001UK01 ', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_to_mhs('COPC_IN000001UK01', message_id, message, wait_for_response=False, expect="error") # Assert MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( - { - 'INBOUND_STATUS': None, - 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', - 'WORKFLOW': 'forward-reliable' - }) + .assert_item_contains_values({ + 'INBOUND_STATUS': None, + 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_NACKD', + 'WORKFLOW': 'forward-reliable' + }) def test_should_return_information_from_soap_fault_returned_from_spine_in_original_post_request_when_wait_for_response_requested(self): """ @@ -212,13 +196,11 @@ def test_should_return_information_from_soap_fault_returned_from_spine_in_origin can be wrapped in wait_for_response """ # Arrange - message, message_id = build_message('PRSC_IN080000UK07', '9446245796', message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') + message, message_id = build_message('PRSC_IN080000UK07', '9446245796', + message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='PRSC_IN080000UK07', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_to_mhs('PRSC_IN080000UK07', message_id, message, wait_for_response=True, expect="error") # Assert JsonErrorResponseAssertor(response.text) \ @@ -239,20 +221,16 @@ def test_should_update_status_when_a_soap_fault_is_returned_from_spine_and_wait_ message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='PRSC_IN080000UK07', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_to_mhs('PRSC_IN080000UK07', message_id, message, wait_for_response=True, expect="error") # Assert MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( - { - 'INBOUND_STATUS': None, - 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', - 'WORKFLOW': 'sync-async' - }) + .assert_item_contains_values({ + 'INBOUND_STATUS': None, + 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', + 'WORKFLOW': 'sync-async' + }) def test_should_return_information_from_an_ebxml_fault_returned_from_spine_in_original_post_request_when_wait_for_response_requested(self): """ @@ -261,16 +239,12 @@ def test_should_return_information_from_an_ebxml_fault_returned_from_spine_in_or Here we use 'PRSC_IN080000UK07' which is an eRS slot polling call, it is a forward reliable message type that can be wrapped in wait_for_response """ - # Arrange message, message_id = build_message('PRSC_IN080000UK07', '9689177923', - message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D' - ) + message_id='A7D43B03-38FB-4ED7-8D04-0496DBDEDB7D') + # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='PRSC_IN080000UK07 ', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_to_mhs('PRSC_IN080000UK07', message_id, message, wait_for_response=True, expect="error") # Assert JsonErrorResponseAssertor(response.text) \ @@ -291,20 +265,16 @@ def test_should_update_status_when_a_ebxml_fault_is_returned_from_spine_and_wait message_id='3771F30C-A231-4D64-A46C-E7FB0D52C27C') # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='PRSC_IN080000UK07', message_id=message_id, wait_for_response=True) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_to_mhs('PRSC_IN080000UK07', message_id, message, wait_for_response=True, expect="error") # Assert MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( - { - 'INBOUND_STATUS': None, - 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', - 'WORKFLOW': 'sync-async' - }) + .assert_item_contains_values({ + 'INBOUND_STATUS': None, + 'OUTBOUND_STATUS': 'OUTBOUND_SYNC_ASYNC_MESSAGE_SUCCESSFULLY_RESPONDED', + 'WORKFLOW': 'sync-async' + }) def test_should_return_bad_request_when_client_sends_invalid_message(self): # Arrange @@ -319,10 +289,8 @@ def test_should_return_bad_request_when_client_sends_invalid_message(self): }] # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='COPC_IN000001UK01', message_id=message_id, wait_for_response=False) \ - .with_body(message, attachments=attachments) \ - .execute_post_expecting_bad_request_response() + response = self._post_to_mhs('COPC_IN000001UK01', message_id, message, wait_for_response=False, + expect="bad_request", attachments=attachments) # Assert self.assertEqual(response.text, "400: Invalid request. Validation errors: {'attachments': {0: " diff --git a/integration-tests/integration_tests/integration_tests/component_tests/component_synchronous_messaging_pattern_tests.py b/integration-tests/integration_tests/integration_tests/component_tests/component_synchronous_messaging_pattern_tests.py index b503ca886..aacc86966 100644 --- a/integration-tests/integration_tests/integration_tests/component_tests/component_synchronous_messaging_pattern_tests.py +++ b/integration-tests/integration_tests/integration_tests/component_tests/component_synchronous_messaging_pattern_tests.py @@ -19,23 +19,60 @@ class SynchronousMessagingPatternTests(unittest.TestCase): They make use of the fake-spine-route-lookup service, which has known responses for certain interaction ids. """ + INTERACTION_ID = 'QUPA_IN040000UK32' + SOAP_FAULT_MESSAGE_ID = 'F5187FB6-B033-4A75-838B-9E7A1AFB3111' + def setUp(self): MHS_STATE_TABLE_WRAPPER.clear_all_records_in_table() MHS_SYNC_ASYNC_TABLE_WRAPPER.clear_all_records_in_table() + def _build_message(self, ods_code, message_id=None): + return build_message(self.INTERACTION_ID, ods_code, message_id=message_id) + + def _post_error(self, message_id, message, wait_for_response=False, from_asid='200000000115'): + return MhsHttpRequestBuilder() \ + .with_headers( + interaction_id=self.INTERACTION_ID, + message_id=message_id, + wait_for_response=wait_for_response, + from_asid=from_asid + ) \ + .with_body(message) \ + .execute_post_expecting_error_response() + + def _post_bad_request(self, message_id, message, wait_for_response=False, from_asid=None): + return MhsHttpRequestBuilder() \ + .with_headers( + interaction_id=self.INTERACTION_ID, + message_id=message_id, + wait_for_response=wait_for_response, + from_asid=from_asid + ) \ + .with_body(message) \ + .execute_post_expecting_bad_request_response() + + def _assert_state(self, message_id, expected_values): + MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ + .assert_single_item_exists_with_key(message_id) \ + .assert_item_contains_values(expected_values) + def test_should_return_error_response_to_client_when_error_response_returned_from_spine(self): """ Message ID: F5187FB6-B033-4A75-838B-9E7A1AFB3111 configured in fakespine to return a SOAP Fault error. Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPA_IN040000UK32', '9689174606', message_id='F5187FB6-B033-4A75-838B-9E7A1AFB3111') + message, message_id = self._build_message( + '9689174606', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPA_IN040000UK32', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + response = self._post_error( + message_id, + message, + wait_for_response=False + ) # Assert JsonErrorResponseAssertor(response.text) \ @@ -50,52 +87,60 @@ def test_should_record_message_status_as_successful_when_error_response_returned Error found here: fake_spine/fake_spine/configured_responses/soap_fault_single_error.xml """ # Arrange - message, message_id = build_message('QUPA_IN040000UK32', '9689174606', - message_id='F5187FB6-B033-4A75-838B-9E7A1AFB3111') + message, message_id = self._build_message( + '9689174606', + message_id=self.SOAP_FAULT_MESSAGE_ID + ) # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPA_IN040000UK32', message_id=message_id, wait_for_response=False) \ - .with_body(message) \ - .execute_post_expecting_error_response() + self._post_error( + message_id, + message, + wait_for_response=False + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values( + self._assert_state( + message_id, { 'INBOUND_STATUS': None, 'OUTBOUND_STATUS': 'SYNC_RESPONSE_SUCCESSFUL', 'WORKFLOW': 'sync' - }) + } + ) def test_should_return_bad_request_when_client_sends_invalid_message(self): # Arrange - message, message_id = build_message('QUPA_IN040000UK32', '9689174606') + message, message_id = self._build_message('9689174606') # Act - response = MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPA_IN040000UK32', message_id=message_id, wait_for_response=False, from_asid=None) \ - .with_body(message) \ - .execute_post_expecting_bad_request_response() + response = self._post_bad_request( + message_id, + message, + wait_for_response=False, + from_asid=None + ) # Assert self.assertEqual(response.text, "`from_asid` header field required for sync messages") def test_should_record_message_received_when_bad_request_returned_to_client(self): # Arrange - message, message_id = build_message('QUPA_IN040000UK32', '9689174606') + message, message_id = self._build_message('9689174606') # Act - MhsHttpRequestBuilder() \ - .with_headers(interaction_id='QUPA_IN040000UK32', message_id=message_id, wait_for_response=False, from_asid=None) \ - .with_body(message) \ - .execute_post_expecting_bad_request_response() + self._post_bad_request( + message_id, + message, + wait_for_response=False, + from_asid=None + ) # Assert - MhsTableStateAssertor(MHS_STATE_TABLE_WRAPPER.get_all_records_in_table()) \ - .assert_single_item_exists_with_key(message_id) \ - .assert_item_contains_values({ - 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_RECEIVED', - 'WORKFLOW': 'sync' - }) + self._assert_state( + message_id, + { + 'OUTBOUND_STATUS': 'OUTBOUND_MESSAGE_RECEIVED', + 'WORKFLOW': 'sync' + } + )