Example #1
0
    def test_publish_sms_endpoint(self):
        list_of_contacts = [
            "+%d" % random.randint(100000000, 9999999999),
            "+%d" % random.randint(100000000, 9999999999),
            "+%d" % random.randint(100000000, 9999999999),
        ]
        message = "Good news everyone!"

        for number in list_of_contacts:
            self.sns_client.subscribe(TopicArn=self.topic_arn, Protocol="sms", Endpoint=number)

        self.sns_client.publish(Message=message, TopicArn=self.topic_arn)

        sns_backend = SNSBackend.get()

        def check_messages():
            sms_messages = sns_backend.sms_messages
            for contact in list_of_contacts:
                sms_was_found = False
                for message in sms_messages:
                    if message["endpoint"] == contact:
                        sms_was_found = True
                        break

                self.assertTrue(sms_was_found)

        retry(check_messages, sleep=0.5)
Example #2
0
    def test_subscribe_platform_endpoint(self):
        sns = self.sns_client
        sns_backend = SNSBackend.get()
        app_arn = sns.create_platform_application(Name='app1', Platform='p1', Attributes={})['PlatformApplicationArn']
        platform_arn = sns.create_platform_endpoint(PlatformApplicationArn=app_arn, Token='token_1')['EndpointArn']
        subscription = self._publish_sns_message_with_attrs(platform_arn, 'application')

        # assert that message has been received
        def check_message():
            self.assertGreater(len(sns_backend.platform_endpoint_messages[platform_arn]), 0)
        retry(check_message, retries=PUBLICATION_RETRIES, sleep=PUBLICATION_TIMEOUT)

        # clean up
        sns.unsubscribe(SubscriptionArn=subscription['SubscriptionArn'])
        sns.delete_endpoint(EndpointArn=platform_arn)
        sns.delete_platform_application(PlatformApplicationArn=app_arn)
Example #3
0
    def test_topic_subscription(self):
        subscription = self.sns_client.subscribe(
            TopicArn=self.topic_arn, Protocol="email", Endpoint="*****@*****.**"
        )
        sns_backend = SNSBackend.get()

        def check_subscription():
            subscription_arn = subscription["SubscriptionArn"]
            subscription_obj = sns_backend.subscription_status[subscription_arn]
            self.assertEqual(subscription_obj["Status"], "Not Subscribed")

            _token = subscription_obj["Token"]
            self.sns_client.confirm_subscription(TopicArn=self.topic_arn, Token=_token)
            self.assertEqual(subscription_obj["Status"], "Subscribed")

        retry(check_subscription, retries=PUBLICATION_RETRIES, sleep=PUBLICATION_TIMEOUT)
Example #4
0
    def test_topic_subscription(self):
        subscription = self.sns_client.subscribe(
            TopicArn=self.topic_arn,
            Protocol='email',
            Endpoint='*****@*****.**'
        )
        sns_backend = SNSBackend.get()

        def check_subscription():
            subscription_arn = subscription['SubscriptionArn']
            subscription_obj = sns_backend.subscription_status[subscription_arn]
            self.assertEqual(subscription_obj['Status'], 'Not Subscribed')

            _token = subscription_obj['Token']
            self.sns_client.confirm_subscription(
                TopicArn=self.topic_arn,
                Token=_token
            )
            self.assertEqual(subscription_obj['Status'], 'Subscribed')
        retry(check_subscription, retries=PUBLICATION_RETRIES, sleep=PUBLICATION_TIMEOUT)
Example #5
0
 def check_messages():
     sns_backend = SNSBackend.get()
     self.assertEqual(len(list_of_contacts),
                      len(sns_backend.sms_messages))