From e9f5a64f0f736ca79e75cd0b75d8841e840775c7 Mon Sep 17 00:00:00 2001 From: kbalk <7536198+kbalk@users.noreply.github.com> Date: Thu, 10 Aug 2023 14:07:41 -0400 Subject: [PATCH] Techdebt: Replace sure with regular assertions in SNS (#6621) --- tests/test_sns/test_application_boto3.py | 128 ++-- tests/test_sns/test_publish_batch.py | 73 ++- tests/test_sns/test_publishing_boto3.py | 680 ++++++++++----------- tests/test_sns/test_server.py | 20 +- tests/test_sns/test_sns_cloudformation.py | 46 +- tests/test_sns/test_subscriptions_boto3.py | 284 +++++---- tests/test_sns/test_topics_boto3.py | 423 ++++++------- tests/test_sns/test_utils.py | 3 +- 8 files changed, 819 insertions(+), 838 deletions(-) diff --git a/tests/test_sns/test_application_boto3.py b/tests/test_sns/test_application_boto3.py index bdc7e3e4c..91b7f4396 100644 --- a/tests/test_sns/test_application_boto3.py +++ b/tests/test_sns/test_application_boto3.py @@ -1,10 +1,10 @@ import boto3 from botocore.exceptions import ClientError -from moto import mock_sns -import sure # noqa # pylint: disable=unused-import -from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID import pytest +from moto import mock_sns +from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID + @mock_sns def test_create_platform_application(): @@ -18,7 +18,7 @@ def test_create_platform_application(): }, ) application_arn = response["PlatformApplicationArn"] - application_arn.should.equal( + assert application_arn == ( f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:app/APNS/my-application" ) @@ -38,20 +38,17 @@ def test_get_platform_application_attributes(): attributes = conn.get_platform_application_attributes(PlatformApplicationArn=arn)[ "Attributes" ] - attributes.should.equal( - { - "PlatformCredential": "platform_credential", - "PlatformPrincipal": "platform_principal", - } - ) + assert attributes == { + "PlatformCredential": "platform_credential", + "PlatformPrincipal": "platform_principal", + } @mock_sns def test_get_missing_platform_application_attributes(): conn = boto3.client("sns", region_name="us-east-1") - conn.get_platform_application_attributes.when.called_with( - PlatformApplicationArn="a-fake-arn" - ).should.throw(ClientError) + with pytest.raises(ClientError): + conn.get_platform_application_attributes(PlatformApplicationArn="a-fake-arn") @mock_sns @@ -72,7 +69,7 @@ def test_set_platform_application_attributes(): attributes = conn.get_platform_application_attributes(PlatformApplicationArn=arn)[ "Attributes" ] - attributes.should.equal( + assert attributes == ( {"PlatformCredential": "platform_credential", "PlatformPrincipal": "other"} ) @@ -89,7 +86,7 @@ def test_list_platform_applications(): applications_response = conn.list_platform_applications() applications = applications_response["PlatformApplications"] - applications.should.have.length_of(2) + assert len(applications) == 2 @mock_sns @@ -104,14 +101,14 @@ def test_delete_platform_application(): applications_response = conn.list_platform_applications() applications = applications_response["PlatformApplications"] - applications.should.have.length_of(2) + assert len(applications) == 2 application_arn = applications[0]["PlatformApplicationArn"] conn.delete_platform_application(PlatformApplicationArn=application_arn) applications_response = conn.list_platform_applications() applications = applications_response["PlatformApplications"] - applications.should.have.length_of(1) + assert len(applications) == 1 @mock_sns @@ -130,8 +127,9 @@ def test_create_platform_endpoint(): ) endpoint_arn = endpoint["EndpointArn"] - endpoint_arn.should.contain( + assert ( f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:endpoint/APNS/my-application/" + in endpoint_arn ) @@ -150,12 +148,13 @@ def test_create_duplicate_platform_endpoint(): Attributes={"Enabled": "false"}, ) - conn.create_platform_endpoint.when.called_with( - PlatformApplicationArn=application_arn, - Token="some_unique_id", - CustomUserData="some user data", - Attributes={"Enabled": "true"}, - ).should.throw(ClientError) + with pytest.raises(ClientError): + conn.create_platform_endpoint( + PlatformApplicationArn=application_arn, + Token="some_unique_id", + CustomUserData="some user data", + Attributes={"Enabled": "true"}, + ) @mock_sns @@ -182,7 +181,7 @@ def test_create_duplicate_platform_endpoint_with_same_attributes(): ) endpoint_arn = endpoint["EndpointArn"] - endpoint_arn.should.equal(created_endpoint_arn) + assert endpoint_arn == created_endpoint_arn @mock_sns @@ -205,9 +204,9 @@ def test_get_list_endpoints_by_platform_application(): PlatformApplicationArn=application_arn )["Endpoints"] - endpoint_list.should.have.length_of(1) - endpoint_list[0]["Attributes"]["CustomUserData"].should.equal("some data") - endpoint_list[0]["EndpointArn"].should.equal(endpoint_arn) + assert len(endpoint_list) == 1 + assert endpoint_list[0]["Attributes"]["CustomUserData"] == "some data" + assert endpoint_list[0]["EndpointArn"] == endpoint_arn @mock_sns @@ -227,7 +226,7 @@ def test_get_endpoint_attributes(): endpoint_arn = endpoint["EndpointArn"] attributes = conn.get_endpoint_attributes(EndpointArn=endpoint_arn)["Attributes"] - attributes.should.equal( + assert attributes == ( {"Token": "some_unique_id", "Enabled": "false", "CustomUserData": "some data"} ) @@ -235,21 +234,23 @@ def test_get_endpoint_attributes(): @mock_sns def test_get_non_existent_endpoint_attributes(): conn = boto3.client("sns", region_name="us-east-1") - endpoint_arn = "arn:aws:sns:us-east-1:123456789012:endpoint/APNS/my-application/c1f76c42-192a-4e75-b04f-a9268ce2abf3" + endpoint_arn = ( + "arn:aws:sns:us-east-1:123456789012:endpoint/APNS/my-application" + "/c1f76c42-192a-4e75-b04f-a9268ce2abf3" + ) with pytest.raises(conn.exceptions.NotFoundException) as excinfo: conn.get_endpoint_attributes(EndpointArn=endpoint_arn) error = excinfo.value.response["Error"] - error["Type"].should.equal("Sender") - error["Code"].should.equal("NotFound") - error["Message"].should.equal("Endpoint does not exist") + assert error["Type"] == "Sender" + assert error["Code"] == "NotFound" + assert error["Message"] == "Endpoint does not exist" @mock_sns def test_get_missing_endpoint_attributes(): conn = boto3.client("sns", region_name="us-east-1") - conn.get_endpoint_attributes.when.called_with( - EndpointArn="a-fake-arn" - ).should.throw(ClientError) + with pytest.raises(ClientError): + conn.get_endpoint_attributes(EndpointArn="a-fake-arn") @mock_sns @@ -272,7 +273,7 @@ def test_set_endpoint_attributes(): EndpointArn=endpoint_arn, Attributes={"CustomUserData": "other data"} ) attributes = conn.get_endpoint_attributes(EndpointArn=endpoint_arn)["Attributes"] - attributes.should.equal( + assert attributes == ( {"Token": "some_unique_id", "Enabled": "false", "CustomUserData": "other data"} ) @@ -291,15 +292,25 @@ def test_delete_endpoint(): Attributes={"Enabled": "true"}, ) - conn.list_endpoints_by_platform_application(PlatformApplicationArn=application_arn)[ - "Endpoints" - ].should.have.length_of(1) + assert ( + len( + conn.list_endpoints_by_platform_application( + PlatformApplicationArn=application_arn + )["Endpoints"] + ) + == 1 + ) conn.delete_endpoint(EndpointArn=endpoint["EndpointArn"]) - conn.list_endpoints_by_platform_application(PlatformApplicationArn=application_arn)[ - "Endpoints" - ].should.have.length_of(0) + assert ( + len( + conn.list_endpoints_by_platform_application( + PlatformApplicationArn=application_arn + )["Endpoints"] + ) + == 0 + ) @mock_sns @@ -341,9 +352,10 @@ def test_publish_to_disabled_platform_endpoint(): endpoint_arn = endpoint["EndpointArn"] - conn.publish.when.called_with( - Message="some message", MessageStructure="json", TargetArn=endpoint_arn - ).should.throw(ClientError) + with pytest.raises(ClientError): + conn.publish( + Message="some message", MessageStructure="json", TargetArn=endpoint_arn + ) @mock_sns @@ -355,11 +367,11 @@ def test_set_sms_attributes(): ) response = conn.get_sms_attributes() - response.should.contain("attributes") - response["attributes"].should.contain("DefaultSMSType") - response["attributes"].should.contain("test") - response["attributes"]["DefaultSMSType"].should.equal("Transactional") - response["attributes"]["test"].should.equal("test") + assert "attributes" in response + assert "DefaultSMSType" in response["attributes"] + assert "test" in response["attributes"] + assert response["attributes"]["DefaultSMSType"] == "Transactional" + assert response["attributes"]["test"] == "test" @mock_sns @@ -371,10 +383,10 @@ def test_get_sms_attributes_filtered(): ) response = conn.get_sms_attributes(attributes=["DefaultSMSType"]) - response.should.contain("attributes") - response["attributes"].should.contain("DefaultSMSType") - response["attributes"].should_not.contain("test") - response["attributes"]["DefaultSMSType"].should.equal("Transactional") + assert "attributes" in response + assert "DefaultSMSType" in response["attributes"] + assert "test" not in response["attributes"] + assert response["attributes"]["DefaultSMSType"] == "Transactional" @mock_sns @@ -395,6 +407,6 @@ def test_delete_endpoints_of_delete_app(): with pytest.raises(conn.exceptions.NotFoundException) as excinfo: conn.get_endpoint_attributes(EndpointArn=endpoint_arn) error = excinfo.value.response["Error"] - error["Type"].should.equal("Sender") - error["Code"].should.equal("NotFound") - error["Message"].should.equal("Endpoint does not exist") + assert error["Type"] == "Sender" + assert error["Code"] == "NotFound" + assert error["Message"] == "Endpoint does not exist" diff --git a/tests/test_sns/test_publish_batch.py b/tests/test_sns/test_publish_batch.py index 517d1f2f9..80d7ef69d 100644 --- a/tests/test_sns/test_publish_batch.py +++ b/tests/test_sns/test_publish_batch.py @@ -1,9 +1,9 @@ -import boto3 import json -import sure # noqa # pylint: disable=unused-import +import boto3 from botocore.exceptions import ClientError import pytest + from moto import mock_sns, mock_sqs from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID @@ -17,8 +17,8 @@ def test_publish_batch_unknown_topic(): PublishBatchRequestEntries=[{"Id": "id_1", "Message": "1"}], ) err = exc.value.response["Error"] - err["Code"].should.equal("NotFound") - err["Message"].should.equal("Topic does not exist") + assert err["Code"] == "NotFound" + assert err["Message"] == "Topic does not exist" @mock_sns @@ -34,10 +34,8 @@ def test_publish_batch_too_many_items(): ], ) err = exc.value.response["Error"] - err["Code"].should.equal("TooManyEntriesInBatchRequest") - err["Message"].should.equal( - "The batch request contains more entries than permissible." - ) + assert err["Code"] == "TooManyEntriesInBatchRequest" + assert err["Message"] == "The batch request contains more entries than permissible." @mock_sns @@ -53,9 +51,9 @@ def test_publish_batch_non_unique_ids(): ], ) err = exc.value.response["Error"] - err["Code"].should.equal("BatchEntryIdsNotDistinct") - err["Message"].should.equal( - "Two or more batch entries in the request have the same Id." + assert err["Code"] == "BatchEntryIdsNotDistinct" + assert ( + err["Message"] == "Two or more batch entries in the request have the same Id." ) @@ -73,8 +71,8 @@ def test_publish_batch_fifo_without_message_group_id(): PublishBatchRequestEntries=[{"Id": "id_2", "Message": "2"}], ) err = exc.value.response["Error"] - err["Code"].should.equal("InvalidParameter") - err["Message"].should.equal( + assert err["Code"] == "InvalidParameter" + assert err["Message"] == ( "Invalid parameter: The MessageGroupId parameter is required for FIFO topics" ) @@ -90,20 +88,21 @@ def test_publish_batch_standard_with_message_group_id(): ] resp = client.publish_batch(TopicArn=topic_arn, PublishBatchRequestEntries=entries) - resp.should.have.key("Successful").length_of(2) + assert len(resp["Successful"]) == 2 for message_status in resp["Successful"]: - message_status.should.have.key("MessageId") - [m["Id"] for m in resp["Successful"]].should.equal(["id_1", "id_3"]) + assert "MessageId" in message_status + assert [m["Id"] for m in resp["Successful"]] == ["id_1", "id_3"] - resp.should.have.key("Failed").length_of(1) - resp["Failed"][0].should.equal( - { - "Id": "id_2", - "Code": "InvalidParameter", - "Message": "Invalid parameter: MessageGroupId Reason: The request includes MessageGroupId parameter that is not valid for this topic type", - "SenderFault": True, - } - ) + assert len(resp["Failed"]) == 1 + assert resp["Failed"][0] == { + "Id": "id_2", + "Code": "InvalidParameter", + "Message": ( + "Invalid parameter: MessageGroupId Reason: The request includes " + "MessageGroupId parameter that is not valid for this topic type" + ), + "SenderFault": True, + } @mock_sns @@ -129,22 +128,22 @@ def test_publish_batch_to_sqs(): resp = client.publish_batch(TopicArn=topic_arn, PublishBatchRequestEntries=entries) - resp.should.have.key("Successful").length_of(3) + assert len(resp["Successful"]) == 3 messages = queue.receive_messages(MaxNumberOfMessages=3) - messages.should.have.length_of(3) + assert len(messages) == 3 messages = [json.loads(m.body) for m in messages] - for m in messages: - for key in list(m.keys()): + for message in messages: + for key in list(message.keys()): if key not in ["Message", "Subject", "MessageAttributes"]: - del m[key] + del message[key] - messages.should.contain({"Message": "1"}) - messages.should.contain({"Message": "2", "Subject": "subj2"}) - messages.should.contain( + assert {"Message": "1"} in messages + assert {"Message": "2", "Subject": "subj2"} in messages + assert ( {"Message": "3", "MessageAttributes": {"a": {"Type": "String", "Value": "v"}}} - ) + ) in messages @mock_sqs @@ -173,7 +172,7 @@ def test_publish_batch_to_sqs_raw(): ] resp = client.publish_batch(TopicArn=topic_arn, PublishBatchRequestEntries=entries) - resp.should.have.key("Successful").length_of(2) + assert len(resp["Successful"]) == 2 received = queue.receive_messages( MaxNumberOfMessages=10, MessageAttributeNames=["All"] @@ -181,5 +180,5 @@ def test_publish_batch_to_sqs_raw(): messages = [(message.body, message.message_attributes) for message in received] - messages.should.contain(("foo", None)) - messages.should.contain(("bar", {"a": {"StringValue": "v", "DataType": "String"}})) + assert ("foo", None) in messages + assert ("bar", {"a": {"StringValue": "v", "DataType": "String"}}) in messages diff --git a/tests/test_sns/test_publishing_boto3.py b/tests/test_sns/test_publishing_boto3.py index e3d7de43c..7b429a648 100644 --- a/tests/test_sns/test_publishing_boto3.py +++ b/tests/test_sns/test_publishing_boto3.py @@ -1,23 +1,33 @@ import base64 import json +import re +from unittest import SkipTest import boto3 -import re -from freezegun import freeze_time -import sure # noqa # pylint: disable=unused-import - from botocore.exceptions import ClientError -from unittest import SkipTest +from freezegun import freeze_time import pytest + from moto import mock_sns, mock_sqs, settings from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID from moto.core.models import responses_mock from moto.sns import sns_backends MESSAGE_FROM_SQS_TEMPLATE = ( - '{\n "Message": "%s",\n "MessageId": "%s",\n "Signature": "EXAMPLElDMXvB8r9R83tGoNn0ecwd5UjllzsvSvbItzfaMpN2nk5HVSw7XnOn/49IkxDKz8YrlH2qJXj2iZB0Zo2O71c4qQk1fMUDi3LGpij7RCW7AW9vYYsSqIKRnFS94ilu7NFhUzLiieYr4BKHpdTmdD6c0esKEYBpabxDSc=",\n "SignatureVersion": "1",\n "SigningCertURL": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",\n "Subject": "my subject",\n "Timestamp": "2015-01-01T12:00:00.000Z",\n "TopicArn": "arn:aws:sns:%s:' - + ACCOUNT_ID - + ':some-topic",\n "Type": "Notification",\n "UnsubscribeURL": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:' + '{\n "Message": "%s",\n ' + '"MessageId": "%s",\n ' + '"Signature": "EXAMPLElDMXvB8r9R83tGoNn0ecwd5UjllzsvSvbItzfaMpN2nk5HVS' + "w7XnOn/49IkxDKz8YrlH2qJXj2iZB0Zo2O71c4qQk1fMUDi3LGpij7RCW7AW9vYYsSqIK" + 'RnFS94ilu7NFhUzLiieYr4BKHpdTmdD6c0esKEYBpabxDSc=",\n ' + '"SignatureVersion": "1",\n ' + '"SigningCertURL": "https://sns.us-east-1.amazonaws.com' + '/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem",\n ' + '"Subject": "my subject",\n ' + '"Timestamp": "2015-01-01T12:00:00.000Z",\n ' + '"TopicArn": "arn:aws:sns:%s:' + ACCOUNT_ID + ':some-topic",\n ' + '"Type": "Notification",\n ' + '"UnsubscribeURL": "https://sns.us-east-1.amazonaws.com' + "/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:" + ACCOUNT_ID + ':some-topic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55"\n}' ) @@ -63,7 +73,7 @@ def test_publish_to_sqs(): "2015-01-01T12:00:00.000Z", messages[0].body, ) - acquired_message.should.equal(expected) + assert acquired_message == expected @mock_sqs @@ -89,7 +99,7 @@ def test_publish_to_sqs_raw(): with freeze_time("2015-01-01 12:00:01"): messages = queue.receive_messages(MaxNumberOfMessages=1) - messages[0].body.should.equal(message) + assert messages[0].body == message @mock_sns @@ -145,9 +155,9 @@ def test_publish_to_sqs_fifo_with_deduplication_id(): MaxNumberOfMessages=1, AttributeNames=["MessageDeduplicationId", "MessageGroupId"], ) - messages[0].attributes["MessageGroupId"].should.equal("message_group_id") - messages[0].attributes["MessageDeduplicationId"].should.equal( - "message_deduplication_id" + assert messages[0].attributes["MessageGroupId"] == "message_group_id" + assert ( + messages[0].attributes["MessageDeduplicationId"] == "message_deduplication_id" ) @@ -186,9 +196,9 @@ def test_publish_to_sqs_fifo_raw_with_deduplication_id(): MaxNumberOfMessages=1, AttributeNames=["MessageDeduplicationId", "MessageGroupId"], ) - messages[0].attributes["MessageGroupId"].should.equal("message_group_id") - messages[0].attributes["MessageDeduplicationId"].should.equal( - "message_deduplication_id" + assert messages[0].attributes["MessageGroupId"] == "message_group_id" + assert ( + messages[0].attributes["MessageDeduplicationId"] == "message_deduplication_id" ) @@ -217,7 +227,7 @@ def test_publish_to_sqs_bad(): MessageAttributes={"store": {"DataType": "String"}}, ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameterValue") + assert err.response["Error"]["Code"] == "InvalidParameterValue" try: # Test empty DataType (if the DataType field is missing entirely # botocore throws an exception during validation) @@ -229,7 +239,7 @@ def test_publish_to_sqs_bad(): }, ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameterValue") + assert err.response["Error"]["Code"] == "InvalidParameterValue" try: # Test empty Value conn.publish( @@ -238,7 +248,7 @@ def test_publish_to_sqs_bad(): MessageAttributes={"store": {"DataType": "String", "StringValue": ""}}, ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameterValue") + assert err.response["Error"]["Code"] == "InvalidParameterValue" try: # Test Number DataType, with a non numeric value conn.publish( @@ -247,9 +257,11 @@ def test_publish_to_sqs_bad(): MessageAttributes={"price": {"DataType": "Number", "StringValue": "error"}}, ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameterValue") - err.response["Error"]["Message"].should.equal( - "An error occurred (ParameterValueInvalid) when calling the Publish operation: Could not cast message attribute 'price' value to number." + assert err.response["Error"]["Code"] == "InvalidParameterValue" + assert err.response["Error"]["Message"] == ( + "An error occurred (ParameterValueInvalid) when calling the " + "Publish operation: Could not cast message attribute 'price' " + "value to number." ) @@ -282,18 +294,16 @@ def test_publish_to_sqs_msg_attr_byte_value(): ) message = json.loads(queue.receive_messages()[0].body) - message["Message"].should.equal("my message") - message["MessageAttributes"].should.equal( - { - "store": { - "Type": "Binary", - "Value": base64.b64encode(b"\x02\x03\x04").decode(), - } + assert message["Message"] == "my message" + assert message["MessageAttributes"] == { + "store": { + "Type": "Binary", + "Value": base64.b64encode(b"\x02\x03\x04").decode(), } - ) + } message = queue_raw.receive_messages()[0] - message.body.should.equal("my message") + assert message.body == "my message" @mock_sqs @@ -317,13 +327,11 @@ def test_publish_to_sqs_msg_attr_number_type(): ) message = json.loads(queue.receive_messages()[0].body) - message["Message"].should.equal("test message") - message["MessageAttributes"].should.equal( - {"retries": {"Type": "Number", "Value": "0"}} - ) + assert message["Message"] == "test message" + assert message["MessageAttributes"] == {"retries": {"Type": "Number", "Value": "0"}} message = queue_raw.receive_messages()[0] - message.body.should.equal("test message") + assert message.body == "test message" @mock_sqs @@ -359,14 +367,12 @@ def test_publish_to_sqs_msg_attr_different_formats(): ) message = messages_resp["Messages"][0] message_attributes = message["MessageAttributes"] - message_attributes.should.equal( - { - "integer": {"DataType": "Number", "StringValue": "123"}, - "float": {"DataType": "Number", "StringValue": "12.34"}, - "big-integer": {"DataType": "Number", "StringValue": "123456789"}, - "big-float": {"DataType": "Number", "StringValue": "123456.789"}, - } - ) + assert message_attributes == { + "integer": {"DataType": "Number", "StringValue": "123"}, + "float": {"DataType": "Number", "StringValue": "12.34"}, + "big-integer": {"DataType": "Number", "StringValue": "123456789"}, + "big-float": {"DataType": "Number", "StringValue": "123456.789"}, + } @mock_sns @@ -375,11 +381,12 @@ def test_publish_sms(): result = client.publish(PhoneNumber="+15551234567", Message="my message") - result.should.contain("MessageId") + assert "MessageId" in result if not settings.TEST_SERVER_MODE: sns_backend = sns_backends[ACCOUNT_ID]["us-east-1"] - sns_backend.sms_messages.should.have.key(result["MessageId"]).being.equal( - ("+15551234567", "my message") + assert sns_backend.sms_messages[result["MessageId"]] == ( + "+15551234567", + "my message", ) @@ -388,16 +395,16 @@ def test_publish_bad_sms(): client = boto3.client("sns", region_name="us-east-1") # Test invalid number - with pytest.raises(ClientError) as cm: + with pytest.raises(ClientError) as client_err: client.publish(PhoneNumber="NAA+15551234567", Message="my message") - cm.value.response["Error"]["Code"].should.equal("InvalidParameter") - cm.value.response["Error"]["Message"].should.contain("not meet the E164") + assert client_err.value.response["Error"]["Code"] == "InvalidParameter" + assert "not meet the E164" in client_err.value.response["Error"]["Message"] # Test to long ASCII message - with pytest.raises(ClientError) as cm: + with pytest.raises(ClientError) as client_err: client.publish(PhoneNumber="+15551234567", Message="a" * 1601) - cm.value.response["Error"]["Code"].should.equal("InvalidParameter") - cm.value.response["Error"]["Message"].should.contain("must be less than 1600") + assert client_err.value.response["Error"]["Code"] == "InvalidParameter" + assert "must be less than 1600" in client_err.value.response["Error"]["Message"] @mock_sqs @@ -446,7 +453,7 @@ def test_publish_to_sqs_dump_json(): "2015-01-01T12:00:00.000Z", messages[0].body, ) - acquired_message.should.equal(expected) + assert acquired_message == expected @mock_sqs @@ -482,7 +489,7 @@ def test_publish_to_sqs_in_different_region(): "2015-01-01T12:00:00.000Z", messages[0].body, ) - acquired_message.should.equal(expected) + assert acquired_message == expected @freeze_time("2013-01-01") @@ -492,8 +499,11 @@ def test_publish_to_http(): raise SkipTest("Can't mock requests in ServerMode") def callback(request): - request.headers["Content-Type"].should.equal("text/plain; charset=UTF-8") - json.loads.when.called_with(request.body.decode()).should_not.throw(Exception) + assert request.headers["Content-Type"] == "text/plain; charset=UTF-8" + try: + json.loads(request.body.decode()) + except Exception: + assert False, "json.load() raised an exception" return 200, {}, "" responses_mock.add_callback( @@ -512,11 +522,11 @@ def test_publish_to_http(): conn.publish(TopicArn=topic_arn, Message="my message", Subject="my subject") sns_backend = sns_backends[ACCOUNT_ID]["us-east-1"] - sns_backend.topics[topic_arn].sent_notifications.should.have.length_of(1) + assert len(sns_backend.topics[topic_arn].sent_notifications) == 1 notification = sns_backend.topics[topic_arn].sent_notifications[0] _, msg, subject, _, _ = notification - msg.should.equal("my message") - subject.should.equal("my subject") + assert msg == "my message" + assert subject == "my subject" @mock_sqs @@ -546,7 +556,7 @@ def test_publish_subject(): with freeze_time("2015-01-01 12:00:00"): conn.publish(TopicArn=topic_arn, Message=message, Subject=subject2) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameter") + assert err.response["Error"]["Code"] == "InvalidParameter" else: raise RuntimeError("Should have raised an InvalidParameter exception") @@ -576,8 +586,8 @@ def test_publish_null_subject(): messages = queue.receive_messages(MaxNumberOfMessages=1) acquired_message = json.loads(messages[0].body) - acquired_message["Message"].should.equal(message) - acquired_message.shouldnt.have.key("Subject") + assert acquired_message["Message"] == message + assert "Subject" not in acquired_message @mock_sns @@ -635,7 +645,10 @@ def test_publish_fifo_needs_deduplication_id(): with pytest.raises( ClientError, - match="The topic should either have ContentBasedDeduplication enabled or MessageDeduplicationId provided explicitly", + match=( + "The topic should either have ContentBasedDeduplication " + "enabled or MessageDeduplicationId provided explicitly" + ), ): topic.publish(Message="message", MessageGroupId="message_group_id") @@ -654,7 +667,10 @@ def test_publish_deduplication_id_to_non_fifo(): with pytest.raises( ClientError, - match="The request includes MessageDeduplicationId parameter that is not valid for this topic type", + match=( + "The request includes MessageDeduplicationId parameter that " + "is not valid for this topic type" + ), ): topic.publish( Message="message", MessageDeduplicationId="message_deduplication_id" @@ -702,11 +718,11 @@ def test_filtering_exact_string(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [{"store": {"Type": "String", "Value": "example_corp"}}] - ) + assert message_attributes == [ + {"store": {"Type": "String", "Value": "example_corp"}} + ] @mock_sqs @@ -723,9 +739,9 @@ def test_filtering_exact_string_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"result": {"Type": "String", "Value": "match"}}]) + assert message_attributes == [{"result": {"Type": "String", "Value": "match"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"store": "example_corp"}]) + assert message_bodies == [{"store": "example_corp"}] @mock_sqs @@ -743,16 +759,14 @@ def test_filtering_exact_string_multiple_message_attributes(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "store": {"Type": "String", "Value": "example_corp"}, - "event": {"Type": "String", "Value": "order_cancelled"}, - } - ] - ) + assert message_attributes == [ + { + "store": {"Type": "String", "Value": "example_corp"}, + "event": {"Type": "String", "Value": "order_cancelled"}, + } + ] @mock_sqs @@ -769,9 +783,9 @@ def test_filtering_exact_string_multiple_message_attributes_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"result": {"Type": "String", "Value": "match"}}]) + assert message_attributes == [{"result": {"Type": "String", "Value": "match"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"store": "example_corp", "event": "order_cancelled"}]) + assert message_bodies == [{"store": "example_corp", "event": "order_cancelled"}] @mock_sqs @@ -795,14 +809,12 @@ def test_filtering_exact_string_OR_matching(): ) messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match example_corp", "match different_corp"]) + assert message_bodies == ["match example_corp", "match different_corp"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - {"store": {"Type": "String", "Value": "example_corp"}}, - {"store": {"Type": "String", "Value": "different_corp"}}, - ] - ) + assert message_attributes == [ + {"store": {"Type": "String", "Value": "example_corp"}}, + {"store": {"Type": "String", "Value": "different_corp"}}, + ] @mock_sqs @@ -828,17 +840,15 @@ def test_filtering_exact_string_OR_matching_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - to_comparable_dicts(message_attributes).should.equal( - to_comparable_dicts( - [ - {"result": {"Type": "String", "Value": "match example_corp"}}, - {"result": {"Type": "String", "Value": "match different_corp"}}, - ] - ) + assert to_comparable_dicts(message_attributes) == to_comparable_dicts( + [ + {"result": {"Type": "String", "Value": "match example_corp"}}, + {"result": {"Type": "String", "Value": "match different_corp"}}, + ] ) message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"store": "example_corp"}, {"store": "different_corp"}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"store": "example_corp"}, {"store": "different_corp"}] ) @@ -859,16 +869,14 @@ def test_filtering_exact_string_AND_matching_positive(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match example_corp order_cancelled"]) + assert message_bodies == ["match example_corp order_cancelled"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "store": {"Type": "String", "Value": "example_corp"}, - "event": {"Type": "String", "Value": "order_cancelled"}, - } - ] - ) + assert message_attributes == [ + { + "store": {"Type": "String", "Value": "example_corp"}, + "event": {"Type": "String", "Value": "order_cancelled"}, + } + ] @mock_sqs @@ -891,18 +899,16 @@ def test_filtering_exact_string_AND_matching_positive_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": { - "Type": "String", - "Value": "match example_corp order_cancelled", - }, - } - ] - ) + assert message_attributes == [ + { + "result": { + "Type": "String", + "Value": "match example_corp order_cancelled", + }, + } + ] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"store": "example_corp", "event": "order_cancelled"}]) + assert message_bodies == [{"store": "example_corp", "event": "order_cancelled"}] @mock_sqs @@ -922,9 +928,9 @@ def test_filtering_exact_string_AND_matching_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -947,9 +953,9 @@ def test_filtering_exact_string_AND_matching_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -966,9 +972,9 @@ def test_filtering_exact_string_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -985,9 +991,9 @@ def test_filtering_exact_string_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -999,9 +1005,9 @@ def test_filtering_exact_string_no_attributes_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1018,9 +1024,9 @@ def test_filtering_exact_string_empty_body_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1035,9 +1041,9 @@ def test_filtering_exact_number_int(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"price": {"Type": "Number", "Value": "100"}}]) + assert message_attributes == [{"price": {"Type": "Number", "Value": "100"}}] @mock_sqs @@ -1054,15 +1060,13 @@ def test_filtering_exact_number_int_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [ + { + "result": {"Type": "String", "Value": "match"}, + } + ] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"price": 100}]) + assert message_bodies == [{"price": 100}] @mock_sqs @@ -1077,9 +1081,9 @@ def test_filtering_exact_number_float(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"price": {"Type": "Number", "Value": "100.1"}}]) + assert message_attributes == [{"price": {"Type": "Number", "Value": "100.1"}}] @mock_sqs @@ -1096,15 +1100,13 @@ def test_filtering_exact_number_float_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [ + { + "result": {"Type": "String", "Value": "match"}, + } + ] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"price": 100.1}]) + assert message_bodies == [{"price": 100.1}] @mock_sqs @@ -1121,11 +1123,9 @@ def test_filtering_exact_number_float_accuracy(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [{"price": {"Type": "Number", "Value": "100.1234567"}}] - ) + assert message_attributes == [{"price": {"Type": "Number", "Value": "100.1234567"}}] @mock_sqs @@ -1142,15 +1142,13 @@ def test_filtering_exact_number_float_accuracy_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [ + { + "result": {"Type": "String", "Value": "match"}, + } + ] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"price": 100.1234567}]) + assert message_bodies == [{"price": 100.1234567}] @mock_sqs @@ -1165,9 +1163,9 @@ def test_filtering_exact_number_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1184,9 +1182,9 @@ def test_filtering_exact_number_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1201,9 +1199,9 @@ def test_filtering_exact_number_with_string_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1220,9 +1218,9 @@ def test_filtering_exact_number_with_string_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1244,18 +1242,16 @@ def test_filtering_string_array_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "customer_interests": { - "Type": "String.Array", - "Value": json.dumps(["basketball", "rugby"]), - } + assert message_attributes == [ + { + "customer_interests": { + "Type": "String.Array", + "Value": json.dumps(["basketball", "rugby"]), } - ] - ) + } + ] @mock_sqs @@ -1273,15 +1269,13 @@ def test_filtering_string_array_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [ + { + "result": {"Type": "String", "Value": "match"}, + } + ] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"customer_interests": ["basketball", "rugby"]}]) + assert message_bodies == [{"customer_interests": ["basketball", "rugby"]}] @mock_sqs @@ -1301,9 +1295,9 @@ def test_filtering_string_array_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1320,9 +1314,9 @@ def test_filtering_string_array_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1339,11 +1333,11 @@ def test_filtering_string_array_with_number_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [{"price": {"Type": "String.Array", "Value": json.dumps([100, 50])}}] - ) + assert message_attributes == [ + {"price": {"Type": "String.Array", "Value": json.dumps([100, 50])}} + ] @mock_sqs @@ -1360,15 +1354,13 @@ def test_filtering_string_array_with_number_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [ + { + "result": {"Type": "String", "Value": "match"}, + } + ] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"price": [100, 50]}]) + assert message_bodies == [{"price": [100, 50]}] @mock_sqs @@ -1388,11 +1380,11 @@ def test_filtering_string_array_with_number_float_accuracy_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [{"price": {"Type": "String.Array", "Value": json.dumps([100.1234567, 50])}}] - ) + assert message_attributes == [ + {"price": {"Type": "String.Array", "Value": json.dumps([100.1234567, 50])}} + ] @mock_sqs @@ -1409,15 +1401,13 @@ def test_filtering_string_array_with_number_float_accuracy_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [ + { + "result": {"Type": "String", "Value": "match"}, + } + ] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"price": [100.1234567, 50]}]) + assert message_bodies == [{"price": [100.1234567, 50]}] @mock_sqs @@ -1433,11 +1423,9 @@ def test_filtering_string_array_with_number_no_array_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [{"price": {"Type": "String.Array", "Value": "100"}}] - ) + assert message_attributes == [{"price": {"Type": "String.Array", "Value": "100"}}] @mock_sqs @@ -1455,15 +1443,9 @@ def test_filtering_string_array_with_number_no_array_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [{"result": {"Type": "String", "Value": "match"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"price": 100}]) + assert message_bodies == [{"price": 100}] @mock_sqs @@ -1480,9 +1462,9 @@ def test_filtering_string_array_with_number_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1499,9 +1481,9 @@ def test_filtering_string_array_with_number_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1519,9 +1501,9 @@ def test_filtering_string_array_with_string_no_array_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1538,9 +1520,9 @@ def test_filtering_string_array_with_string_no_array_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1557,11 +1539,11 @@ def test_filtering_attribute_key_exists_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [{"store": {"Type": "String", "Value": "example_corp"}}] - ) + assert message_attributes == [ + {"store": {"Type": "String", "Value": "example_corp"}} + ] @mock_sqs @@ -1578,15 +1560,9 @@ def test_filtering_body_key_exists_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [{"result": {"Type": "String", "Value": "match"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"store": "example_corp"}]) + assert message_bodies == [{"store": "example_corp"}] @mock_sqs @@ -1603,9 +1579,9 @@ def test_filtering_attribute_key_exists_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1622,9 +1598,9 @@ def test_filtering_body_key_exists_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1641,11 +1617,11 @@ def test_filtering_attribute_key_not_exists_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [{"event": {"Type": "String", "Value": "order_cancelled"}}] - ) + assert message_attributes == [ + {"event": {"Type": "String", "Value": "order_cancelled"}} + ] @mock_sqs @@ -1662,15 +1638,9 @@ def test_filtering_body_key_not_exists_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [{"result": {"Type": "String", "Value": "match"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([{"event": "order_cancelled"}]) + assert message_bodies == [{"event": "order_cancelled"}] @mock_sqs @@ -1687,9 +1657,9 @@ def test_filtering_attribute_key_not_exists_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1706,9 +1676,9 @@ def test_filtering_body_key_not_exists_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1738,21 +1708,19 @@ def test_filtering_all_AND_matching_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal(["match"]) + assert message_bodies == ["match"] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "store": {"Type": "String", "Value": "example_corp"}, - "event": {"Type": "String", "Value": "order_cancelled"}, - "customer_interests": { - "Type": "String.Array", - "Value": json.dumps(["basketball", "rugby"]), - }, - "price": {"Type": "Number", "Value": "100"}, - } - ] - ) + assert message_attributes == [ + { + "store": {"Type": "String", "Value": "example_corp"}, + "event": {"Type": "String", "Value": "order_cancelled"}, + "customer_interests": { + "Type": "String.Array", + "Value": json.dumps(["basketball", "rugby"]), + }, + "price": {"Type": "Number", "Value": "100"}, + } + ] @mock_sqs @@ -1782,24 +1750,16 @@ def test_filtering_all_AND_matching_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal( - [ - { - "result": {"Type": "String", "Value": "match"}, - } - ] - ) + assert message_attributes == [{"result": {"Type": "String", "Value": "match"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal( - [ - { - "store": "example_corp", - "event": "order_cancelled", - "customer_interests": ["basketball", "rugby"], - "price": 100, - } - ] - ) + assert message_bodies == [ + { + "store": "example_corp", + "event": "order_cancelled", + "customer_interests": ["basketball", "rugby"], + "price": 100, + } + ] @mock_sqs @@ -1830,9 +1790,9 @@ def test_filtering_all_AND_matching_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -1863,9 +1823,9 @@ def test_filtering_all_AND_matching_no_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] @mock_sqs @@ -1885,7 +1845,7 @@ def test_filtering_prefix(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match1", "match3"}) + assert set(message_bodies) == {"match1", "match3"} @mock_sqs @@ -1909,10 +1869,8 @@ def test_filtering_prefix_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts( - [{"customer_interests": "basketball"}, {"customer_interests": "baseball"}] - ) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"customer_interests": "basketball"}, {"customer_interests": "baseball"}] ) @@ -1933,7 +1891,7 @@ def test_filtering_anything_but(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match2", "match3"}) + assert set(message_bodies) == {"match2", "match3"} @mock_sqs @@ -1957,10 +1915,8 @@ def test_filtering_anything_but_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts( - [{"customer_interests": "rugby"}, {"customer_interests": "baseball"}] - ) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"customer_interests": "rugby"}, {"customer_interests": "baseball"}] ) @@ -1981,7 +1937,7 @@ def test_filtering_anything_but_multiple_values(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match3"}) + assert set(message_bodies) == {"match3"} @mock_sqs @@ -2005,8 +1961,8 @@ def test_filtering_anything_but_multiple_values_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"customer_interests": "baseball"}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"customer_interests": "baseball"}] ) @@ -2028,7 +1984,7 @@ def test_filtering_anything_but_prefix(): # This should match rugby only messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match2"}) + assert set(message_bodies) == {"match2"} @mock_sqs @@ -2052,8 +2008,8 @@ def test_filtering_anything_but_prefix_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"customer_interests": "rugby"}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"customer_interests": "rugby"}] ) @@ -2065,7 +2021,7 @@ def test_filtering_anything_but_unknown(): {"customer_interests": [{"anything-but": {"unknown": "bas"}}]} ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameter") + assert err.response["Error"]["Code"] == "InvalidParameter" @mock_sqs @@ -2079,7 +2035,7 @@ def test_filtering_anything_but_unknown_message_body_raises(): filter_policy_scope="MessageBody", ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameter") + assert err.response["Error"]["Code"] == "InvalidParameter" @mock_sqs @@ -2099,7 +2055,7 @@ def test_filtering_anything_but_numeric(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match1", "match3"}) + assert set(message_bodies) == {"match1", "match3"} @mock_sqs @@ -2124,8 +2080,8 @@ def test_filtering_anything_but_numeric_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"customer_interests": 50}, {"customer_interests": 150}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"customer_interests": 50}, {"customer_interests": 150}] ) @@ -2146,7 +2102,7 @@ def test_filtering_anything_but_numeric_string(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match1", "match2", "match3"}) + assert set(message_bodies) == {"match1", "match2", "match3"} @mock_sqs @@ -2171,14 +2127,12 @@ def test_filtering_anything_but_numeric_string_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts( - [ - {"customer_interests": 50}, - {"customer_interests": 100}, - {"customer_interests": 150}, - ] - ) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [ + {"customer_interests": 50}, + {"customer_interests": 100}, + {"customer_interests": 150}, + ] ) @@ -2199,7 +2153,7 @@ def test_filtering_numeric_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match2"}) + assert set(message_bodies) == {"match2"} @mock_sqs @@ -2223,8 +2177,8 @@ def test_filtering_numeric_match_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"customer_interests": 100}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"customer_interests": 100}] ) @@ -2245,7 +2199,7 @@ def test_filtering_numeric_range(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - set(message_bodies).should.equal({"match1", "match2"}) + assert set(message_bodies) == {"match1", "match2"} @mock_sqs @@ -2269,8 +2223,8 @@ def test_filtering_numeric_range_message_body(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"customer_interests": 50}, {"customer_interests": 100}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"customer_interests": 50}, {"customer_interests": 100}] ) @@ -2288,9 +2242,9 @@ def test_filtering_exact_string_message_body_invalid_json_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -2305,12 +2259,12 @@ def test_filtering_exact_string_message_body_empty_filter_policy_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - to_comparable_dicts(message_attributes).should.equal( - to_comparable_dicts([{"match": {"Type": "String", "Value": "body"}}]) + assert to_comparable_dicts(message_attributes) == to_comparable_dicts( + [{"match": {"Type": "String", "Value": "body"}}] ) message_bodies = [json.loads(m.body)["Message"] for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"store": "another_corp"}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"store": "another_corp"}] ) @@ -2328,10 +2282,10 @@ def test_filtering_exact_string_message_body_nested(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"match": {"Type": "String", "Value": "body"}}]) + assert message_attributes == [{"match": {"Type": "String", "Value": "body"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"store": {"name": "example_corp"}}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"store": {"name": "example_corp"}}] ) @@ -2349,9 +2303,9 @@ def test_filtering_exact_string_message_body_nested_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -2369,10 +2323,10 @@ def test_filtering_message_body_nested_prefix(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"match": {"Type": "String", "Value": "body"}}]) + assert message_attributes == [{"match": {"Type": "String", "Value": "body"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - to_comparable_dicts(message_bodies).should.equal( - to_comparable_dicts([{"store": {"name": "example_corp"}}]) + assert to_comparable_dicts(message_bodies) == to_comparable_dicts( + [{"store": {"name": "example_corp"}}] ) @@ -2391,9 +2345,9 @@ def test_filtering_message_body_nested_prefix_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -2429,9 +2383,9 @@ def test_filtering_message_body_nested_multiple_prefix(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"match": {"Type": "String", "Value": "body"}}]) + assert message_attributes == [{"match": {"Type": "String", "Value": "body"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([payload]) + assert message_bodies == [payload] @mock_sqs @@ -2467,9 +2421,9 @@ def test_filtering_message_body_nested_multiple_prefix_no_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_bodies = [json.loads(m.body)["Message"] for m in messages] - message_bodies.should.equal([]) + assert message_bodies == [] message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([]) + assert message_attributes == [] @mock_sqs @@ -2502,9 +2456,9 @@ def test_filtering_message_body_nested_multiple_records_partial_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"match": {"Type": "String", "Value": "body"}}]) + assert message_attributes == [{"match": {"Type": "String", "Value": "body"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([payload]) + assert message_bodies == [payload] @mock_sqs @@ -2537,6 +2491,6 @@ def test_filtering_message_body_nested_multiple_records_match(): messages = queue.receive_messages(MaxNumberOfMessages=5) message_attributes = [json.loads(m.body)["MessageAttributes"] for m in messages] - message_attributes.should.equal([{"match": {"Type": "String", "Value": "body"}}]) + assert message_attributes == [{"match": {"Type": "String", "Value": "body"}}] message_bodies = [json.loads(json.loads(m.body)["Message"]) for m in messages] - message_bodies.should.equal([payload]) + assert message_bodies == [payload] diff --git a/tests/test_sns/test_server.py b/tests/test_sns/test_server.py index bba85538b..778e96b2a 100644 --- a/tests/test_sns/test_server.py +++ b/tests/test_sns/test_server.py @@ -1,26 +1,20 @@ +"""Test the different server responses.""" from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID - -import sure # noqa # pylint: disable=unused-import - import moto.server as server -""" -Test the different server responses -""" - def test_sns_server_get(): backend = server.create_backend_app("sns") test_client = backend.test_client() topic_data = test_client.action_data("CreateTopic", Name="testtopic") - topic_data.should.contain("CreateTopicResult") - topic_data.should.contain( + assert "CreateTopicResult" in topic_data + assert ( f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:testtopic" - ) + ) in topic_data topics_data = test_client.action_data("ListTopics") - topics_data.should.contain("ListTopicsResult") - topic_data.should.contain( + assert "ListTopicsResult" in topics_data + assert ( f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:testtopic" - ) + ) in topics_data diff --git a/tests/test_sns/test_sns_cloudformation.py b/tests/test_sns/test_sns_cloudformation.py index df8e1eb03..c1d6dbd03 100644 --- a/tests/test_sns/test_sns_cloudformation.py +++ b/tests/test_sns/test_sns_cloudformation.py @@ -1,6 +1,6 @@ -import boto3 import json -import sure # noqa # pylint: disable=unused-import + +import boto3 import pytest from moto import mock_cloudformation, mock_sns @@ -16,25 +16,25 @@ def test_sns_topic(): sns = boto3.client("sns", region_name="us-west-1") topics = sns.list_topics()["Topics"] - topics.should.have.length_of(1) + assert len(topics) == 1 topic_arn = topics[0]["TopicArn"] - topic_arn.should.contain("my_topics") + assert "my_topics" in topic_arn subscriptions = sns.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(1) + assert len(subscriptions) == 1 subscription = subscriptions[0] - subscription["TopicArn"].should.equal(topic_arn) - subscription["Protocol"].should.equal("https") - subscription["SubscriptionArn"].should.contain(topic_arn) - subscription["Endpoint"].should.equal("https://example.com") + assert subscription["TopicArn"] == topic_arn + assert subscription["Protocol"] == "https" + assert topic_arn in subscription["SubscriptionArn"] + assert subscription["Endpoint"] == "https://example.com" stack = cf.describe_stacks(StackName="test_stack")["Stacks"][0] topic_name_output = [x for x in stack["Outputs"] if x["OutputKey"] == "topic_name"][ 0 ] - topic_name_output["OutputValue"].should.equal("my_topics") + assert topic_name_output["OutputValue"] == "my_topics" topic_arn_output = [x for x in stack["Outputs"] if x["OutputKey"] == "topic_arn"][0] - topic_arn_output["OutputValue"].should.equal(topic_arn) + assert topic_arn_output["OutputValue"] == topic_arn @mock_cloudformation @@ -47,7 +47,7 @@ def test_sns_update_topic(): sns = boto3.client("sns", region_name="us-west-1") topics = sns.list_topics()["Topics"] - topics.should.have.length_of(1) + assert len(topics) == 1 dummy_template["Resources"]["MySNSTopic"]["Properties"]["Subscription"][0][ "Endpoint" @@ -56,17 +56,17 @@ def test_sns_update_topic(): cf.update_stack(StackName="test_stack", TemplateBody=sns_template_json) topics = sns.list_topics()["Topics"] - topics.should.have.length_of(1) + assert len(topics) == 1 topic_arn = topics[0]["TopicArn"] - topic_arn.should.contain("my_topics") + assert "my_topics" in topic_arn subscriptions = sns.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(1) + assert len(subscriptions) == 1 subscription = subscriptions[0] - subscription["TopicArn"].should.equal(topic_arn) - subscription["Protocol"].should.equal("https") - subscription["SubscriptionArn"].should.contain(topic_arn) - subscription["Endpoint"].should.equal("https://example-updated.com") + assert subscription["TopicArn"] == topic_arn + assert subscription["Protocol"] == "https" + assert topic_arn in subscription["SubscriptionArn"] + assert subscription["Endpoint"] == "https://example-updated.com" @mock_cloudformation @@ -80,7 +80,7 @@ def test_sns_update_remove_topic(with_properties): sns = boto3.client("sns", region_name="us-west-1") topics = sns.list_topics()["Topics"] - topics.should.have.length_of(1) + assert len(topics) == 1 dummy_template["Resources"].pop("MySNSTopic") dummy_template.pop("Outputs") @@ -88,7 +88,7 @@ def test_sns_update_remove_topic(with_properties): cf.update_stack(StackName="test_stack", TemplateBody=sns_template_json) topics = sns.list_topics()["Topics"] - topics.should.have.length_of(0) + assert len(topics) == 0 @mock_cloudformation @@ -101,12 +101,12 @@ def test_sns_delete_topic(with_properties): sns = boto3.client("sns", region_name="us-west-1") topics = sns.list_topics()["Topics"] - topics.should.have.length_of(1) + assert len(topics) == 1 cf.delete_stack(StackName="test_stack") topics = sns.list_topics()["Topics"] - topics.should.have.length_of(0) + assert len(topics) == 0 def get_template(with_properties): diff --git a/tests/test_sns/test_subscriptions_boto3.py b/tests/test_sns/test_subscriptions_boto3.py index 226ff2073..3b7ce9d0d 100644 --- a/tests/test_sns/test_subscriptions_boto3.py +++ b/tests/test_sns/test_subscriptions_boto3.py @@ -1,8 +1,6 @@ -import boto3 import json -import sure # noqa # pylint: disable=unused-import - +import boto3 from botocore.exceptions import ClientError import pytest @@ -22,10 +20,10 @@ def test_subscribe_sms(): arn = resp["TopicArn"] resp = client.subscribe(TopicArn=arn, Protocol="sms", Endpoint="+15551234567") - resp.should.have.key("SubscriptionArn") + assert "SubscriptionArn" in resp resp = client.subscribe(TopicArn=arn, Protocol="sms", Endpoint="+15/55-123.4567") - resp.should.have.key("SubscriptionArn") + assert "SubscriptionArn" in resp @mock_sns @@ -42,7 +40,7 @@ def test_double_subscription(): TopicArn=arn, Protocol="sqs", Endpoint="arn:aws:sqs:elasticmq:000000000000:foo" ) - resp1["SubscriptionArn"].should.equal(resp2["SubscriptionArn"]) + assert resp1["SubscriptionArn"] == resp2["SubscriptionArn"] @mock_sns @@ -56,19 +54,29 @@ def test_subscribe_bad_sms(): # Test invalid number client.subscribe(TopicArn=arn, Protocol="sms", Endpoint="NAA+15551234567") except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameter") + assert err.response["Error"]["Code"] == "InvalidParameter" - client.subscribe.when.called_with( - TopicArn=arn, Protocol="sms", Endpoint="+15--551234567" - ).should.throw(ClientError, "Invalid SMS endpoint: +15--551234567") + with pytest.raises(ClientError) as client_err: + client.subscribe(TopicArn=arn, Protocol="sms", Endpoint="+15--551234567") + assert ( + client_err.value.response["Error"]["Message"] + == "Invalid SMS endpoint: +15--551234567" + ) - client.subscribe.when.called_with( - TopicArn=arn, Protocol="sms", Endpoint="+15551234567." - ).should.throw(ClientError, "Invalid SMS endpoint: +15551234567.") + with pytest.raises(ClientError) as client_err: + client.subscribe(TopicArn=arn, Protocol="sms", Endpoint="+15551234567.") + assert ( + client_err.value.response["Error"]["Message"] + == "Invalid SMS endpoint: +15551234567." + ) - client.subscribe.when.called_with( - TopicArn=arn, Protocol="sms", Endpoint="/+15551234567" - ).should.throw(ClientError, "Invalid SMS endpoint: /+15551234567") + with pytest.raises(ClientError) as client_err: + assert client.subscribe(TopicArn=arn, Protocol="sms", Endpoint="/+15551234567") + + assert ( + client_err.value.response["Error"]["Message"] + == "Invalid SMS endpoint: /+15551234567" + ) @mock_sns @@ -81,19 +89,19 @@ def test_creating_subscription(): conn.subscribe(TopicArn=topic_arn, Protocol="http", Endpoint="http://example.com/") subscriptions = conn.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(1) + assert len(subscriptions) == 1 subscription = subscriptions[0] - subscription["TopicArn"].should.equal(topic_arn) - subscription["Protocol"].should.equal("http") - subscription["SubscriptionArn"].should.contain(topic_arn) - subscription["Endpoint"].should.equal("http://example.com/") + assert subscription["TopicArn"] == topic_arn + assert subscription["Protocol"] == "http" + assert topic_arn in subscription["SubscriptionArn"] + assert subscription["Endpoint"] == "http://example.com/" # Now unsubscribe the subscription conn.unsubscribe(SubscriptionArn=subscription["SubscriptionArn"]) # And there should be zero subscriptions left subscriptions = conn.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(0) + assert len(subscriptions) == 0 @mock_sns @@ -108,13 +116,13 @@ def test_unsubscribe_from_deleted_topic(): ) subscriptions = client.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(1) + assert len(subscriptions) == 1 subscription = subscriptions[0] subscription_arn = subscription["SubscriptionArn"] - subscription["TopicArn"].should.equal(topic_arn) - subscription["Protocol"].should.equal("http") - subscription_arn.should.contain(topic_arn) - subscription["Endpoint"].should.equal("http://example.com/") + assert subscription["TopicArn"] == topic_arn + assert subscription["Protocol"] == "http" + assert topic_arn in subscription_arn + assert subscription["Endpoint"] == "http://example.com/" # Now delete the topic client.delete_topic(TopicArn=topic_arn) @@ -122,17 +130,17 @@ def test_unsubscribe_from_deleted_topic(): # And there should now be 0 topics topics_json = client.list_topics() topics = topics_json["Topics"] - topics.should.have.length_of(0) + assert len(topics) == 0 # as per the documentation deleting a topic deletes all the subscriptions subscriptions = client.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(0) + assert len(subscriptions) == 0 # Now delete hanging subscription client.unsubscribe(SubscriptionArn=subscription_arn) subscriptions = client.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(0) + assert len(subscriptions) == 0 # Deleting it again should not result in any error client.unsubscribe(SubscriptionArn=subscription_arn) @@ -159,8 +167,8 @@ def test_getting_subscriptions_by_topic(): topic1_subscriptions = conn.list_subscriptions_by_topic(TopicArn=topic1_arn)[ "Subscriptions" ] - topic1_subscriptions.should.have.length_of(1) - topic1_subscriptions[0]["Endpoint"].should.equal("http://example1.com/") + assert len(topic1_subscriptions) == 1 + assert topic1_subscriptions[0]["Endpoint"] == "http://example1.com/" @mock_sns @@ -180,26 +188,24 @@ def test_subscription_paging(): ) all_subscriptions = conn.list_subscriptions() - all_subscriptions["Subscriptions"].should.have.length_of(DEFAULT_PAGE_SIZE) + assert len(all_subscriptions["Subscriptions"]) == DEFAULT_PAGE_SIZE next_token = all_subscriptions["NextToken"] - next_token.should.equal(str(DEFAULT_PAGE_SIZE)) + assert next_token == str(DEFAULT_PAGE_SIZE) all_subscriptions = conn.list_subscriptions(NextToken=next_token) - all_subscriptions["Subscriptions"].should.have.length_of(int(DEFAULT_PAGE_SIZE / 3)) - all_subscriptions.shouldnt.have("NextToken") + assert len(all_subscriptions["Subscriptions"]) == int(DEFAULT_PAGE_SIZE / 3) + assert "NextToken" not in all_subscriptions topic1_subscriptions = conn.list_subscriptions_by_topic(TopicArn=topic1_arn) - topic1_subscriptions["Subscriptions"].should.have.length_of(DEFAULT_PAGE_SIZE) + assert len(topic1_subscriptions["Subscriptions"]) == DEFAULT_PAGE_SIZE next_token = topic1_subscriptions["NextToken"] - next_token.should.equal(str(DEFAULT_PAGE_SIZE)) + assert next_token == str(DEFAULT_PAGE_SIZE) topic1_subscriptions = conn.list_subscriptions_by_topic( TopicArn=topic1_arn, NextToken=next_token ) - topic1_subscriptions["Subscriptions"].should.have.length_of( - int(DEFAULT_PAGE_SIZE / 3) - ) - topic1_subscriptions.shouldnt.have("NextToken") + assert len(topic1_subscriptions["Subscriptions"]) == int(DEFAULT_PAGE_SIZE / 3) + assert "NextToken" not in topic1_subscriptions @mock_sns @@ -215,17 +221,17 @@ def test_subscribe_attributes(): SubscriptionArn=resp["SubscriptionArn"] ) - response.should.contain("Attributes") + assert "Attributes" in response attributes = response["Attributes"] - attributes["PendingConfirmation"].should.equal("false") - attributes["ConfirmationWasAuthenticated"].should.equal("true") - attributes["Endpoint"].should.equal("http://test.com") - attributes["TopicArn"].should.equal(arn) - attributes["Protocol"].should.equal("http") - attributes["SubscriptionArn"].should.equal(resp["SubscriptionArn"]) - attributes["Owner"].should.equal(str(ACCOUNT_ID)) - attributes["RawMessageDelivery"].should.equal("false") - json.loads(attributes["EffectiveDeliveryPolicy"]).should.equal( + assert attributes["PendingConfirmation"] == "false" + assert attributes["ConfirmationWasAuthenticated"] == "true" + assert attributes["Endpoint"] == "http://test.com" + assert attributes["TopicArn"] == arn + assert attributes["Protocol"] == "http" + assert attributes["SubscriptionArn"] == resp["SubscriptionArn"] + assert attributes["Owner"] == str(ACCOUNT_ID) + assert attributes["RawMessageDelivery"] == "false" + assert json.loads(attributes["EffectiveDeliveryPolicy"]) == ( DEFAULT_EFFECTIVE_DELIVERY_POLICY ) @@ -272,28 +278,28 @@ def test_creating_subscription_with_attributes(): ) subscriptions = conn.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(1) + assert len(subscriptions) == 1 subscription = subscriptions[0] - subscription["TopicArn"].should.equal(topic_arn) - subscription["Protocol"].should.equal("http") - subscription["SubscriptionArn"].should.contain(topic_arn) - subscription["Endpoint"].should.equal("http://example.com/") + assert subscription["TopicArn"] == topic_arn + assert subscription["Protocol"] == "http" + assert topic_arn in subscription["SubscriptionArn"] + assert subscription["Endpoint"] == "http://example.com/" # Test the subscription attributes have been set subscription_arn = subscription["SubscriptionArn"] attrs = conn.get_subscription_attributes(SubscriptionArn=subscription_arn) - attrs["Attributes"]["RawMessageDelivery"].should.equal("true") - attrs["Attributes"]["DeliveryPolicy"].should.equal(delivery_policy) - attrs["Attributes"]["FilterPolicy"].should.equal(filter_policy) - attrs["Attributes"]["SubscriptionRoleArn"].should.equal(subscription_role_arn) + assert attrs["Attributes"]["RawMessageDelivery"] == "true" + assert attrs["Attributes"]["DeliveryPolicy"] == delivery_policy + assert attrs["Attributes"]["FilterPolicy"] == filter_policy + assert attrs["Attributes"]["SubscriptionRoleArn"] == subscription_role_arn # Now unsubscribe the subscription conn.unsubscribe(SubscriptionArn=subscription["SubscriptionArn"]) # And there should be zero subscriptions left subscriptions = conn.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(0) + assert len(subscriptions) == 0 # invalid attr name with pytest.raises(ClientError): @@ -319,12 +325,12 @@ def test_delete_subscriptions_on_delete_topic(): ) subscriptions = conn.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(1) + assert len(subscriptions) == 1 conn.delete_topic(TopicArn=topic.get("TopicArn")) subscriptions = conn.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(0) + assert len(subscriptions) == 0 @mock_sns @@ -337,16 +343,16 @@ def test_set_subscription_attributes(): conn.subscribe(TopicArn=topic_arn, Protocol="http", Endpoint="http://example.com/") subscriptions = conn.list_subscriptions()["Subscriptions"] - subscriptions.should.have.length_of(1) + assert len(subscriptions) == 1 subscription = subscriptions[0] - subscription["TopicArn"].should.equal(topic_arn) - subscription["Protocol"].should.equal("http") - subscription["SubscriptionArn"].should.contain(topic_arn) - subscription["Endpoint"].should.equal("http://example.com/") + assert subscription["TopicArn"] == topic_arn + assert subscription["Protocol"] == "http" + assert topic_arn in subscription["SubscriptionArn"] + assert subscription["Endpoint"] == "http://example.com/" subscription_arn = subscription["SubscriptionArn"] attrs = conn.get_subscription_attributes(SubscriptionArn=subscription_arn) - attrs.should.have.key("Attributes") + assert "Attributes" in attrs conn.set_subscription_attributes( SubscriptionArn=subscription_arn, AttributeName="RawMessageDelivery", @@ -384,9 +390,9 @@ def test_set_subscription_attributes(): attrs = conn.get_subscription_attributes(SubscriptionArn=subscription_arn) - attrs["Attributes"]["RawMessageDelivery"].should.equal("true") - attrs["Attributes"]["DeliveryPolicy"].should.equal(delivery_policy) - attrs["Attributes"]["FilterPolicy"].should.equal(filter_policy) + assert attrs["Attributes"]["RawMessageDelivery"] == "true" + assert attrs["Attributes"]["DeliveryPolicy"] == delivery_policy + assert attrs["Attributes"]["FilterPolicy"] == filter_policy filter_policy_scope = "MessageBody" conn.set_subscription_attributes( @@ -397,7 +403,7 @@ def test_set_subscription_attributes(): attrs = conn.get_subscription_attributes(SubscriptionArn=subscription_arn) - attrs["Attributes"]["FilterPolicyScope"].should.equal(filter_policy_scope) + assert attrs["Attributes"]["FilterPolicyScope"] == filter_policy_scope # not existing subscription with pytest.raises(ClientError): @@ -436,8 +442,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: FilterPolicy: Filter policy is too complex" ) @@ -450,8 +456,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: FilterPolicy: Match value must be String, number, true, false, or null" ) @@ -464,8 +470,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: FilterPolicy: exists match pattern must be either true or false." ) @@ -478,8 +484,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: FilterPolicy: Unrecognized match type error" ) @@ -492,7 +498,7 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InternalFailure") + assert err.response["Error"]["Code"] == "InternalFailure" with pytest.raises(ClientError) as err_info: conn.subscribe( @@ -505,8 +511,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: Attributes Reason: FilterPolicy: Value of < must be numeric\n at ..." ) @@ -523,8 +529,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: Attributes Reason: FilterPolicy: Value of <= must be numeric\n at ..." ) @@ -537,9 +543,10 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( - "Invalid parameter: Attributes Reason: FilterPolicy: Invalid member in numeric match: ]\n at ..." + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( + "Invalid parameter: Attributes Reason: FilterPolicy: " + "Invalid member in numeric match: ]\n at ..." ) with pytest.raises(ClientError) as err_info: @@ -553,9 +560,10 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( - "Invalid parameter: Attributes Reason: FilterPolicy: Invalid member in numeric match: 50\n at ..." + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( + "Invalid parameter: Attributes Reason: FilterPolicy: Invalid " + "member in numeric match: 50\n at ..." ) with pytest.raises(ClientError) as err_info: @@ -567,8 +575,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: Attributes Reason: FilterPolicy: Value of < must be numeric\n at ..." ) @@ -581,9 +589,10 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( - "Invalid parameter: Attributes Reason: FilterPolicy: Unrecognized numeric range operator: 0\n at ..." + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( + "Invalid parameter: Attributes Reason: FilterPolicy: " + "Unrecognized numeric range operator: 0\n at ..." ) with pytest.raises(ClientError) as err_info: @@ -597,9 +606,10 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( - "Invalid parameter: Attributes Reason: FilterPolicy: Too many elements in numeric expression\n at ..." + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( + "Invalid parameter: Attributes Reason: FilterPolicy: Too many " + "elements in numeric expression\n at ..." ) with pytest.raises(ClientError) as err_info: @@ -613,8 +623,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: Attributes Reason: FilterPolicy: Bad numeric range operator: >\n at ..." ) @@ -629,8 +639,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: Attributes Reason: FilterPolicy: Bottom must be less than top\n at ..." ) @@ -645,8 +655,8 @@ def test_subscribe_invalid_filter_policy(): ) err = err_info.value - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: Attributes Reason: FilterPolicy: Value of < must be numeric\n at ..." ) @@ -660,9 +670,10 @@ def test_subscribe_invalid_filter_policy(): }, ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( - "Invalid parameter: Filter policy scope MessageAttributes does not support nested filter policy" + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( + "Invalid parameter: Filter policy scope MessageAttributes does " + "not support nested filter policy" ) try: @@ -681,8 +692,8 @@ def test_subscribe_invalid_filter_policy(): Attributes={"FilterPolicy": json.dumps(filter_policy)}, ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: FilterPolicy: Filter policy can not have more than 5 keys" ) @@ -696,8 +707,9 @@ def test_subscribe_invalid_filter_policy(): "key_d": {"key_e": ["value_one", "value_two", "value_three"]}, "key_f": ["value_one", "value_two", "value_three"], } - # The first array has four values in a three-level nested key, and the second has three values in a two-level - # nested key. The total combination is calculated as follows: + # The first array has four values in a three-level nested key, + # and the second has three values in a two-level nested key. The + # total combination is calculated as follows: # 3 x 4 x 2 x 3 x 1 x 3 = 216 conn.subscribe( TopicArn=topic_arn, @@ -709,8 +721,8 @@ def test_subscribe_invalid_filter_policy(): }, ) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameter") - err.response["Error"]["Message"].should.equal( + assert err.response["Error"]["Code"] == "InvalidParameter" + assert err.response["Error"]["Message"] == ( "Invalid parameter: FilterPolicy: Filter policy is too complex" ) @@ -720,8 +732,8 @@ def test_check_not_opted_out(): conn = boto3.client("sns", region_name="us-east-1") response = conn.check_if_phone_number_is_opted_out(phoneNumber="+447428545375") - response.should.contain("isOptedOut") - response["isOptedOut"].should.be(False) + assert "isOptedOut" in response + assert response["isOptedOut"] is False @mock_sns @@ -731,8 +743,8 @@ def test_check_opted_out(): conn = boto3.client("sns", region_name="us-east-1") response = conn.check_if_phone_number_is_opted_out(phoneNumber="+447428545399") - response.should.contain("isOptedOut") - response["isOptedOut"].should.be(True) + assert "isOptedOut" in response + assert response["isOptedOut"] is True @mock_sns @@ -749,8 +761,8 @@ def test_list_opted_out(): conn = boto3.client("sns", region_name="us-east-1") response = conn.list_phone_numbers_opted_out() - response.should.contain("phoneNumbers") - len(response["phoneNumbers"]).should.be.greater_than(0) + assert "phoneNumbers" in response + assert len(response["phoneNumbers"]) > 0 @mock_sns @@ -763,8 +775,8 @@ def test_opt_in(): conn.opt_in_phone_number(phoneNumber=response["phoneNumbers"][0]) response = conn.list_phone_numbers_opted_out() - len(response["phoneNumbers"]).should.be.greater_than(0) - len(response["phoneNumbers"]).should.be.lower_than(current_len) + assert len(response["phoneNumbers"]) > 0 + assert len(response["phoneNumbers"]) < current_len @mock_sns @@ -774,7 +786,12 @@ def test_confirm_subscription(): conn.confirm_subscription( TopicArn=response["TopicArn"], - Token="2336412f37fb687f5d51e6e241d59b68c4e583a5cee0be6f95bbf97ab8d2441cf47b99e848408adaadf4c197e65f03473d53c4ba398f6abbf38ce2e8ebf7b4ceceb2cd817959bcde1357e58a2861b05288c535822eb88cac3db04f592285249971efc6484194fc4a4586147f16916692", + Token=( + "2336412f37fb687f5d51e6e241d59b68c4e583a5cee0be6f95bbf97ab8d" + "2441cf47b99e848408adaadf4c197e65f03473d53c4ba398f6abbf38ce2" + "e8ebf7b4ceceb2cd817959bcde1357e58a2861b05288c535822eb88cac3" + "db04f592285249971efc6484194fc4a4586147f16916692" + ), AuthenticateOnUnsubscribe="true", ) @@ -783,15 +800,18 @@ def test_confirm_subscription(): def test_get_subscription_attributes_error_not_exists(): # given client = boto3.client("sns", region_name="us-east-1") - sub_arn = f"arn:aws:sqs:us-east-1:{ACCOUNT_ID}:test-queue:66d97e76-31e5-444f-8fa7-b60b680d0d39" + sub_arn = ( + f"arn:aws:sqs:us-east-1:{ACCOUNT_ID}:test-queue" + ":66d97e76-31e5-444f-8fa7-b60b680d0d39" + ) # when - with pytest.raises(ClientError) as e: + with pytest.raises(ClientError) as exc: client.get_subscription_attributes(SubscriptionArn=sub_arn) # then - ex = e.value - ex.operation_name.should.equal("GetSubscriptionAttributes") - ex.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(404) - ex.response["Error"]["Code"].should.contain("NotFound") - ex.response["Error"]["Message"].should.equal("Subscription does not exist") + exc_value = exc.value + assert exc_value.operation_name == "GetSubscriptionAttributes" + assert exc_value.response["ResponseMetadata"]["HTTPStatusCode"] == 404 + assert "NotFound" in exc_value.response["Error"]["Code"] + assert exc_value.response["Error"]["Message"] == "Subscription does not exist" diff --git a/tests/test_sns/test_topics_boto3.py b/tests/test_sns/test_topics_boto3.py index cb99afb4a..35fe4ffdd 100644 --- a/tests/test_sns/test_topics_boto3.py +++ b/tests/test_sns/test_topics_boto3.py @@ -1,13 +1,11 @@ -import boto3 import json -import pytest - -import sure # noqa # pylint: disable=unused-import +import boto3 from botocore.exceptions import ClientError from moto import mock_sns from moto.sns.models import DEFAULT_EFFECTIVE_DELIVERY_POLICY, DEFAULT_PAGE_SIZE from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID +import pytest @mock_sns @@ -18,8 +16,8 @@ def test_create_and_delete_topic(): topics_json = conn.list_topics() topics = topics_json["Topics"] - topics.should.have.length_of(1) - topics[0]["TopicArn"].should.equal( + assert len(topics) == 1 + assert topics[0]["TopicArn"] == ( f"arn:aws:sns:{conn._client_config.region_name}:{ACCOUNT_ID}:{topic_name}" ) @@ -32,7 +30,7 @@ def test_create_and_delete_topic(): # And there should now be 0 topics topics_json = conn.list_topics() topics = topics_json["Topics"] - topics.should.have.length_of(0) + assert len(topics) == 0 @mock_sns @@ -55,7 +53,7 @@ def test_create_topic_with_attributes(): topic_arn = topics_json["Topics"][0]["TopicArn"] attributes = conn.get_topic_attributes(TopicArn=topic_arn)["Attributes"] - attributes["DisplayName"].should.equal("test-topic") + assert attributes["DisplayName"] == "test-topic" @mock_sns @@ -70,7 +68,7 @@ def test_create_topic_with_tags(): ) topic_arn = response["TopicArn"] - conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"].should.equal( + assert conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"] == ( [ {"Key": "tag_key_1", "Value": "tag_value_1"}, {"Key": "tag_key_2", "Value": "tag_value_2"}, @@ -88,22 +86,23 @@ def test_create_topic_should_be_indempodent(): topic_display_name = conn.get_topic_attributes(TopicArn=topic_arn)["Attributes"][ "DisplayName" ] - topic_display_name.should.be.equal("should_be_set") + assert topic_display_name == "should_be_set" # recreate topic to prove indempodentcy topic_arn = conn.create_topic(Name="some-topic")["TopicArn"] topic_display_name = conn.get_topic_attributes(TopicArn=topic_arn)["Attributes"][ "DisplayName" ] - topic_display_name.should.be.equal("should_be_set") + assert topic_display_name == "should_be_set" @mock_sns def test_get_missing_topic(): conn = boto3.client("sns", region_name="us-east-1") - conn.get_topic_attributes.when.called_with( - TopicArn="arn:aws:sns:us-east-1:424242424242:a-fake-arn" - ).should.throw(ClientError) + with pytest.raises(ClientError): + conn.get_topic_attributes( + TopicArn="arn:aws:sns:us-east-1:424242424242:a-fake-arn" + ) @mock_sns @@ -111,21 +110,21 @@ def test_create_topic_must_meet_constraints(): conn = boto3.client("sns", region_name="us-east-1") common_random_chars = [":", ";", "!", "@", "|", "^", "%"] for char in common_random_chars: - conn.create_topic.when.called_with(Name=f"no{char}_invalidchar").should.throw( - ClientError - ) - conn.create_topic.when.called_with(Name="no spaces allowed").should.throw( - ClientError - ) + with pytest.raises(ClientError): + conn.create_topic(Name=f"no{char}_invalidchar") + with pytest.raises(ClientError): + conn.create_topic(Name="no spaces allowed") @mock_sns def test_create_topic_should_be_of_certain_length(): conn = boto3.client("sns", region_name="us-east-1") too_short = "" - conn.create_topic.when.called_with(Name=too_short).should.throw(ClientError) + with pytest.raises(ClientError): + conn.create_topic(Name=too_short) too_long = "x" * 257 - conn.create_topic.when.called_with(Name=too_long).should.throw(ClientError) + with pytest.raises(ClientError): + conn.create_topic(Name=too_long) @mock_sns @@ -134,7 +133,7 @@ def test_create_topic_in_multiple_regions(): conn = boto3.client("sns", region_name=region) topic_arn = conn.create_topic(Name="some-topic")["TopicArn"] # We can find the topic - list(conn.list_topics()["Topics"]).should.have.length_of(1) + assert len(list(conn.list_topics()["Topics"])) == 1 # We can read the Topic details topic = boto3.resource("sns", region_name=region).Topic(topic_arn) @@ -158,7 +157,7 @@ def test_topic_corresponds_to_region(): conn.create_topic(Name="some-topic") topics_json = conn.list_topics() topic_arn = topics_json["Topics"][0]["TopicArn"] - topic_arn.should.equal(f"arn:aws:sns:{region}:{ACCOUNT_ID}:some-topic") + assert topic_arn == f"arn:aws:sns:{region}:{ACCOUNT_ID}:some-topic" @mock_sns @@ -170,42 +169,40 @@ def test_topic_attributes(): topic_arn = topics_json["Topics"][0]["TopicArn"] attributes = conn.get_topic_attributes(TopicArn=topic_arn)["Attributes"] - attributes["TopicArn"].should.equal( + assert attributes["TopicArn"] == ( f"arn:aws:sns:{conn._client_config.region_name}:{ACCOUNT_ID}:some-topic" ) - attributes["Owner"].should.equal(ACCOUNT_ID) - json.loads(attributes["Policy"]).should.equal( - { - "Version": "2008-10-17", - "Id": "__default_policy_ID", - "Statement": [ - { - "Effect": "Allow", - "Sid": "__default_statement_ID", - "Principal": {"AWS": "*"}, - "Action": [ - "SNS:GetTopicAttributes", - "SNS:SetTopicAttributes", - "SNS:AddPermission", - "SNS:RemovePermission", - "SNS:DeleteTopic", - "SNS:Subscribe", - "SNS:ListSubscriptionsByTopic", - "SNS:Publish", - "SNS:Receive", - ], - "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:some-topic", - "Condition": {"StringEquals": {"AWS:SourceOwner": ACCOUNT_ID}}, - } - ], - } - ) - attributes["DisplayName"].should.equal("") - attributes["SubscriptionsPending"].should.equal("0") - attributes["SubscriptionsConfirmed"].should.equal("0") - attributes["SubscriptionsDeleted"].should.equal("0") - attributes["DeliveryPolicy"].should.equal("") - json.loads(attributes["EffectiveDeliveryPolicy"]).should.equal( + assert attributes["Owner"] == ACCOUNT_ID + assert json.loads(attributes["Policy"]) == { + "Version": "2008-10-17", + "Id": "__default_policy_ID", + "Statement": [ + { + "Effect": "Allow", + "Sid": "__default_statement_ID", + "Principal": {"AWS": "*"}, + "Action": [ + "SNS:GetTopicAttributes", + "SNS:SetTopicAttributes", + "SNS:AddPermission", + "SNS:RemovePermission", + "SNS:DeleteTopic", + "SNS:Subscribe", + "SNS:ListSubscriptionsByTopic", + "SNS:Publish", + "SNS:Receive", + ], + "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:some-topic", + "Condition": {"StringEquals": {"AWS:SourceOwner": ACCOUNT_ID}}, + } + ], + } + assert attributes["DisplayName"] == "" + assert attributes["SubscriptionsPending"] == "0" + assert attributes["SubscriptionsConfirmed"] == "0" + assert attributes["SubscriptionsDeleted"] == "0" + assert attributes["DeliveryPolicy"] == "" + assert json.loads(attributes["EffectiveDeliveryPolicy"]) == ( DEFAULT_EFFECTIVE_DELIVERY_POLICY ) @@ -226,9 +223,9 @@ def test_topic_attributes(): ) attributes = conn.get_topic_attributes(TopicArn=topic_arn)["Attributes"] - attributes["Policy"].should.equal('{"foo":"bar"}') - attributes["DisplayName"].should.equal("My display name") - attributes["DeliveryPolicy"].should.equal( + assert attributes["Policy"] == '{"foo":"bar"}' + assert attributes["DisplayName"] == "My display name" + assert attributes["DeliveryPolicy"] == ( '{"http": {"defaultHealthyRetryPolicy": {"numRetries": 5}}}' ) @@ -243,14 +240,14 @@ def test_topic_paging(): topics_list = response["Topics"] next_token = response["NextToken"] - len(topics_list).should.equal(DEFAULT_PAGE_SIZE) - int(next_token).should.equal(DEFAULT_PAGE_SIZE) + assert len(topics_list) == DEFAULT_PAGE_SIZE + assert int(next_token) == DEFAULT_PAGE_SIZE response = conn.list_topics(NextToken=next_token) topics_list = response["Topics"] - response.shouldnt.have("NextToken") + assert "NextToken" not in response - topics_list.should.have.length_of(int(DEFAULT_PAGE_SIZE / 2)) + assert len(topics_list) == int(DEFAULT_PAGE_SIZE / 2) @mock_sns @@ -266,69 +263,65 @@ def test_add_remove_permissions(): ) response = client.get_topic_attributes(TopicArn=topic_arn) - json.loads(response["Attributes"]["Policy"]).should.equal( - { - "Version": "2008-10-17", - "Id": "__default_policy_ID", - "Statement": [ - { - "Effect": "Allow", - "Sid": "__default_statement_ID", - "Principal": {"AWS": "*"}, - "Action": [ - "SNS:GetTopicAttributes", - "SNS:SetTopicAttributes", - "SNS:AddPermission", - "SNS:RemovePermission", - "SNS:DeleteTopic", - "SNS:Subscribe", - "SNS:ListSubscriptionsByTopic", - "SNS:Publish", - "SNS:Receive", - ], - "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", - "Condition": {"StringEquals": {"AWS:SourceOwner": ACCOUNT_ID}}, - }, - { - "Sid": "test", - "Effect": "Allow", - "Principal": {"AWS": "arn:aws:iam::999999999999:root"}, - "Action": "SNS:Publish", - "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", - }, - ], - } - ) + assert json.loads(response["Attributes"]["Policy"]) == { + "Version": "2008-10-17", + "Id": "__default_policy_ID", + "Statement": [ + { + "Effect": "Allow", + "Sid": "__default_statement_ID", + "Principal": {"AWS": "*"}, + "Action": [ + "SNS:GetTopicAttributes", + "SNS:SetTopicAttributes", + "SNS:AddPermission", + "SNS:RemovePermission", + "SNS:DeleteTopic", + "SNS:Subscribe", + "SNS:ListSubscriptionsByTopic", + "SNS:Publish", + "SNS:Receive", + ], + "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", + "Condition": {"StringEquals": {"AWS:SourceOwner": ACCOUNT_ID}}, + }, + { + "Sid": "test", + "Effect": "Allow", + "Principal": {"AWS": "arn:aws:iam::999999999999:root"}, + "Action": "SNS:Publish", + "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", + }, + ], + } client.remove_permission(TopicArn=topic_arn, Label="test") response = client.get_topic_attributes(TopicArn=topic_arn) - json.loads(response["Attributes"]["Policy"]).should.equal( - { - "Version": "2008-10-17", - "Id": "__default_policy_ID", - "Statement": [ - { - "Effect": "Allow", - "Sid": "__default_statement_ID", - "Principal": {"AWS": "*"}, - "Action": [ - "SNS:GetTopicAttributes", - "SNS:SetTopicAttributes", - "SNS:AddPermission", - "SNS:RemovePermission", - "SNS:DeleteTopic", - "SNS:Subscribe", - "SNS:ListSubscriptionsByTopic", - "SNS:Publish", - "SNS:Receive", - ], - "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", - "Condition": {"StringEquals": {"AWS:SourceOwner": ACCOUNT_ID}}, - } - ], - } - ) + assert json.loads(response["Attributes"]["Policy"]) == { + "Version": "2008-10-17", + "Id": "__default_policy_ID", + "Statement": [ + { + "Effect": "Allow", + "Sid": "__default_statement_ID", + "Principal": {"AWS": "*"}, + "Action": [ + "SNS:GetTopicAttributes", + "SNS:SetTopicAttributes", + "SNS:AddPermission", + "SNS:RemovePermission", + "SNS:DeleteTopic", + "SNS:Subscribe", + "SNS:ListSubscriptionsByTopic", + "SNS:Publish", + "SNS:Receive", + ], + "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", + "Condition": {"StringEquals": {"AWS:SourceOwner": ACCOUNT_ID}}, + } + ], + } client.add_permission( TopicArn=topic_arn, @@ -338,20 +331,18 @@ def test_add_remove_permissions(): ) response = client.get_topic_attributes(TopicArn=topic_arn) - json.loads(response["Attributes"]["Policy"])["Statement"][1].should.equal( - { - "Sid": "test", - "Effect": "Allow", - "Principal": { - "AWS": [ - "arn:aws:iam::888888888888:root", - "arn:aws:iam::999999999999:root", - ] - }, - "Action": ["SNS:Publish", "SNS:Subscribe"], - "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", - } - ) + assert json.loads(response["Attributes"]["Policy"])["Statement"][1] == { + "Sid": "test", + "Effect": "Allow", + "Principal": { + "AWS": [ + "arn:aws:iam::888888888888:root", + "arn:aws:iam::999999999999:root", + ] + }, + "Action": ["SNS:Publish", "SNS:Subscribe"], + "Resource": f"arn:aws:sns:us-east-1:{ACCOUNT_ID}:test-permissions", + } # deleting non existing permission should be successful client.remove_permission(TopicArn=topic_arn, Label="non-existing") @@ -368,30 +359,36 @@ def test_add_permission_errors(): ActionName=["Publish"], ) - client.add_permission.when.called_with( - TopicArn=topic_arn, - Label="test", - AWSAccountId=["999999999999"], - ActionName=["AddPermission"], - ).should.throw(ClientError, "Statement already exists") + with pytest.raises(ClientError) as client_err: + client.add_permission( + TopicArn=topic_arn, + Label="test", + AWSAccountId=["999999999999"], + ActionName=["AddPermission"], + ) + assert client_err.value.response["Error"]["Message"] == "Statement already exists" - client.add_permission.when.called_with( - TopicArn=topic_arn + "-not-existing", - Label="test-2", - AWSAccountId=["999999999999"], - ActionName=["AddPermission"], - ).should.throw( - ClientError, - "An error occurred (NotFound) when calling the AddPermission operation: Topic does not exist", + with pytest.raises(ClientError) as client_err: + client.add_permission( + TopicArn=topic_arn + "-not-existing", + Label="test-2", + AWSAccountId=["999999999999"], + ActionName=["AddPermission"], + ) + assert client_err.value.response["Error"]["Code"] == "NotFound" + assert client_err.value.response["Error"]["Message"] == "Topic does not exist" + + with pytest.raises(ClientError) as client_err: + client.add_permission( + TopicArn=topic_arn, + Label="test-2", + AWSAccountId=["999999999999"], + ActionName=["NotExistingAction"], + ) + assert client_err.value.response["Error"]["Message"] == ( + "Policy statement action out of service scope!" ) - client.add_permission.when.called_with( - TopicArn=topic_arn, - Label="test-2", - AWSAccountId=["999999999999"], - ActionName=["NotExistingAction"], - ).should.throw(ClientError, "Policy statement action out of service scope!") - @mock_sns def test_remove_permission_errors(): @@ -404,12 +401,11 @@ def test_remove_permission_errors(): ActionName=["Publish"], ) - client.remove_permission.when.called_with( - TopicArn=topic_arn + "-not-existing", Label="test" - ).should.throw( - ClientError, - "An error occurred (NotFound) when calling the RemovePermission operation: Topic does not exist", - ) + with pytest.raises(ClientError) as client_err: + client.remove_permission(TopicArn=topic_arn + "-not-existing", Label="test") + + assert client_err.value.response["Error"]["Code"] == "NotFound" + assert client_err.value.response["Error"]["Message"] == "Topic does not exist" @mock_sns @@ -421,14 +417,14 @@ def test_tag_topic(): conn.tag_resource( ResourceArn=topic_arn, Tags=[{"Key": "tag_key_1", "Value": "tag_value_1"}] ) - conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"].should.equal( + assert conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"] == ( [{"Key": "tag_key_1", "Value": "tag_value_1"}] ) conn.tag_resource( ResourceArn=topic_arn, Tags=[{"Key": "tag_key_2", "Value": "tag_value_2"}] ) - conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"].should.equal( + assert conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"] == ( [ {"Key": "tag_key_1", "Value": "tag_value_1"}, {"Key": "tag_key_2", "Value": "tag_value_2"}, @@ -438,7 +434,7 @@ def test_tag_topic(): conn.tag_resource( ResourceArn=topic_arn, Tags=[{"Key": "tag_key_1", "Value": "tag_value_X"}] ) - conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"].should.equal( + assert conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"] == ( [ {"Key": "tag_key_1", "Value": "tag_value_X"}, {"Key": "tag_key_2", "Value": "tag_value_2"}, @@ -459,13 +455,13 @@ def test_untag_topic(): topic_arn = response["TopicArn"] conn.untag_resource(ResourceArn=topic_arn, TagKeys=["tag_key_1"]) - conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"].should.equal( + assert conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"] == ( [{"Key": "tag_key_2", "Value": "tag_value_2"}] ) # removing a non existing tag should not raise any error conn.untag_resource(ResourceArn=topic_arn, TagKeys=["not-existing-tag"]) - conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"].should.equal( + assert conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"] == ( [{"Key": "tag_key_2", "Value": "tag_value_2"}] ) @@ -477,9 +473,9 @@ def test_list_tags_for_resource_error(): Name="some-topic-with-tags", Tags=[{"Key": "tag_key_1", "Value": "tag_value_X"}] ) - conn.list_tags_for_resource.when.called_with( - ResourceArn="not-existing-topic" - ).should.throw(ClientError, "Resource does not exist") + with pytest.raises(ClientError) as client_err: + conn.list_tags_for_resource(ResourceArn="not-existing-topic") + assert client_err.value.response["Error"]["Message"] == "Resource does not exist" @mock_sns @@ -490,22 +486,24 @@ def test_tag_resource_errors(): ) topic_arn = response["TopicArn"] - conn.tag_resource.when.called_with( - ResourceArn="not-existing-topic", - Tags=[{"Key": "tag_key_1", "Value": "tag_value_1"}], - ).should.throw(ClientError, "Resource does not exist") + with pytest.raises(ClientError) as client_err: + conn.tag_resource( + ResourceArn="not-existing-topic", + Tags=[{"Key": "tag_key_1", "Value": "tag_value_1"}], + ) + assert client_err.value.response["Error"]["Message"] == "Resource does not exist" too_many_tags = [ {"Key": f"tag_key_{i}", "Value": f"tag_value_{i}"} for i in range(51) ] - conn.tag_resource.when.called_with( - ResourceArn=topic_arn, Tags=too_many_tags - ).should.throw( - ClientError, "Could not complete request: tag quota of per resource exceeded" + with pytest.raises(ClientError) as client_err: + conn.tag_resource(ResourceArn=topic_arn, Tags=too_many_tags) + assert client_err.value.response["Error"]["Message"] == ( + "Could not complete request: tag quota of per resource exceeded" ) # when the request fails, the tags should not be updated - conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"].should.equal( + assert conn.list_tags_for_resource(ResourceArn=topic_arn)["Tags"] == ( [{"Key": "tag_key_1", "Value": "tag_value_X"}] ) @@ -517,9 +515,9 @@ def test_untag_resource_error(): Name="some-topic-with-tags", Tags=[{"Key": "tag_key_1", "Value": "tag_value_X"}] ) - conn.untag_resource.when.called_with( - ResourceArn="not-existing-topic", TagKeys=["tag_key_1"] - ).should.throw(ClientError, "Resource does not exist") + with pytest.raises(ClientError) as client_err: + conn.untag_resource(ResourceArn="not-existing-topic", TagKeys=["tag_key_1"]) + assert client_err.value.response["Error"]["Message"] == "Resource does not exist" @mock_sns @@ -534,29 +532,32 @@ def test_create_fifo_topic(): try: conn.create_topic(Name="test_topic", Attributes={"FifoTopic": "true"}) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameterValue") - err.response["Error"]["Message"].should.equal( - "Fifo Topic names must end with .fifo and must be made up of only uppercase and lowercase ASCII letters, " - "numbers, underscores, and hyphens, and must be between 1 and 256 characters long." + assert err.response["Error"]["Code"] == "InvalidParameterValue" + assert err.response["Error"]["Message"] == ( + "Fifo Topic names must end with .fifo and must be made up of only " + "uppercase and lowercase ASCII letters, numbers, underscores, " + "and hyphens, and must be between 1 and 256 characters long." ) - err.response["Error"]["Type"].should.equal("Sender") + assert err.response["Error"]["Type"] == "Sender" try: conn.create_topic(Name="test_topic.fifo") except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameterValue") - err.response["Error"]["Message"].should.equal( - "Topic names must be made up of only uppercase and lowercase ASCII letters, numbers, underscores, " + assert err.response["Error"]["Code"] == "InvalidParameterValue" + assert err.response["Error"]["Message"] == ( + "Topic names must be made up of only uppercase and lowercase " + "ASCII letters, numbers, underscores, " "and hyphens, and must be between 1 and 256 characters long." ) try: conn.create_topic(Name="topic.name.fifo", Attributes={"FifoTopic": "true"}) except ClientError as err: - err.response["Error"]["Code"].should.equal("InvalidParameterValue") - err.response["Error"]["Message"].should.equal( - "Fifo Topic names must end with .fifo and must be made up of only uppercase and lowercase ASCII letters, " - "numbers, underscores, and hyphens, and must be between 1 and 256 characters long." + assert err.response["Error"]["Code"] == "InvalidParameterValue" + assert err.response["Error"]["Message"] == ( + "Fifo Topic names must end with .fifo and must be made up of only " + "uppercase and lowercase ASCII letters, numbers, underscores, " + "and hyphens, and must be between 1 and 256 characters long." ) @@ -566,22 +567,22 @@ def test_topic_kms_master_key_id_attribute(): resp = client.create_topic(Name="test-sns-no-key-attr") topic_arn = resp["TopicArn"] resp = client.get_topic_attributes(TopicArn=topic_arn) - resp["Attributes"].should_not.have.key("KmsMasterKeyId") + assert "KmsMasterKeyId" not in resp["Attributes"] client.set_topic_attributes( TopicArn=topic_arn, AttributeName="KmsMasterKeyId", AttributeValue="test-key" ) resp = client.get_topic_attributes(TopicArn=topic_arn) - resp["Attributes"].should.have.key("KmsMasterKeyId") - resp["Attributes"]["KmsMasterKeyId"].should.equal("test-key") + assert "KmsMasterKeyId" in resp["Attributes"] + assert resp["Attributes"]["KmsMasterKeyId"] == "test-key" resp = client.create_topic( Name="test-sns-with-key-attr", Attributes={"KmsMasterKeyId": "key-id"} ) topic_arn = resp["TopicArn"] resp = client.get_topic_attributes(TopicArn=topic_arn) - resp["Attributes"].should.have.key("KmsMasterKeyId") - resp["Attributes"]["KmsMasterKeyId"].should.equal("key-id") + assert "KmsMasterKeyId" in resp["Attributes"] + assert resp["Attributes"]["KmsMasterKeyId"] == "key-id" @mock_sns @@ -593,11 +594,11 @@ def test_topic_fifo_get_attributes(): topic_arn = resp["TopicArn"] attributes = client.get_topic_attributes(TopicArn=topic_arn)["Attributes"] - attributes.should.have.key("FifoTopic") - attributes.should.have.key("ContentBasedDeduplication") + assert "FifoTopic" in attributes + assert "ContentBasedDeduplication" in attributes - attributes["FifoTopic"].should.equal("true") - attributes["ContentBasedDeduplication"].should.equal("false") + assert attributes["FifoTopic"] == "true" + assert attributes["ContentBasedDeduplication"] == "false" client.set_topic_attributes( TopicArn=topic_arn, @@ -605,7 +606,7 @@ def test_topic_fifo_get_attributes(): AttributeValue="true", ) attributes = client.get_topic_attributes(TopicArn=topic_arn)["Attributes"] - attributes["ContentBasedDeduplication"].should.equal("true") + assert attributes["ContentBasedDeduplication"] == "true" @mock_sns @@ -615,8 +616,8 @@ def test_topic_get_attributes(): topic_arn = resp["TopicArn"] attributes = client.get_topic_attributes(TopicArn=topic_arn)["Attributes"] - attributes.should_not.have.key("FifoTopic") - attributes.should_not.have.key("ContentBasedDeduplication") + assert "FifoTopic" not in attributes + assert "ContentBasedDeduplication" not in attributes @mock_sns @@ -628,5 +629,5 @@ def test_topic_get_attributes_with_fifo_false(): topic_arn = resp["TopicArn"] attributes = client.get_topic_attributes(TopicArn=topic_arn)["Attributes"] - attributes.should_not.have.key("FifoTopic") - attributes.should_not.have.key("ContentBasedDeduplication") + assert "FifoTopic" not in attributes + assert "ContentBasedDeduplication" not in attributes diff --git a/tests/test_sns/test_utils.py b/tests/test_sns/test_utils.py index 4ef9afe1c..5726626f3 100644 --- a/tests/test_sns/test_utils.py +++ b/tests/test_sns/test_utils.py @@ -1,6 +1,7 @@ -from moto.sns.utils import FilterPolicyMatcher import pytest +from moto.sns.utils import FilterPolicyMatcher + def test_filter_policy_matcher_scope_sanity_check(): with pytest.raises(FilterPolicyMatcher.CheckException):