def test_serialize_required_tags(self):
        for required_tag in get_test_message_dictionary().keys():
            with self.subTest(required_tag=required_tag):
                if required_tag != soap_envelope.MESSAGE_ID:
                    test_message_dict = get_test_message_dictionary()
                    del test_message_dict[required_tag]
                    envelope = soap_envelope.SoapEnvelope(test_message_dict)

                    with self.assertRaisesRegex(pystache_message_builder.MessageGenerationError, 'Failed to find key'):
                        envelope.serialize()
    def test_serialize(self, mock_get_uuid, mock_get_timestamp):
        mock_get_uuid.return_value = MOCK_UUID
        mock_get_timestamp.return_value = MOCK_TIMESTAMP

        envelope = soap_envelope.SoapEnvelope(get_test_message_dictionary())

        message_id, http_headers, message = envelope.serialize()

        normalized_message = file_utilities.FileUtilities.normalize_line_endings(message)

        self.assertEqual(MOCK_UUID, message_id)
        self.assertEqual(EXPECTED_HTTP_HEADERS, http_headers)
        self.assertEqual(self.normalized_expected_serialized_message, normalized_message)
    def test_serialize_message_id_not_generated(self, mock_get_uuid, mock_get_timestamp):
        mock_get_timestamp.return_value = MOCK_TIMESTAMP

        message_dictionary = get_test_message_dictionary()
        message_dictionary[soap_envelope.MESSAGE_ID] = MOCK_UUID
        envelope = soap_envelope.SoapEnvelope(message_dictionary)

        message_id, http_headers, message = envelope.serialize()

        normalized_message = file_utilities.FileUtilities.normalize_line_endings(message)

        mock_get_uuid.assert_not_called()
        self.assertEqual(MOCK_UUID, message_id)
        self.assertEqual(EXPECTED_HTTP_HEADERS, http_headers)
        self.assertEqual(self.normalized_expected_serialized_message, normalized_message)
Exemple #4
0
    async def _prepare_outbound_message(self, message_id: Optional[str],
                                        to_asid: str, from_asid: str,
                                        message: str,
                                        interaction_details: dict):
        action = f'{interaction_details[soap_envelope.SERVICE]}/{interaction_details[soap_envelope.ACTION]}'
        message_details = {
            soap_envelope.MESSAGE_ID: message_id,
            soap_envelope.TO_ASID: to_asid,
            soap_envelope.FROM_ASID: from_asid,
            soap_envelope.SERVICE: interaction_details[soap_envelope.SERVICE],
            soap_envelope.ACTION: action,
            soap_envelope.MESSAGE: message
        }

        envelope = soap_envelope.SoapEnvelope(message_details)
        return envelope.serialize()