From 4942e74ab1ae3343b0ac7b36ac32bf6631abdd2d Mon Sep 17 00:00:00 2001 From: Mike Pappas Date: Fri, 11 Nov 2016 17:01:47 -0500 Subject: [PATCH] Fix SNS application endpoint to match AWS return format (#763) --- moto/sns/models.py | 9 +++++++++ tests/test_sns/test_application.py | 2 ++ tests/test_sns/test_application_boto3.py | 2 ++ 3 files changed, 13 insertions(+) diff --git a/moto/sns/models.py b/moto/sns/models.py index 5ce2eb6f7..d924b1e5d 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -120,6 +120,15 @@ class PlatformEndpoint(object): self.attributes = attributes self.id = uuid.uuid4() self.messages = OrderedDict() + self.__fixup_attributes() + + def __fixup_attributes(self): + # When AWS returns the attributes dict, it always contains these two elements, so we need to + # automatically ensure they exist as well. + if not 'Token' in self.attributes: + self.attributes['Token'] = self.token + if not 'Enabled' in self.attributes: + self.attributes['Enabled'] = True @property def arn(self): diff --git a/tests/test_sns/test_application.py b/tests/test_sns/test_application.py index 790e3f8ff..0566adeb3 100644 --- a/tests/test_sns/test_application.py +++ b/tests/test_sns/test_application.py @@ -181,6 +181,7 @@ def test_get_endpoint_attributes(): attributes = conn.get_endpoint_attributes(endpoint_arn)['GetEndpointAttributesResponse']['GetEndpointAttributesResult']['Attributes'] attributes.should.equal({ + "Token": "some_unique_id", "Enabled": 'False', "CustomUserData": "some data", }) @@ -217,6 +218,7 @@ def test_set_endpoint_attributes(): ) attributes = conn.get_endpoint_attributes(endpoint_arn)['GetEndpointAttributesResponse']['GetEndpointAttributesResult']['Attributes'] attributes.should.equal({ + "Token": "some_unique_id", "Enabled": 'False', "CustomUserData": "other data", }) diff --git a/tests/test_sns/test_application_boto3.py b/tests/test_sns/test_application_boto3.py index 8dda67b0a..251d1cf1d 100644 --- a/tests/test_sns/test_application_boto3.py +++ b/tests/test_sns/test_application_boto3.py @@ -188,6 +188,7 @@ def test_get_endpoint_attributes(): attributes = conn.get_endpoint_attributes(EndpointArn=endpoint_arn)['Attributes'] attributes.should.equal({ + "Token": "some_unique_id", "Enabled": 'false', "CustomUserData": "some data", }) @@ -225,6 +226,7 @@ def test_set_endpoint_attributes(): ) attributes = conn.get_endpoint_attributes(EndpointArn=endpoint_arn)['Attributes'] attributes.should.equal({ + "Token": "some_unique_id", "Enabled": 'false', "CustomUserData": "other data", })