def upload(self, message: MeshMessage, upload_event_metadata: UploadEventMetadata): try: message_content = message.read().decode("utf-8") if message_content == "": upload_event_metadata.record_sns_empty_message_error(message) return mesh_message_id_key = "meshMessageId" sns_attributes = { mesh_message_id_key: { "DataType": "String", "StringValue": message.id, } } response = self._sns_client.publish( TopicArn=self.topic_arn, Message=message_content, MessageAttributes=sns_attributes) upload_event_metadata.record_sns_message_id(response["MessageId"]) except ClientError as error: if error.response["Error"]["Code"] == "InvalidParameter": upload_event_metadata.record_invalid_parameter_error( error.response["Error"]["Message"]) raise UploaderError(str(error))
def test_calls_read_on_underlying_client_message(): expected_value = "data" client_message = mock_client_message() client_message.read.return_value = expected_value message = MeshMessage(client_message) actual_value = message.read(n=43) client_message.read.assert_called_once_with(43) assert actual_value == expected_value