Replace sure with regular assertions (#6594)

This commit is contained in:
kbalk 2023-08-04 10:14:14 -04:00 committed by GitHub
parent b32c5e8d96
commit 6a2131358a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 330 additions and 322 deletions

View File

@ -1,21 +1,16 @@
"""Test the different server responses."""
from datetime import datetime from datetime import datetime
import re import re
import sure # noqa # pylint: disable=unused-import
import moto.server as server import moto.server as server
"""
Test the different server responses
"""
def test_ses_list_identities(): def test_ses_list_identities():
backend = server.create_backend_app("ses") backend = server.create_backend_app("ses")
test_client = backend.test_client() test_client = backend.test_client()
res = test_client.get("/?Action=ListIdentities") res = test_client.get("/?Action=ListIdentities")
res.data.should.contain(b"ListIdentitiesResponse") assert b"ListIdentitiesResponse" in res.data
def test_ses_get_send_statistics(): def test_ses_get_send_statistics():
@ -23,7 +18,7 @@ def test_ses_get_send_statistics():
test_client = backend.test_client() test_client = backend.test_client()
res = test_client.get("/?Action=GetSendStatistics") res = test_client.get("/?Action=GetSendStatistics")
res.data.should.contain(b"GetSendStatisticsResponse") assert b"GetSendStatisticsResponse" in res.data
# Timestamps must be in ISO 8601 format # Timestamps must be in ISO 8601 format
groups = re.search("<Timestamp>(.*)</Timestamp>", res.data.decode("utf-8")) groups = re.search("<Timestamp>(.*)</Timestamp>", res.data.decode("utf-8"))

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
import boto3
import json import json
import boto3
import sure # noqa # pylint: disable=unused-import import sure # noqa # pylint: disable=unused-import
from moto import mock_ses, mock_sns, mock_sqs from moto import mock_ses, mock_sns, mock_sqs
from moto.ses.models import SESFeedback from moto.ses.models import SESFeedback
@ -57,18 +58,18 @@ def __test_sns_feedback__(addr, expected_msg, raw_email=False):
) )
# Send the message # Send the message
kwargs = dict( kwargs = {
Source="test@" + domain, "Source": "test@" + domain,
Destination={ "Destination": {
"ToAddresses": [addr + "@" + domain], "ToAddresses": [addr + "@" + domain],
"CcAddresses": ["test_cc@" + domain], "CcAddresses": ["test_cc@" + domain],
"BccAddresses": ["test_bcc@" + domain], "BccAddresses": ["test_bcc@" + domain],
}, },
Message={ "Message": {
"Subject": {"Data": "test subject"}, "Subject": {"Data": "test subject"},
"Body": {"Text": {"Data": "test body"}}, "Body": {"Text": {"Data": "test body"}},
}, },
) }
if raw_email: if raw_email:
kwargs.pop("Message") kwargs.pop("Message")
kwargs.pop("Destination") kwargs.pop("Destination")
@ -139,22 +140,16 @@ def test_get_identity_notification_attributes_default_values():
resp = ses.get_identity_notification_attributes( resp = ses.get_identity_notification_attributes(
Identities=["test@example.com", "another@example.com"] Identities=["test@example.com", "another@example.com"]
)["NotificationAttributes"] )["NotificationAttributes"]
resp.should.have.length_of(2) assert len(resp) == 2
resp.should.have.key("test@example.com") assert "test@example.com" in resp
resp.should.have.key("another@example.com") assert "another@example.com" in resp
resp["test@example.com"].should.have.key("ForwardingEnabled").equal(True) assert resp["test@example.com"]["ForwardingEnabled"] is True
resp["test@example.com"].should.have.key( assert resp["test@example.com"]["HeadersInBounceNotificationsEnabled"] is False
"HeadersInBounceNotificationsEnabled" assert resp["test@example.com"]["HeadersInComplaintNotificationsEnabled"] is False
).equal(False) assert resp["test@example.com"]["HeadersInDeliveryNotificationsEnabled"] is False
resp["test@example.com"].should.have.key( assert "BounceTopic" not in resp["test@example.com"]
"HeadersInComplaintNotificationsEnabled" assert "ComplaintTopic" not in resp["test@example.com"]
).equal(False) assert "DeliveryTopic" not in resp["test@example.com"]
resp["test@example.com"].should.have.key(
"HeadersInDeliveryNotificationsEnabled"
).equal(False)
resp["test@example.com"].shouldnt.have.key("BounceTopic")
resp["test@example.com"].shouldnt.have.key("ComplaintTopic")
resp["test@example.com"].shouldnt.have.key("DeliveryTopic")
@mock_ses @mock_ses
@ -166,7 +161,7 @@ def test_set_identity_feedback_forwarding_enabled():
resp = ses.get_identity_notification_attributes(Identities=["test@example.com"])[ resp = ses.get_identity_notification_attributes(Identities=["test@example.com"])[
"NotificationAttributes" "NotificationAttributes"
] ]
resp["test@example.com"].should.have.key("ForwardingEnabled").equal(True) assert resp["test@example.com"]["ForwardingEnabled"] is True
ses.set_identity_feedback_forwarding_enabled( ses.set_identity_feedback_forwarding_enabled(
Identity="test@example.com", ForwardingEnabled=False Identity="test@example.com", ForwardingEnabled=False
@ -175,7 +170,7 @@ def test_set_identity_feedback_forwarding_enabled():
resp = ses.get_identity_notification_attributes(Identities=["test@example.com"])[ resp = ses.get_identity_notification_attributes(Identities=["test@example.com"])[
"NotificationAttributes" "NotificationAttributes"
] ]
resp["test@example.com"].should.have.key("ForwardingEnabled").equal(False) assert resp["test@example.com"]["ForwardingEnabled"] is False
ses.set_identity_feedback_forwarding_enabled( ses.set_identity_feedback_forwarding_enabled(
Identity="test@example.com", ForwardingEnabled=True Identity="test@example.com", ForwardingEnabled=True
@ -184,4 +179,4 @@ def test_set_identity_feedback_forwarding_enabled():
resp = ses.get_identity_notification_attributes(Identities=["test@example.com"])[ resp = ses.get_identity_notification_attributes(Identities=["test@example.com"])[
"NotificationAttributes" "NotificationAttributes"
] ]
resp["test@example.com"].should.have.key("ForwardingEnabled").equal(True) assert resp["test@example.com"]["ForwardingEnabled"] is True

View File

@ -1,14 +1,12 @@
import sure # noqa # pylint: disable=unused-import
from moto.ses.utils import is_valid_address from moto.ses.utils import is_valid_address
def test_is_valid_address(): def test_is_valid_address():
msg = is_valid_address("test@example.com") msg = is_valid_address("test@example.com")
msg.should.equal(None) assert msg is None
msg = is_valid_address("test@") msg = is_valid_address("test@")
msg.should.be.a(str) assert isinstance(msg, str)
msg = is_valid_address("test") msg = is_valid_address("test")
msg.should.be.a(str) assert isinstance(msg, str)

View File

@ -1,33 +1,36 @@
from moto.ses.template import parse_template from moto.ses.template import parse_template
import sure # noqa # pylint: disable=unused-import
def test_template_without_args(): def test_template_without_args():
parse_template("some template", template_data={}).should.equal("some template") assert parse_template("some template", template_data={}) == "some template"
def test_template_with_simple_arg(): def test_template_with_simple_arg():
t = "Dear {{name}}," template = "Dear {{name}},"
parse_template(t, template_data={"name": "John"}).should.equal("Dear John,") assert parse_template(template, template_data={"name": "John"}) == "Dear John,"
def test_template_with_foreach(): def test_template_with_foreach():
t = "List:{{#each l}} - {{obj}}{{/each}} and other things" template = "List:{{#each l}} - {{obj}}{{/each}} and other things"
kwargs = {"l": [{"obj": "it1"}, {"obj": "it2"}]} kwargs = {"l": [{"obj": "it1"}, {"obj": "it2"}]}
parse_template(t, kwargs).should.equal("List: - it1 - it2 and other things") assert parse_template(template, kwargs) == "List: - it1 - it2 and other things"
def test_template_with_multiple_foreach(): def test_template_with_multiple_foreach():
t = "{{#each l}} - {{obj}}{{/each}} and list 2 {{#each l2}} {{o1}} {{o2}} {{/each}}" template = (
"{{#each l}} - {{obj}}{{/each}} and list 2 {{#each l2}} {{o1}} {{o2}} {{/each}}"
)
kwargs = { kwargs = {
"l": [{"obj": "it1"}, {"obj": "it2"}], "l": [{"obj": "it1"}, {"obj": "it2"}],
"l2": [{"o1": "ob1", "o2": "ob2"}, {"o1": "oc1", "o2": "oc2"}], "l2": [{"o1": "ob1", "o2": "ob2"}, {"o1": "oc1", "o2": "oc2"}],
} }
parse_template(t, kwargs).should.equal(" - it1 - it2 and list 2 ob1 ob2 oc1 oc2 ") assert (
parse_template(template, kwargs) == " - it1 - it2 and list 2 ob1 ob2 oc1 oc2 "
)
def test_template_with_single_curly_brace(): def test_template_with_single_curly_brace():
t = "Dear {{name}} my {brace} is fine." template = "Dear {{name}} my {brace} is fine."
parse_template(t, template_data={"name": "John"}).should.equal( assert parse_template(template, template_data={"name": "John"}) == (
"Dear John my {brace} is fine." "Dear John my {brace} is fine."
) )