Merge pull request #1005 from fdfk/verify_email

Adding list_verified_email_addresses and testing
This commit is contained in:
Jack Danger 2017-07-11 10:56:54 -07:00 committed by GitHub
commit f80e87aca3
3 changed files with 45 additions and 0 deletions

View File

@ -36,6 +36,7 @@ class SESBackend(BaseBackend):
def __init__(self):
self.addresses = []
self.email_addresses = []
self.domains = []
self.sent_messages = []
self.sent_message_count = 0
@ -49,12 +50,18 @@ class SESBackend(BaseBackend):
def verify_email_identity(self, address):
self.addresses.append(address)
def verify_email_address(self, address):
self.email_addresses.append(address)
def verify_domain(self, domain):
self.domains.append(domain)
def list_identities(self):
return self.domains + self.addresses
def list_verified_email_addresses(self):
return self.email_addresses
def delete_identity(self, identity):
if '@' in identity:
self.addresses.remove(identity)

View File

@ -15,11 +15,22 @@ class EmailResponse(BaseResponse):
template = self.response_template(VERIFY_EMAIL_IDENTITY)
return template.render()
def verify_email_address(self):
address = self.querystring.get('EmailAddress')[0]
ses_backend.verify_email_address(address)
template = self.response_template(VERIFY_EMAIL_ADDRESS)
return template.render()
def list_identities(self):
identities = ses_backend.list_identities()
template = self.response_template(LIST_IDENTITIES_RESPONSE)
return template.render(identities=identities)
def list_verified_email_addresses(self):
email_addresses = ses_backend.list_verified_email_addresses()
template = self.response_template(LIST_VERIFIED_EMAIL_RESPONSE)
return template.render(email_addresses=email_addresses)
def verify_domain_dkim(self):
domain = self.querystring.get('Domain')[0]
ses_backend.verify_domain(domain)
@ -95,6 +106,13 @@ VERIFY_EMAIL_IDENTITY = """<VerifyEmailIdentityResponse xmlns="http://ses.amazon
</ResponseMetadata>
</VerifyEmailIdentityResponse>"""
VERIFY_EMAIL_ADDRESS = """<VerifyEmailAddressResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<VerifyEmailAddressResult/>
<ResponseMetadata>
<RequestId>47e0ef1a-9bf2-11e1-9279-0100e8cf109a</RequestId>
</ResponseMetadata>
</VerifyEmailAddressResponse>"""
LIST_IDENTITIES_RESPONSE = """<ListIdentitiesResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<ListIdentitiesResult>
<Identities>
@ -108,6 +126,19 @@ LIST_IDENTITIES_RESPONSE = """<ListIdentitiesResponse xmlns="http://ses.amazonaw
</ResponseMetadata>
</ListIdentitiesResponse>"""
LIST_VERIFIED_EMAIL_RESPONSE = """<ListVerifiedEmailAddressesResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<ListVerifiedEmailAddressesResult>
<VerifiedEmailAddresses>
{% for email in email_addresses %}
<member>{{ email }}</member>
{% endfor %}
</VerifiedEmailAddresses>
</ListVerifiedEmailAddressesResult>
<ResponseMetadata>
<RequestId>cacecf23-9bf1-11e1-9279-0100e8cf109a</RequestId>
</ResponseMetadata>
</ListVerifiedEmailAddressesResponse>"""
VERIFY_DOMAIN_DKIM_RESPONSE = """<VerifyDomainDkimResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<VerifyDomainDkimResult>
<DkimTokens>

View File

@ -19,6 +19,13 @@ def test_verify_email_identity():
address = identities['Identities'][0]
address.should.equal('test@example.com')
@mock_ses
def test_verify_email_address():
conn = boto3.client('ses', region_name='us-east-1')
conn.verify_email_address(EmailAddress="test@example.com")
email_addresses = conn.list_verified_email_addresses()
email = email_addresses['VerifiedEmailAddresses'][0]
email.should.equal('test@example.com')
@mock_ses
def test_domain_verify():