How to use the moto.mock_sns function in moto

To help you get started, we’ve selected a few moto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spulec / moto / tests / test_sns / test_subscriptions_boto3.py View on Github external
@mock_sns
def test_subscription_paging():
    conn = boto3.client("sns", region_name="us-east-1")
    conn.create_topic(Name="topic1")

    response = conn.list_topics()
    topics = response["Topics"]
    topic1_arn = topics[0]["TopicArn"]

    for index in range(DEFAULT_PAGE_SIZE + int(DEFAULT_PAGE_SIZE / 3)):
        conn.subscribe(
            TopicArn=topic1_arn,
            Protocol="email",
            Endpoint="email_" + str(index) + "@test.com",
        )

    all_subscriptions = conn.list_subscriptions()
github spulec / moto / tests / test_sns / test_publishing_boto3.py View on Github external
@mock_sns
def test_publish_message_too_long():
    sns = boto3.resource("sns", region_name="us-east-1")
    topic = sns.create_topic(Name="some-topic")

    with assert_raises(ClientError):
        topic.publish(Message="".join(["." for i in range(0, 262145)]))

    # message short enough - does not raise an error
    topic.publish(Message="".join(["." for i in range(0, 262144)]))
github rackerlabs / ebs_snapper / tests / test_snapshot.py View on Github external
@mock_ec2
@mock_dynamodb2
@mock_sns
@mock_iam
@mock_sts
@mock_events
@mock_cloudformation
def test_perform_fanout_all_regions_snapshot(mocker):
    """Test for method of the same name."""

    # make a dummy SNS topic
    mocks.create_event_rule('ScheduledRuleReplicationFunction')
    mocks.create_sns_topic('CreateSnapshotTopic')
    expected_sns_topic = utils.get_topic_arn('CreateSnapshotTopic', 'us-east-1')

    dummy_regions = ['us-west-2', 'us-east-1']

    # make some dummy instances in two regions
    instance_maps = {}
github spulec / moto / tests / test_sns / test_sms_boto3.py View on Github external
@mock_sns
def test_list_opted_out():
    conn = boto3.client('sns', region_name='us-east-1')
    response = conn.list_phone_numbers_opted_out()

    response.should.contain('phoneNumbers')
    len(response['phoneNumbers']).should.be.greater_than(0)
github spulec / moto / tests / test_sns / test_sms_boto3.py View on Github external
@mock_sns
def test_get_sms_attributes_filtered():
    conn = boto3.client('sns', region_name='us-east-1')

    conn.set_sms_attributes(attributes={'DefaultSMSType': 'Transactional', 'test': 'test'})

    response = conn.get_sms_attributes(attributes=['DefaultSMSType'])
    response.should.contain('attributes')
    response['attributes'].should.contain('DefaultSMSType')
    response['attributes'].should_not.contain('test')
    response['attributes']['DefaultSMSType'].should.equal('Transactional')
github spulec / moto / tests / test_sns / test_sms_boto3.py View on Github external
@mock_sns
def test_confirm_subscription():
    conn = boto3.client('sns', region_name='us-east-1')
    response = conn.create_topic(Name='testconfirm')

    conn.confirm_subscription(
        TopicArn=response['TopicArn'],
        Token='2336412f37fb687f5d51e6e241d59b68c4e583a5cee0be6f95bbf97ab8d2441cf47b99e848408adaadf4c197e65f03473d53c4ba398f6abbf38ce2e8ebf7b4ceceb2cd817959bcde1357e58a2861b05288c535822eb88cac3db04f592285249971efc6484194fc4a4586147f16916692',
        AuthenticateOnUnsubscribe='true'
    )
github spulec / moto / tests / test_sns / test_publishing_boto3.py View on Github external
@mock_sns
def test_publish_to_sqs_raw():
    sns = boto3.resource("sns", region_name="us-east-1")
    topic = sns.create_topic(Name="some-topic")

    sqs = boto3.resource("sqs", region_name="us-east-1")
    queue = sqs.create_queue(QueueName="test-queue")

    subscription = topic.subscribe(
        Protocol="sqs", Endpoint=queue.attributes["QueueArn"]
    )

    subscription.set_attributes(
        AttributeName="RawMessageDelivery", AttributeValue="true"
    )

    message = "my message"
github spulec / moto / tests / test_sns / test_topics_boto3.py View on Github external
@mock_sns
def test_create_topic_must_meet_constraints():
    conn = boto3.client("sns", region_name="us-east-1")
    common_random_chars = [":", ";", "!", "@", "|", "^", "%"]
    for char in common_random_chars:
        conn.create_topic.when.called_with(Name="no%s_invalidchar" % char).should.throw(
            ClientError
        )
    conn.create_topic.when.called_with(Name="no spaces allowed").should.throw(
        ClientError
    )
github spulec / moto / tests / test_sns / test_topics_boto3.py View on Github external
@mock_sns
def test_topic_attributes():
    conn = boto3.client("sns", region_name="us-east-1")
    conn.create_topic(Name="some-topic")

    topics_json = conn.list_topics()
    topic_arn = topics_json["Topics"][0]["TopicArn"]

    attributes = conn.get_topic_attributes(TopicArn=topic_arn)["Attributes"]
    attributes["TopicArn"].should.equal(
        "arn:aws:sns:{0}:123456789012:some-topic".format(
            conn._client_config.region_name
        )
    )
    attributes["Owner"].should.equal("123456789012")
    json.loads(attributes["Policy"]).should.equal(DEFAULT_TOPIC_POLICY)
    attributes["DisplayName"].should.equal("")
github spulec / moto / tests / test_awslambda / test_lambda.py View on Github external
@mock_sns
@mock_ec2
@mock_lambda
def test_invoke_function_from_sns():
    logs_conn = boto3.client("logs", region_name="us-west-2")
    sns_conn = boto3.client("sns", region_name="us-west-2")
    sns_conn.create_topic(Name="some-topic")
    topics_json = sns_conn.list_topics()
    topics = topics_json["Topics"]
    topic_arn = topics[0]["TopicArn"]

    conn = boto3.client("lambda", "us-west-2")
    result = conn.create_function(
        FunctionName="testFunction",
        Runtime="python2.7",
        Role="test-iam-role",
        Handler="lambda_function.lambda_handler",