moto/tests/test_ses/test_ses.py

117 lines
3.6 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2013-02-25 04:30:51 +00:00
import email
import boto
from boto.exception import BotoServerError
2013-08-03 21:21:25 +00:00
import sure # noqa
2013-02-25 04:30:51 +00:00
2017-02-16 03:35:45 +00:00
from moto import mock_ses_deprecated
2013-02-25 04:30:51 +00:00
2017-02-16 03:35:45 +00:00
@mock_ses_deprecated
2013-02-25 04:30:51 +00:00
def test_verify_email_identity():
conn = boto.connect_ses('the_key', 'the_secret')
conn.verify_email_identity("test@example.com")
identities = conn.list_identities()
2017-02-24 02:37:43 +00:00
address = identities['ListIdentitiesResponse'][
'ListIdentitiesResult']['Identities'][0]
2013-02-25 04:30:51 +00:00
address.should.equal('test@example.com')
2017-02-16 03:35:45 +00:00
@mock_ses_deprecated
2013-02-25 04:30:51 +00:00
def test_domain_verify():
conn = boto.connect_ses('the_key', 'the_secret')
conn.verify_domain_dkim("domain1.com")
conn.verify_domain_identity("domain2.com")
identities = conn.list_identities()
2017-02-24 02:37:43 +00:00
domains = list(identities['ListIdentitiesResponse'][
'ListIdentitiesResult']['Identities'])
2013-02-25 04:30:51 +00:00
domains.should.equal(['domain1.com', 'domain2.com'])
2017-02-16 03:35:45 +00:00
@mock_ses_deprecated
2013-02-25 04:30:51 +00:00
def test_delete_identity():
conn = boto.connect_ses('the_key', 'the_secret')
conn.verify_email_identity("test@example.com")
2017-02-24 02:37:43 +00:00
conn.list_identities()['ListIdentitiesResponse']['ListIdentitiesResult'][
'Identities'].should.have.length_of(1)
2013-02-25 04:30:51 +00:00
conn.delete_identity("test@example.com")
2017-02-24 02:37:43 +00:00
conn.list_identities()['ListIdentitiesResponse']['ListIdentitiesResult'][
'Identities'].should.have.length_of(0)
2013-02-25 04:30:51 +00:00
2017-02-16 03:35:45 +00:00
@mock_ses_deprecated
2013-02-25 04:30:51 +00:00
def test_send_email():
conn = boto.connect_ses('the_key', 'the_secret')
2013-08-03 21:21:25 +00:00
conn.send_email.when.called_with(
"test@example.com", "test subject",
2013-02-25 04:30:51 +00:00
"test body", "test_to@example.com").should.throw(BotoServerError)
conn.verify_email_identity("test@example.com")
2017-02-24 02:37:43 +00:00
conn.send_email("test@example.com", "test subject",
"test body", "test_to@example.com")
2013-02-25 04:30:51 +00:00
send_quota = conn.get_send_quota()
2017-02-24 02:37:43 +00:00
sent_count = int(send_quota['GetSendQuotaResponse'][
'GetSendQuotaResult']['SentLast24Hours'])
2013-02-25 04:30:51 +00:00
sent_count.should.equal(1)
2017-02-24 02:37:43 +00:00
2017-02-16 03:35:45 +00:00
@mock_ses_deprecated
2013-09-26 13:17:38 +00:00
def test_send_html_email():
conn = boto.connect_ses('the_key', 'the_secret')
conn.send_email.when.called_with(
"test@example.com", "test subject",
"<span>test body</span>", "test_to@example.com", format="html").should.throw(BotoServerError)
2013-02-25 04:30:51 +00:00
2013-09-26 13:17:38 +00:00
conn.verify_email_identity("test@example.com")
2017-02-24 02:37:43 +00:00
conn.send_email("test@example.com", "test subject",
"<span>test body</span>", "test_to@example.com", format="html")
2013-09-26 13:17:38 +00:00
send_quota = conn.get_send_quota()
2017-02-24 02:37:43 +00:00
sent_count = int(send_quota['GetSendQuotaResponse'][
'GetSendQuotaResult']['SentLast24Hours'])
2013-09-26 13:17:38 +00:00
sent_count.should.equal(1)
2013-02-25 04:30:51 +00:00
2017-02-24 02:37:43 +00:00
2017-02-16 03:35:45 +00:00
@mock_ses_deprecated
2013-02-25 04:30:51 +00:00
def test_send_raw_email():
conn = boto.connect_ses('the_key', 'the_secret')
message = email.mime.multipart.MIMEMultipart()
message['Subject'] = 'Test'
message['From'] = 'test@example.com'
message['To'] = 'to@example.com'
2013-02-25 04:30:51 +00:00
# Message body
part = email.mime.text.MIMEText('test file attached')
message.attach(part)
# Attachment
part = email.mime.text.MIMEText('contents of test file here')
part.add_header('Content-Disposition', 'attachment; filename=test.txt')
message.attach(part)
2013-08-03 21:21:25 +00:00
conn.send_raw_email.when.called_with(
source=message['From'],
raw_message=message.as_string(),
).should.throw(BotoServerError)
2013-02-25 04:30:51 +00:00
conn.verify_email_identity("test@example.com")
2013-08-03 21:21:25 +00:00
conn.send_raw_email(
source=message['From'],
raw_message=message.as_string(),
)
2013-02-25 04:30:51 +00:00
send_quota = conn.get_send_quota()
2017-02-24 02:37:43 +00:00
sent_count = int(send_quota['GetSendQuotaResponse'][
'GetSendQuotaResult']['SentLast24Hours'])
2013-02-25 04:30:51 +00:00
sent_count.should.equal(1)