示例#1
0
def test_publish_blob_payload(sqs):
    blob = (
        b'\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{'
        b'wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3\x01\x02\x03\x00xQ\xc4\xf2QF\xbfw~W\x1b\xf1\xf1Nq\xff\xc0\x94'
        b'\x84ov\x9a0\x1dC\xcf\xd2\x06r4\n\xe7m\x01\nQ{wb6X\x9cz\xab\xb5\x04\x97\x8e\xdf^cr\x81\xb1\x83s\xf2\xb0\xa1['
        b'2\xd0\x9f|V\xb0\xc3\xb0\xc3\xb0\xc3\xb0\xc3 ')

    with vcr.use_cassette('publish_blob_payload') as cassette:
        message_id = sqs.publish(blob)

    assert cassette.all_played

    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == sqs.queue_url
    assert b64decode(get_message_body_from_request(request_data)) == blob
    assert get_message_id_from_response(cassette) == message_id
示例#2
0
def test_delete_message_that_has_already_been_deleted(queue_url):
    sqs = SqsReceiver(queue_url=queue_url)

    message_id = '96427844-a8c4-41e5-beed-dab5780cc681'
    receipt_handle = (
        'AQEBY/+I4IQJzCkjsop/FaaKLb5VKXL9JHF4BWbJwOD0osZbenehbjp4xQ59r1DD0pEonhUCaILKkQfq7FrPhUomHBzOzK+e4qCGI62QgkLt6V'
        '8vYJtHlhSNrroy+c9LyuZFKtVNJQ/8rjFwEDQ/jnFdA6MLGnG2Aaj+8LTdvXb4aG+r1PwkS4AEEa4IvMty5NJOwmd70QynfopkRO18EGe6pKkE'
        '6d0j1XvZNkd7peisPLxwU9cljjyu+Hdds12atn71Ss7nn/jr2ElhsnzJrB3eQ4XCtjYP/9sfXT8+0BT5SPb2zCIe1bDzXCLxZypikkdEkQq33z'
        '/TtjWk0/b8yyReM4o52m83tYP6fB0XNlQnWebpO/9leappxF5mFXl7kO2N4ga0dBJ0ts+I/j4rn6GP5w=='
    )

    message = SqsMessage(message_id=message_id,
                         receipt_handle=receipt_handle,
                         payload='hello world!',
                         payload_type=PayloadType.PLAINTEXT)

    with vcr.use_cassette(
            'delete_message_that_has_already_been_deleted') as cassette:
        sqs.delete_message(message)
        sqs.delete_message(message)

    assert cassette.all_played
    request = get_sqs_request_data(cassette)
    assert get_request_attribute(request, 'ReceiptHandle') == receipt_handle
    assert get_queue_url_from_request(request) == sqs.queue_url
示例#3
0
def assert_request_match_sqs_receiver_attributes(cassette, sqs_receiver):
    request = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request) == sqs_receiver.queue_url
    assert int(get_request_attribute(
        request, 'MaxNumberOfMessages')) == sqs_receiver.max_number_of_messages
    assert int(get_request_attribute(
        request, 'WaitTimeSeconds')) == sqs_receiver.wait_time_seconds
    assert int(get_request_attribute(
        request, 'VisibilityTimeout')) == sqs_receiver.visibility_timeout
示例#4
0
def test_publish_overriding_default_topic_arn(sqs):
    another_queue_url = 'https://sqs.us-east-2.amazonaws.com/424566909325/another-queue'
    data = build_generic_data()

    with vcr.use_cassette('publish_overriding_default_queue_url') as cassette:
        message_id = sqs.publish(data, queue_url=another_queue_url)

    assert cassette.all_played
    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == another_queue_url
    assert get_message_id_from_response(cassette) == message_id
示例#5
0
def test_publish_plaintext_payload(sqs):
    plaintext = 'hello world!'
    with vcr.use_cassette('publish_plaintext_payload') as cassette:
        message_id = sqs.publish(plaintext)

    assert cassette.all_played

    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == sqs.queue_url
    assert get_message_body_from_request(request_data) == plaintext
    assert get_message_id_from_response(cassette) == message_id
示例#6
0
def test_publish_raw_json_message(sqs):
    data = build_generic_data()
    plaintext_json = json.dumps(data, sort_keys=True)

    with vcr.use_cassette('publish_raw_json_message') as cassette:
        message_id = sqs.publish_raw_message(plaintext_json)

    assert cassette.all_played

    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == sqs.queue_url
    assert get_message_body_from_request(request_data) == plaintext_json
    assert get_message_id_from_response(cassette) == message_id
示例#7
0
def test_publish_data_payload_as_plaintext_json(sqs):
    data = build_generic_data()

    with vcr.use_cassette(
            'publish_data_payload_as_plaintext_json') as cassette:
        message_id = sqs.publish(data)

    assert cassette.all_played

    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == sqs.queue_url
    assert json.loads(get_message_body_from_request(request_data)) == data
    assert get_message_id_from_response(cassette) == message_id
示例#8
0
def test_publish_mega_payload_as_binary_bson(sqs):
    mega_payload = build_mega_payload()

    with vcr.use_cassette('publish_mega_payload_as_binary_bson') as cassette:
        message_id = sqs.publish(mega_payload, binary_encoding=True)

    assert cassette.all_played

    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == sqs.queue_url

    message_body = get_message_body_from_request(request_data)
    blob = b64decode(message_body)
    assert mega.event.deserialize_payload(bson.loads(blob)) == mega_payload
    assert get_message_id_from_response(cassette) == message_id
示例#9
0
def test_publish_data_payload_as_binary_bson(sqs):
    data = build_generic_data()

    with vcr.use_cassette('publish_data_payload_as_binary_bson') as cassette:
        message_id = sqs.publish(data, binary_encoding=True)

    assert cassette.all_played

    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == sqs.queue_url

    message_body = get_message_body_from_request(request_data)
    blob = b64decode(message_body)
    assert bson.loads(blob) == data
    assert get_message_id_from_response(cassette) == message_id
示例#10
0
def test_publish_mega_payload_as_plaintext_json(sqs):
    mega_payload = build_mega_payload()

    with vcr.use_cassette(
            'publish_mega_payload_as_plaintext_json') as cassette:
        message_id = sqs.publish(mega_payload)

    assert cassette.all_played

    request_data = get_sqs_request_data(cassette)
    assert get_queue_url_from_request(request_data) == sqs.queue_url

    message_body = get_message_body_from_request(request_data)
    assert mega.event.deserialize_payload(
        json.loads(message_body)) == mega_payload
    assert get_message_id_from_response(cassette) == message_id