def test_deserialize_sqs_message_with_mega_payload_encoded_as_binary_bson(): mega_payload = build_mega_payload_data() blob = bson.dumps(mega_payload) sqs_data = build_sqs_message_data(Body=b64encode(blob).decode()) sqs_message = deserialize_sqs_message(sqs_data) assert_sqs_message_matches_data_attributes(sqs_message, sqs_data) assert sqs_message.payload_type == PayloadType.MEGA assert sqs_message.payload == deserialize_payload(mega_payload) assert sqs_message.embedded_message is None
def test_deserialize_sqs_message_with_mega_payload_encoded_as_plaintext_json(): mega_payload = build_mega_payload_data() plaintext = json.dumps(mega_payload) sqs_data = build_sqs_message_data(Body=plaintext) sqs_message = deserialize_sqs_message(sqs_data) assert_sqs_message_matches_data_attributes(sqs_message, sqs_data) assert sqs_message.payload_type == PayloadType.MEGA assert sqs_message.payload == deserialize_payload(mega_payload) assert sqs_message.embedded_message is None
def test_deserialize_sqs_message_with_embedded_sns_message_having_mega_payload_encoded_as_plaintext_json( ): mega_payload_data = build_mega_payload_data() sns_data = build_sns_notification_data( Message=json.dumps(mega_payload_data)) sns_json = json.dumps(sns_data) sqs_data = build_sqs_message_data(Body=sns_json) sqs_message = deserialize_sqs_message(sqs_data) assert_sqs_message_matches_data_attributes(sqs_message, sqs_data) expected_mega_payload = deserialize_payload(mega_payload_data) assert sqs_message.payload_type == PayloadType.MEGA assert sqs_message.payload == expected_mega_payload assert_sqs_message_has_embedded_sns_notification(sqs_message) assert sqs_message.embedded_message.payload_type == PayloadType.MEGA assert sqs_message.embedded_message.payload == expected_mega_payload
def test_receive_message_with_plaintext_mega_payload(queue_url): sqs = SqsReceiver(queue_url=queue_url, max_number_of_messages=1) with vcr.use_cassette( 'receive_message_with_plaintext_mega_payload') as cassette: messages = sqs.receive_messages() assert cassette.all_played response = get_sqs_receive_message_response_data(cassette) assert len(messages) == 1 message = messages[0] assert_is_sqs_message(message) assert_message_attributes_match_response(message, response) assert message.payload_type == PayloadType.MEGA assert message.payload == deserialize_payload( json.loads(response['Message']['Body'])) assert message.embedded_message is None assert_request_match_sqs_receiver_attributes(cassette, sqs)
def test_receive_message_with_base64_encoded_binary_mega_payload_over_sns( queue_url): sqs = SqsReceiver(queue_url=queue_url, max_number_of_messages=1) with vcr.use_cassette( 'receive_message_with_base64_encoded_binary_mega_payload_over_sns' ) as cassette: messages = sqs.receive_messages() assert cassette.all_played response = get_sqs_receive_message_response_data(cassette) assert len(messages) == 1 message = messages[0] assert_is_sqs_message(message) assert_message_attributes_match_response(message, response) assert message.payload_type == PayloadType.MEGA assert message.payload == deserialize_payload( bson.loads( b64decode(json.loads(response['Message']['Body'])['Message']))) assert_is_sns_notification(message.embedded_message) assert_request_match_sqs_receiver_attributes(cassette, sqs)