moto/tests/test_sns/test_publishing.py

54 lines
1.6 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2014-08-26 17:25:50 +00:00
from six.moves.urllib.parse import parse_qs
2014-05-12 02:56:44 +00:00
import boto
from freezegun import freeze_time
import sure # noqa
2017-02-16 03:35:45 +00:00
from moto.packages.responses import responses
2017-02-28 01:53:57 +00:00
from moto import mock_sns_deprecated, mock_sqs_deprecated
2014-05-12 02:56:44 +00:00
2017-02-16 03:35:45 +00:00
@mock_sqs_deprecated
@mock_sns_deprecated
2014-05-12 02:56:44 +00:00
def test_publish_to_sqs():
conn = boto.connect_sns()
conn.create_topic("some-topic")
topics_json = conn.get_all_topics()
2017-02-24 02:37:43 +00:00
topic_arn = topics_json["ListTopicsResponse"][
"ListTopicsResult"]["Topics"][0]['TopicArn']
2014-05-12 02:56:44 +00:00
sqs_conn = boto.connect_sqs()
sqs_conn.create_queue("test-queue")
2017-02-24 02:37:43 +00:00
conn.subscribe(topic_arn, "sqs",
"arn:aws:sqs:us-east-1:123456789012:test-queue")
2014-05-12 02:56:44 +00:00
conn.publish(topic=topic_arn, message="my message")
queue = sqs_conn.get_queue("test-queue")
message = queue.read(1)
message.get_body().should.equal('my message')
2017-02-16 03:35:45 +00:00
@mock_sqs_deprecated
@mock_sns_deprecated
def test_publish_to_sqs_in_different_region():
conn = boto.sns.connect_to_region("us-west-1")
conn.create_topic("some-topic")
topics_json = conn.get_all_topics()
2017-02-24 02:37:43 +00:00
topic_arn = topics_json["ListTopicsResponse"][
"ListTopicsResult"]["Topics"][0]['TopicArn']
sqs_conn = boto.sqs.connect_to_region("us-west-2")
sqs_conn.create_queue("test-queue")
2017-02-24 02:37:43 +00:00
conn.subscribe(topic_arn, "sqs",
"arn:aws:sqs:us-west-2:123456789012:test-queue")
conn.publish(topic=topic_arn, message="my message")
queue = sqs_conn.get_queue("test-queue")
message = queue.read(1)
message.get_body().should.equal('my message')