From a5fc99c9af86d2d93b8f55a31f1ea899f2eb14fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20=C3=81lvarez?= Date: Fri, 19 Mar 2021 09:36:53 -0600 Subject: [PATCH] Raise `TemplateDoesNotExist` if template does not exist (#3784) * Raise TemplateDoesNotExist if template does not exist When sending templated emails * Remove unnecessary 'when called with' in test --- moto/ses/models.py | 3 +++ tests/test_ses/test_ses_boto3.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/moto/ses/models.py b/moto/ses/models.py index 138c33f3e..c6722c3d1 100644 --- a/moto/ses/models.py +++ b/moto/ses/models.py @@ -164,6 +164,9 @@ class SESBackend(BaseBackend): self.rejected_messages_count += 1 raise MessageRejectedError("Email address not verified %s" % source) + if not self.templates.get(template[0]): + raise TemplateDoesNotExist("Template (%s) does not exist" % template[0]) + self.__process_sns_feedback__(source, destinations, region) message_id = get_random_message_id() diff --git a/tests/test_ses/test_ses_boto3.py b/tests/test_ses/test_ses_boto3.py index 287eb46b9..c071ddc1c 100644 --- a/tests/test_ses/test_ses_boto3.py +++ b/tests/test_ses/test_ses_boto3.py @@ -132,6 +132,21 @@ def test_send_templated_email(): conn.send_templated_email.when.called_with(**kwargs).should.throw(ClientError) conn.verify_domain_identity(Domain="example.com") + + with pytest.raises(ClientError) as ex: + conn.send_templated_email(**kwargs) + + ex.value.response["Error"]["Code"].should.equal("TemplateDoesNotExist") + + conn.create_template( + Template={ + "TemplateName": "test_template", + "SubjectPart": "lalala", + "HtmlPart": "", + "TextPart": "", + } + ) + conn.send_templated_email(**kwargs) too_many_addresses = list("to%s@example.com" % i for i in range(51))