sns#create_platform_endpoint: If token and attributes are the same, return endpoint (#4055)

* If token and attributes are the same, return endpoint

* fix black

* moto sns platform_endpoint.attributes includes only token,enabled

* add tests when calling sns#create_platform_endpoint with same attrs for #4056
This commit is contained in:
kohbis 2021-07-04 15:43:22 +09:00 committed by GitHub
commit c20a36b8cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 5 deletions

View file

@ -584,10 +584,13 @@ class SNSBackend(BaseBackend):
def create_platform_endpoint(
self, region, application, custom_user_data, token, attributes
):
if any(
token == endpoint.token for endpoint in self.platform_endpoints.values()
):
raise DuplicateSnsEndpointError("Duplicate endpoint token: %s" % token)
for endpoint in self.platform_endpoints.values():
if token == endpoint.token:
if attributes["Enabled"].lower() == endpoint.attributes["Enabled"]:
return endpoint
raise DuplicateSnsEndpointError(
"Duplicate endpoint token with different attributes: %s" % token
)
platform_endpoint = PlatformEndpoint(
region, application, custom_user_data, token, attributes
)