From e9dc5edf7fafeb677bc3d720c6e2c3dfc8f3460e Mon Sep 17 00:00:00 2001 From: aantillonl Date: Sun, 31 Jan 2021 14:29:10 +0200 Subject: [PATCH] Update SNS get_endpoint_attributes response for Not Found endpoints (#3637) The response returned for sns.get_endpoint_attributes was not in sync with the actual response from boto. Co-authored-by: Antillon, Alejandro --- moto/sns/exceptions.py | 16 ++++++++++++++-- moto/sns/models.py | 2 +- tests/test_sns/test_application_boto3.py | 13 +++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/moto/sns/exceptions.py b/moto/sns/exceptions.py index 187865220..74d25608e 100644 --- a/moto/sns/exceptions.py +++ b/moto/sns/exceptions.py @@ -1,12 +1,24 @@ from __future__ import unicode_literals from moto.core.exceptions import RESTError +NOT_FOUND_ENDPOINT_ERROR = """ + + {{ sender }} + {{ error_type }} + {{ message }} + + 9dd01905-5012-5f99-8663-4b3ecd0dfaef +""" + class SNSNotFoundError(RESTError): code = 404 - def __init__(self, message): - super(SNSNotFoundError, self).__init__("NotFound", message) + def __init__(self, message, **kwargs): + kwargs.setdefault("template", "endpoint_error") + kwargs.setdefault("sender", "Sender") + self.templates["endpoint_error"] = NOT_FOUND_ENDPOINT_ERROR + super(SNSNotFoundError, self).__init__("NotFound", message, **kwargs) class ResourceNotFoundError(RESTError): diff --git a/moto/sns/models.py b/moto/sns/models.py index f1091bf74..2bde642ac 100644 --- a/moto/sns/models.py +++ b/moto/sns/models.py @@ -605,7 +605,7 @@ class SNSBackend(BaseBackend): try: return self.platform_endpoints[arn] except KeyError: - raise SNSNotFoundError("Endpoint with arn {0} not found".format(arn)) + raise SNSNotFoundError("Endpoint does not exist") def set_endpoint_attributes(self, arn, attributes): endpoint = self.get_endpoint(arn) diff --git a/tests/test_sns/test_application_boto3.py b/tests/test_sns/test_application_boto3.py index f23b07543..2720c3eab 100644 --- a/tests/test_sns/test_application_boto3.py +++ b/tests/test_sns/test_application_boto3.py @@ -5,6 +5,7 @@ from botocore.exceptions import ClientError from moto import mock_sns import sure # noqa from moto.core import ACCOUNT_ID +import pytest @mock_sns @@ -206,6 +207,18 @@ def test_get_endpoint_attributes(): ) +@mock_sns +def test_get_non_existent_endpoint_attributes(): + conn = boto3.client("sns", region_name="us-east-1") + endpoint_arn = "arn:aws:sns:us-east-1:123456789012:endpoint/APNS/my-application/c1f76c42-192a-4e75-b04f-a9268ce2abf3" + with pytest.raises(conn.exceptions.NotFoundException) as excinfo: + conn.get_endpoint_attributes(EndpointArn=endpoint_arn) + error = excinfo.value.response["Error"] + error["Type"].should.equal("Sender") + error["Code"].should.equal("NotFound") + error["Message"].should.equal("Endpoint does not exist") + + @mock_sns def test_get_missing_endpoint_attributes(): conn = boto3.client("sns", region_name="us-east-1")