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
This commit is contained in:
Andrés Álvarez 2021-03-19 09:36:53 -06:00 committed by GitHub
parent 74272ae51c
commit a5fc99c9af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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()

View File

@ -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))