From 83c8740b910e178d93fc26b02d3557d4ad36bbd3 Mon Sep 17 00:00:00 2001 From: Ivan Dromigny Date: Wed, 2 Oct 2019 18:06:34 +0200 Subject: [PATCH 1/4] Add informations in subscriptions `attributes` --- moto/sns/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/moto/sns/models.py b/moto/sns/models.py index 92e6c61d..515fe116 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -339,6 +339,14 @@ class SNSBackend(BaseBackend): return old_subscription topic = self.get_topic(topic_arn) subscription = Subscription(topic, endpoint, protocol) + attributes = { + 'PendingConfirmation' : 'false', + 'Endpoint' : endpoint, + 'TopicArn' : topic_arn, + 'Protocol': protocol, + 'SubscriptionArn': subscription.arn + } + subscription.attributes = attributes self.subscriptions[subscription.arn] = subscription return subscription From 03986df929a2dd59e845bf4be90b1acf3b09e0f2 Mon Sep 17 00:00:00 2001 From: Ivan Dromigny Date: Thu, 3 Oct 2019 09:53:04 +0200 Subject: [PATCH 2/4] Update syntax --- moto/sns/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moto/sns/models.py b/moto/sns/models.py index 515fe116..cead172e 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -340,9 +340,9 @@ class SNSBackend(BaseBackend): topic = self.get_topic(topic_arn) subscription = Subscription(topic, endpoint, protocol) attributes = { - 'PendingConfirmation' : 'false', - 'Endpoint' : endpoint, - 'TopicArn' : topic_arn, + 'PendingConfirmation': 'false', + 'Endpoint': endpoint, + 'TopicArn': topic_arn, 'Protocol': protocol, 'SubscriptionArn': subscription.arn } From 02fc1fbcef69a4de1a98bf808a15beb71ebfb280 Mon Sep 17 00:00:00 2001 From: Ivan Dromigny Date: Mon, 14 Oct 2019 18:03:01 +0200 Subject: [PATCH 3/4] Add a test --- tests/test_sns/test_subscriptions_boto3.py | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_sns/test_subscriptions_boto3.py b/tests/test_sns/test_subscriptions_boto3.py index 012cd647..d09f625f 100644 --- a/tests/test_sns/test_subscriptions_boto3.py +++ b/tests/test_sns/test_subscriptions_boto3.py @@ -181,6 +181,30 @@ def test_subscription_paging(): int(DEFAULT_PAGE_SIZE / 3)) topic1_subscriptions.shouldnt.have("NextToken") +@mock_sns +def test_subscribe_attributes(): + client = boto3.client('sns', region_name='us-east-1') + client.create_topic(Name="some-topic") + resp = client.create_topic(Name="some-topic") + arn = resp['TopicArn'] + + resp = client.subscribe( + TopicArn=arn, + Protocol='http', + Endpoint='http://test.com' + ) + + attributes = client.get_subscription_attributes( + SubscriptionArn=resp['SubscriptionArn'] + ) + + attributes.should.contain('Attributes') + attributes['Attributes'].should.contain('PendingConfirmation') + attributes['Attributes'].should.contain('Endpoint') + attributes['Attributes'].should.contain('TopicArn') + attributes['Attributes'].should.contain('Protocol') + attributes['Attributes'].should.contain('SubscriptionArn') + @mock_sns def test_creating_subscription_with_attributes(): From 123209515c7338b3324e29b51d478b48afbca25c Mon Sep 17 00:00:00 2001 From: Ivan Dromigny Date: Tue, 15 Oct 2019 16:12:22 +0200 Subject: [PATCH 4/4] Change test --- tests/test_sns/test_subscriptions_boto3.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_sns/test_subscriptions_boto3.py b/tests/test_sns/test_subscriptions_boto3.py index d09f625f..282ec465 100644 --- a/tests/test_sns/test_subscriptions_boto3.py +++ b/tests/test_sns/test_subscriptions_boto3.py @@ -200,10 +200,15 @@ def test_subscribe_attributes(): attributes.should.contain('Attributes') attributes['Attributes'].should.contain('PendingConfirmation') + attributes['Attributes']['PendingConfirmation'].should.equal('false') attributes['Attributes'].should.contain('Endpoint') + attributes['Attributes']['Endpoint'].should.equal('http://test.com') attributes['Attributes'].should.contain('TopicArn') + attributes['Attributes']['TopicArn'].should.equal(arn) attributes['Attributes'].should.contain('Protocol') + attributes['Attributes']['Protocol'].should.equal('http') attributes['Attributes'].should.contain('SubscriptionArn') + attributes['Attributes']['SubscriptionArn'].should.equal(resp['SubscriptionArn']) @mock_sns