Run black on moto & test directories.
This commit is contained in:
parent
c820395dbf
commit
96e5b1993d
507 changed files with 52541 additions and 47814 deletions
|
|
@ -3,14 +3,14 @@ import sure # noqa
|
|||
|
||||
import moto.server as server
|
||||
|
||||
'''
|
||||
"""
|
||||
Test the different server responses
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
def test_ses_list_identities():
|
||||
backend = server.create_backend_app("ses")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=ListIdentities')
|
||||
res = test_client.get("/?Action=ListIdentities")
|
||||
res.data.should.contain(b"ListIdentitiesResponse")
|
||||
|
|
|
|||
|
|
@ -11,106 +11,119 @@ from moto import mock_ses_deprecated
|
|||
|
||||
@mock_ses_deprecated
|
||||
def test_verify_email_identity():
|
||||
conn = boto.connect_ses('the_key', 'the_secret')
|
||||
conn = boto.connect_ses("the_key", "the_secret")
|
||||
conn.verify_email_identity("test@example.com")
|
||||
|
||||
identities = conn.list_identities()
|
||||
address = identities['ListIdentitiesResponse'][
|
||||
'ListIdentitiesResult']['Identities'][0]
|
||||
address.should.equal('test@example.com')
|
||||
address = identities["ListIdentitiesResponse"]["ListIdentitiesResult"][
|
||||
"Identities"
|
||||
][0]
|
||||
address.should.equal("test@example.com")
|
||||
|
||||
|
||||
@mock_ses_deprecated
|
||||
def test_domain_verify():
|
||||
conn = boto.connect_ses('the_key', 'the_secret')
|
||||
conn = boto.connect_ses("the_key", "the_secret")
|
||||
|
||||
conn.verify_domain_dkim("domain1.com")
|
||||
conn.verify_domain_identity("domain2.com")
|
||||
|
||||
identities = conn.list_identities()
|
||||
domains = list(identities['ListIdentitiesResponse'][
|
||||
'ListIdentitiesResult']['Identities'])
|
||||
domains.should.equal(['domain1.com', 'domain2.com'])
|
||||
domains = list(
|
||||
identities["ListIdentitiesResponse"]["ListIdentitiesResult"]["Identities"]
|
||||
)
|
||||
domains.should.equal(["domain1.com", "domain2.com"])
|
||||
|
||||
|
||||
@mock_ses_deprecated
|
||||
def test_delete_identity():
|
||||
conn = boto.connect_ses('the_key', 'the_secret')
|
||||
conn = boto.connect_ses("the_key", "the_secret")
|
||||
conn.verify_email_identity("test@example.com")
|
||||
|
||||
conn.list_identities()['ListIdentitiesResponse']['ListIdentitiesResult'][
|
||||
'Identities'].should.have.length_of(1)
|
||||
conn.list_identities()["ListIdentitiesResponse"]["ListIdentitiesResult"][
|
||||
"Identities"
|
||||
].should.have.length_of(1)
|
||||
conn.delete_identity("test@example.com")
|
||||
conn.list_identities()['ListIdentitiesResponse']['ListIdentitiesResult'][
|
||||
'Identities'].should.have.length_of(0)
|
||||
conn.list_identities()["ListIdentitiesResponse"]["ListIdentitiesResult"][
|
||||
"Identities"
|
||||
].should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_ses_deprecated
|
||||
def test_send_email():
|
||||
conn = boto.connect_ses('the_key', 'the_secret')
|
||||
conn = boto.connect_ses("the_key", "the_secret")
|
||||
|
||||
conn.send_email.when.called_with(
|
||||
"test@example.com", "test subject",
|
||||
"test body", "test_to@example.com").should.throw(BotoServerError)
|
||||
"test@example.com", "test subject", "test body", "test_to@example.com"
|
||||
).should.throw(BotoServerError)
|
||||
|
||||
conn.verify_email_identity("test@example.com")
|
||||
conn.send_email("test@example.com", "test subject",
|
||||
"test body", "test_to@example.com")
|
||||
conn.send_email(
|
||||
"test@example.com", "test subject", "test body", "test_to@example.com"
|
||||
)
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['GetSendQuotaResponse'][
|
||||
'GetSendQuotaResult']['SentLast24Hours'])
|
||||
sent_count = int(
|
||||
send_quota["GetSendQuotaResponse"]["GetSendQuotaResult"]["SentLast24Hours"]
|
||||
)
|
||||
sent_count.should.equal(1)
|
||||
|
||||
|
||||
@mock_ses_deprecated
|
||||
def test_send_html_email():
|
||||
conn = boto.connect_ses('the_key', 'the_secret')
|
||||
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)
|
||||
"test@example.com",
|
||||
"test subject",
|
||||
"<span>test body</span>",
|
||||
"test_to@example.com",
|
||||
format="html",
|
||||
).should.throw(BotoServerError)
|
||||
|
||||
conn.verify_email_identity("test@example.com")
|
||||
conn.send_email("test@example.com", "test subject",
|
||||
"<span>test body</span>", "test_to@example.com", format="html")
|
||||
conn.send_email(
|
||||
"test@example.com",
|
||||
"test subject",
|
||||
"<span>test body</span>",
|
||||
"test_to@example.com",
|
||||
format="html",
|
||||
)
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['GetSendQuotaResponse'][
|
||||
'GetSendQuotaResult']['SentLast24Hours'])
|
||||
sent_count = int(
|
||||
send_quota["GetSendQuotaResponse"]["GetSendQuotaResult"]["SentLast24Hours"]
|
||||
)
|
||||
sent_count.should.equal(1)
|
||||
|
||||
|
||||
@mock_ses_deprecated
|
||||
def test_send_raw_email():
|
||||
conn = boto.connect_ses('the_key', 'the_secret')
|
||||
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'
|
||||
message["Subject"] = "Test"
|
||||
message["From"] = "test@example.com"
|
||||
message["To"] = "to@example.com"
|
||||
|
||||
# Message body
|
||||
part = email.mime.text.MIMEText('test file attached')
|
||||
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')
|
||||
part = email.mime.text.MIMEText("contents of test file here")
|
||||
part.add_header("Content-Disposition", "attachment; filename=test.txt")
|
||||
message.attach(part)
|
||||
|
||||
conn.send_raw_email.when.called_with(
|
||||
source=message['From'],
|
||||
raw_message=message.as_string(),
|
||||
source=message["From"], raw_message=message.as_string()
|
||||
).should.throw(BotoServerError)
|
||||
|
||||
conn.verify_email_identity("test@example.com")
|
||||
conn.send_raw_email(
|
||||
source=message['From'],
|
||||
raw_message=message.as_string(),
|
||||
)
|
||||
conn.send_raw_email(source=message["From"], raw_message=message.as_string())
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['GetSendQuotaResponse'][
|
||||
'GetSendQuotaResult']['SentLast24Hours'])
|
||||
sent_count = int(
|
||||
send_quota["GetSendQuotaResponse"]["GetSendQuotaResult"]["SentLast24Hours"]
|
||||
)
|
||||
sent_count.should.equal(1)
|
||||
|
|
|
|||
|
|
@ -12,46 +12,48 @@ from moto import mock_ses
|
|||
|
||||
@mock_ses
|
||||
def test_verify_email_identity():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
conn.verify_email_identity(EmailAddress="test@example.com")
|
||||
|
||||
identities = conn.list_identities()
|
||||
address = identities['Identities'][0]
|
||||
address.should.equal('test@example.com')
|
||||
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 = 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')
|
||||
email = email_addresses["VerifiedEmailAddresses"][0]
|
||||
email.should.equal("test@example.com")
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_domain_verify():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
|
||||
conn.verify_domain_dkim(Domain="domain1.com")
|
||||
conn.verify_domain_identity(Domain="domain2.com")
|
||||
|
||||
identities = conn.list_identities()
|
||||
domains = list(identities['Identities'])
|
||||
domains.should.equal(['domain1.com', 'domain2.com'])
|
||||
domains = list(identities["Identities"])
|
||||
domains.should.equal(["domain1.com", "domain2.com"])
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_delete_identity():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
conn.verify_email_identity(EmailAddress="test@example.com")
|
||||
|
||||
conn.list_identities()['Identities'].should.have.length_of(1)
|
||||
conn.list_identities()["Identities"].should.have.length_of(1)
|
||||
conn.delete_identity(Identity="test@example.com")
|
||||
conn.list_identities()['Identities'].should.have.length_of(0)
|
||||
conn.list_identities()["Identities"].should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_send_email():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
|
||||
kwargs = dict(
|
||||
Source="test@example.com",
|
||||
|
|
@ -62,27 +64,27 @@ def test_send_email():
|
|||
},
|
||||
Message={
|
||||
"Subject": {"Data": "test subject"},
|
||||
"Body": {"Text": {"Data": "test body"}}
|
||||
}
|
||||
"Body": {"Text": {"Data": "test body"}},
|
||||
},
|
||||
)
|
||||
conn.send_email.when.called_with(**kwargs).should.throw(ClientError)
|
||||
|
||||
conn.verify_domain_identity(Domain='example.com')
|
||||
conn.verify_domain_identity(Domain="example.com")
|
||||
conn.send_email(**kwargs)
|
||||
|
||||
too_many_addresses = list('to%s@example.com' % i for i in range(51))
|
||||
too_many_addresses = list("to%s@example.com" % i for i in range(51))
|
||||
conn.send_email.when.called_with(
|
||||
**dict(kwargs, Destination={'ToAddresses': too_many_addresses})
|
||||
**dict(kwargs, Destination={"ToAddresses": too_many_addresses})
|
||||
).should.throw(ClientError)
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['SentLast24Hours'])
|
||||
sent_count = int(send_quota["SentLast24Hours"])
|
||||
sent_count.should.equal(3)
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_send_templated_email():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
|
||||
kwargs = dict(
|
||||
Source="test@example.com",
|
||||
|
|
@ -92,38 +94,35 @@ def test_send_templated_email():
|
|||
"BccAddresses": ["test_bcc@example.com"],
|
||||
},
|
||||
Template="test_template",
|
||||
TemplateData='{\"name\": \"test\"}'
|
||||
TemplateData='{"name": "test"}',
|
||||
)
|
||||
|
||||
conn.send_templated_email.when.called_with(
|
||||
**kwargs).should.throw(ClientError)
|
||||
conn.send_templated_email.when.called_with(**kwargs).should.throw(ClientError)
|
||||
|
||||
conn.verify_domain_identity(Domain='example.com')
|
||||
conn.verify_domain_identity(Domain="example.com")
|
||||
conn.send_templated_email(**kwargs)
|
||||
|
||||
too_many_addresses = list('to%s@example.com' % i for i in range(51))
|
||||
too_many_addresses = list("to%s@example.com" % i for i in range(51))
|
||||
conn.send_templated_email.when.called_with(
|
||||
**dict(kwargs, Destination={'ToAddresses': too_many_addresses})
|
||||
**dict(kwargs, Destination={"ToAddresses": too_many_addresses})
|
||||
).should.throw(ClientError)
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['SentLast24Hours'])
|
||||
sent_count = int(send_quota["SentLast24Hours"])
|
||||
sent_count.should.equal(3)
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_send_html_email():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
|
||||
kwargs = dict(
|
||||
Source="test@example.com",
|
||||
Destination={
|
||||
"ToAddresses": ["test_to@example.com"]
|
||||
},
|
||||
Destination={"ToAddresses": ["test_to@example.com"]},
|
||||
Message={
|
||||
"Subject": {"Data": "test subject"},
|
||||
"Body": {"Html": {"Data": "test body"}}
|
||||
}
|
||||
"Body": {"Html": {"Data": "test body"}},
|
||||
},
|
||||
)
|
||||
|
||||
conn.send_email.when.called_with(**kwargs).should.throw(ClientError)
|
||||
|
|
@ -132,32 +131,29 @@ def test_send_html_email():
|
|||
conn.send_email(**kwargs)
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['SentLast24Hours'])
|
||||
sent_count = int(send_quota["SentLast24Hours"])
|
||||
sent_count.should.equal(1)
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_send_raw_email():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
|
||||
message = MIMEMultipart()
|
||||
message['Subject'] = 'Test'
|
||||
message['From'] = 'test@example.com'
|
||||
message['To'] = 'to@example.com, foo@example.com'
|
||||
message["Subject"] = "Test"
|
||||
message["From"] = "test@example.com"
|
||||
message["To"] = "to@example.com, foo@example.com"
|
||||
|
||||
# Message body
|
||||
part = MIMEText('test file attached')
|
||||
part = MIMEText("test file attached")
|
||||
message.attach(part)
|
||||
|
||||
# Attachment
|
||||
part = MIMEText('contents of test file here')
|
||||
part.add_header('Content-Disposition', 'attachment; filename=test.txt')
|
||||
part = MIMEText("contents of test file here")
|
||||
part.add_header("Content-Disposition", "attachment; filename=test.txt")
|
||||
message.attach(part)
|
||||
|
||||
kwargs = dict(
|
||||
Source=message['From'],
|
||||
RawMessage={'Data': message.as_string()},
|
||||
)
|
||||
kwargs = dict(Source=message["From"], RawMessage={"Data": message.as_string()})
|
||||
|
||||
conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)
|
||||
|
||||
|
|
@ -165,31 +161,29 @@ def test_send_raw_email():
|
|||
conn.send_raw_email(**kwargs)
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['SentLast24Hours'])
|
||||
sent_count = int(send_quota["SentLast24Hours"])
|
||||
sent_count.should.equal(2)
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_send_raw_email_without_source():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
|
||||
message = MIMEMultipart()
|
||||
message['Subject'] = 'Test'
|
||||
message['From'] = 'test@example.com'
|
||||
message['To'] = 'to@example.com, foo@example.com'
|
||||
message["Subject"] = "Test"
|
||||
message["From"] = "test@example.com"
|
||||
message["To"] = "to@example.com, foo@example.com"
|
||||
|
||||
# Message body
|
||||
part = MIMEText('test file attached')
|
||||
part = MIMEText("test file attached")
|
||||
message.attach(part)
|
||||
|
||||
# Attachment
|
||||
part = MIMEText('contents of test file here')
|
||||
part.add_header('Content-Disposition', 'attachment; filename=test.txt')
|
||||
part = MIMEText("contents of test file here")
|
||||
part.add_header("Content-Disposition", "attachment; filename=test.txt")
|
||||
message.attach(part)
|
||||
|
||||
kwargs = dict(
|
||||
RawMessage={'Data': message.as_string()},
|
||||
)
|
||||
kwargs = dict(RawMessage={"Data": message.as_string()})
|
||||
|
||||
conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)
|
||||
|
||||
|
|
@ -197,29 +191,26 @@ def test_send_raw_email_without_source():
|
|||
conn.send_raw_email(**kwargs)
|
||||
|
||||
send_quota = conn.get_send_quota()
|
||||
sent_count = int(send_quota['SentLast24Hours'])
|
||||
sent_count = int(send_quota["SentLast24Hours"])
|
||||
sent_count.should.equal(2)
|
||||
|
||||
|
||||
@mock_ses
|
||||
def test_send_raw_email_without_source_or_from():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
|
||||
message = MIMEMultipart()
|
||||
message['Subject'] = 'Test'
|
||||
message['To'] = 'to@example.com, foo@example.com'
|
||||
message["Subject"] = "Test"
|
||||
message["To"] = "to@example.com, foo@example.com"
|
||||
|
||||
# Message body
|
||||
part = MIMEText('test file attached')
|
||||
part = MIMEText("test file attached")
|
||||
message.attach(part)
|
||||
# Attachment
|
||||
part = MIMEText('contents of test file here')
|
||||
part.add_header('Content-Disposition', 'attachment; filename=test.txt')
|
||||
part = MIMEText("contents of test file here")
|
||||
part.add_header("Content-Disposition", "attachment; filename=test.txt")
|
||||
message.attach(part)
|
||||
|
||||
kwargs = dict(
|
||||
RawMessage={'Data': message.as_string()},
|
||||
)
|
||||
kwargs = dict(RawMessage={"Data": message.as_string()})
|
||||
|
||||
conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,19 +14,16 @@ from moto.ses.models import SESFeedback
|
|||
|
||||
@mock_ses
|
||||
def test_enable_disable_ses_sns_communication():
|
||||
conn = boto3.client('ses', region_name='us-east-1')
|
||||
conn = boto3.client("ses", region_name="us-east-1")
|
||||
conn.set_identity_notification_topic(
|
||||
Identity='test.com',
|
||||
NotificationType='Bounce',
|
||||
SnsTopic='the-arn'
|
||||
)
|
||||
conn.set_identity_notification_topic(
|
||||
Identity='test.com',
|
||||
NotificationType='Bounce'
|
||||
Identity="test.com", NotificationType="Bounce", SnsTopic="the-arn"
|
||||
)
|
||||
conn.set_identity_notification_topic(Identity="test.com", NotificationType="Bounce")
|
||||
|
||||
|
||||
def __setup_feedback_env__(ses_conn, sns_conn, sqs_conn, domain, topic, queue, region, expected_msg):
|
||||
def __setup_feedback_env__(
|
||||
ses_conn, sns_conn, sqs_conn, domain, topic, queue, region, expected_msg
|
||||
):
|
||||
"""Setup the AWS environment to test the SES SNS Feedback"""
|
||||
# Environment setup
|
||||
# Create SQS queue
|
||||
|
|
@ -35,30 +32,32 @@ def __setup_feedback_env__(ses_conn, sns_conn, sqs_conn, domain, topic, queue, r
|
|||
create_topic_response = sns_conn.create_topic(Name=topic)
|
||||
topic_arn = create_topic_response["TopicArn"]
|
||||
# Subscribe the SNS topic to the SQS queue
|
||||
sns_conn.subscribe(TopicArn=topic_arn,
|
||||
Protocol="sqs",
|
||||
Endpoint="arn:aws:sqs:%s:123456789012:%s" % (region, queue))
|
||||
sns_conn.subscribe(
|
||||
TopicArn=topic_arn,
|
||||
Protocol="sqs",
|
||||
Endpoint="arn:aws:sqs:%s:123456789012:%s" % (region, queue),
|
||||
)
|
||||
# Verify SES domain
|
||||
ses_conn.verify_domain_identity(Domain=domain)
|
||||
# Setup SES notification topic
|
||||
if expected_msg is not None:
|
||||
ses_conn.set_identity_notification_topic(
|
||||
Identity=domain,
|
||||
NotificationType=expected_msg,
|
||||
SnsTopic=topic_arn
|
||||
Identity=domain, NotificationType=expected_msg, SnsTopic=topic_arn
|
||||
)
|
||||
|
||||
|
||||
def __test_sns_feedback__(addr, expected_msg):
|
||||
region_name = "us-east-1"
|
||||
ses_conn = boto3.client('ses', region_name=region_name)
|
||||
sns_conn = boto3.client('sns', region_name=region_name)
|
||||
sqs_conn = boto3.resource('sqs', region_name=region_name)
|
||||
ses_conn = boto3.client("ses", region_name=region_name)
|
||||
sns_conn = boto3.client("sns", region_name=region_name)
|
||||
sqs_conn = boto3.resource("sqs", region_name=region_name)
|
||||
domain = "example.com"
|
||||
topic = "bounce-arn-feedback"
|
||||
queue = "feedback-test-queue"
|
||||
|
||||
__setup_feedback_env__(ses_conn, sns_conn, sqs_conn, domain, topic, queue, region_name, expected_msg)
|
||||
__setup_feedback_env__(
|
||||
ses_conn, sns_conn, sqs_conn, domain, topic, queue, region_name, expected_msg
|
||||
)
|
||||
|
||||
# Send the message
|
||||
kwargs = dict(
|
||||
|
|
@ -70,8 +69,8 @@ def __test_sns_feedback__(addr, expected_msg):
|
|||
},
|
||||
Message={
|
||||
"Subject": {"Data": "test subject"},
|
||||
"Body": {"Text": {"Data": "test body"}}
|
||||
}
|
||||
"Body": {"Text": {"Data": "test body"}},
|
||||
},
|
||||
)
|
||||
ses_conn.send_email(**kwargs)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue