Techdebt: Replace sure with regular assertions in Pinpoint (#6677)

Co-authored-by: Karri Balk <kbalk@users.noreply.github.com>
This commit is contained in:
kbalk 2023-08-16 07:29:57 -04:00 committed by GitHub
parent 35fc33c81c
commit 45cffb6cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 67 deletions

View File

@ -1,9 +1,8 @@
"""Unit tests for pinpoint-supported APIs."""
import boto3
import pytest
import sure # noqa # pylint: disable=unused-import
from botocore.exceptions import ClientError
import pytest
from moto import mock_pinpoint
# See our Development Tips on writing tests for hints on how to write good tests:
@ -15,11 +14,11 @@ def test_create_app():
client = boto3.client("pinpoint", region_name="us-east-1")
resp = client.create_app(CreateApplicationRequest={"Name": "myfirstapp"})
resp.should.have.key("ApplicationResponse")
resp["ApplicationResponse"].should.have.key("Arn")
resp["ApplicationResponse"].should.have.key("Id")
resp["ApplicationResponse"].should.have.key("Name").equals("myfirstapp")
resp["ApplicationResponse"].should.have.key("CreationDate")
assert "ApplicationResponse" in resp
assert "Arn" in resp["ApplicationResponse"]
assert "Id" in resp["ApplicationResponse"]
assert resp["ApplicationResponse"]["Name"] == "myfirstapp"
assert "CreationDate" in resp["ApplicationResponse"]
@mock_pinpoint
@ -31,13 +30,13 @@ def test_delete_app():
app_id = creation["Id"]
deletion = client.delete_app(ApplicationId=app_id)["ApplicationResponse"]
deletion.should.equal(creation)
assert deletion == creation
with pytest.raises(ClientError) as exc:
client.get_app(ApplicationId=app_id)
err = exc.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal("Application not found")
assert err["Code"] == "NotFoundException"
assert err["Message"] == "Application not found"
@mock_pinpoint
@ -48,11 +47,11 @@ def test_get_app():
resp = client.get_app(ApplicationId=app_id)
resp.should.have.key("ApplicationResponse")
resp["ApplicationResponse"].should.have.key("Arn")
resp["ApplicationResponse"].should.have.key("Id")
resp["ApplicationResponse"].should.have.key("Name").equals("myfirstapp")
resp["ApplicationResponse"].should.have.key("CreationDate")
assert "ApplicationResponse" in resp
assert "Arn" in resp["ApplicationResponse"]
assert "Id" in resp["ApplicationResponse"]
assert resp["ApplicationResponse"]["Name"] == "myfirstapp"
assert "CreationDate" in resp["ApplicationResponse"]
@mock_pinpoint
@ -60,8 +59,8 @@ def test_get_apps_initial():
client = boto3.client("pinpoint", region_name="us-east-1")
resp = client.get_apps()
resp.should.have.key("ApplicationsResponse")
resp["ApplicationsResponse"].should.equal({"Item": []})
assert "ApplicationsResponse" in resp
assert resp["ApplicationsResponse"] == {"Item": []}
@mock_pinpoint
@ -72,11 +71,11 @@ def test_get_apps():
resp = client.get_apps()
resp.should.have.key("ApplicationsResponse").should.have.key("Item").length_of(1)
resp["ApplicationsResponse"]["Item"][0].should.have.key("Arn")
resp["ApplicationsResponse"]["Item"][0].should.have.key("Id").equals(app_id)
resp["ApplicationsResponse"]["Item"][0].should.have.key("Name").equals("myfirstapp")
resp["ApplicationsResponse"]["Item"][0].should.have.key("CreationDate")
assert len(resp["ApplicationsResponse"]["Item"]) == 1
assert "Arn" in resp["ApplicationsResponse"]["Item"][0]
assert resp["ApplicationsResponse"]["Item"][0]["Id"] == app_id
assert resp["ApplicationsResponse"]["Item"][0]["Name"] == "myfirstapp"
assert "CreationDate" in resp["ApplicationsResponse"]["Item"][0]
@mock_pinpoint
@ -95,12 +94,12 @@ def test_update_application_settings():
},
)
resp.should.have.key("ApplicationSettingsResource")
assert "ApplicationSettingsResource" in resp
app_settings = resp["ApplicationSettingsResource"]
app_settings.should.have.key("ApplicationId").equals(app_id)
app_settings.should.have.key("CampaignHook").equals({"LambdaFunctionName": "lfn"})
app_settings.should.have.key("Limits").equals({"Daily": 42})
app_settings.should.have.key("LastModifiedDate")
assert app_settings["ApplicationId"] == app_id
assert app_settings["CampaignHook"] == {"LambdaFunctionName": "lfn"}
assert app_settings["Limits"] == {"Daily": 42}
assert "LastModifiedDate" in app_settings
@mock_pinpoint
@ -121,9 +120,9 @@ def test_get_application_settings():
resp = client.get_application_settings(ApplicationId=app_id)
resp.should.have.key("ApplicationSettingsResource")
assert "ApplicationSettingsResource" in resp
app_settings = resp["ApplicationSettingsResource"]
app_settings.should.have.key("ApplicationId").equals(app_id)
app_settings.should.have.key("CampaignHook").equals({"LambdaFunctionName": "lfn"})
app_settings.should.have.key("Limits").equals({"Daily": 42})
app_settings.should.have.key("LastModifiedDate")
assert app_settings["ApplicationId"] == app_id
assert app_settings["CampaignHook"] == {"LambdaFunctionName": "lfn"}
assert app_settings["Limits"] == {"Daily": 42}
assert "LastModifiedDate" in app_settings

View File

@ -1,6 +1,5 @@
"""Unit tests for pinpoint-supported APIs."""
import boto3
import sure # noqa # pylint: disable=unused-import
from moto import mock_pinpoint
@ -12,7 +11,7 @@ def test_list_tags_for_resource_empty():
app_arn = resp["ApplicationResponse"]["Arn"]
resp = client.list_tags_for_resource(ResourceArn=app_arn)
resp.should.have.key("TagsModel").equals({"tags": {}})
assert resp["TagsModel"] == {"tags": {}}
@mock_pinpoint
@ -27,10 +26,8 @@ def test_list_tags_for_resource():
app_arn = resp["ApplicationResponse"]["Arn"]
resp = client.list_tags_for_resource(ResourceArn=app_arn)
resp.should.have.key("TagsModel")
resp["TagsModel"].should.have.key("tags").equals(
{"key1": "value1", "key2": "value2"}
)
assert "TagsModel" in resp
assert resp["TagsModel"]["tags"] == {"key1": "value1", "key2": "value2"}
@mock_pinpoint
@ -44,10 +41,8 @@ def test_tag_resource():
)
resp = client.list_tags_for_resource(ResourceArn=app_arn)
resp.should.have.key("TagsModel")
resp["TagsModel"].should.have.key("tags").equals(
{"key1": "value1", "key2": "value2"}
)
assert "TagsModel" in resp
assert resp["TagsModel"]["tags"] == {"key1": "value1", "key2": "value2"}
@mock_pinpoint
@ -65,7 +60,5 @@ def test_untag_resource():
client.untag_resource(ResourceArn=app_arn, TagKeys=["key2"])
resp = client.list_tags_for_resource(ResourceArn=app_arn)
resp.should.have.key("TagsModel")
resp["TagsModel"].should.have.key("tags").equals(
{"key1": "value1", "key3": "value3"}
)
assert "TagsModel" in resp
assert resp["TagsModel"]["tags"] == {"key1": "value1", "key3": "value3"}

View File

@ -1,9 +1,8 @@
"""Unit tests for pinpoint-supported APIs."""
import boto3
import pytest
import sure # noqa # pylint: disable=unused-import
from botocore.exceptions import ClientError
import pytest
from moto import mock_pinpoint
# See our Development Tips on writing tests for hints on how to write good tests:
@ -21,11 +20,11 @@ def test_put_event_stream():
WriteEventStream={"DestinationStreamArn": "kinesis:arn", "RoleArn": "iam:arn"},
)
resp.should.have.key("EventStream")
resp["EventStream"].should.have.key("ApplicationId").equals(app_id)
resp["EventStream"].should.have.key("DestinationStreamArn").equals("kinesis:arn")
resp["EventStream"].should.have.key("LastModifiedDate")
resp["EventStream"].should.have.key("RoleArn").equals("iam:arn")
assert "EventStream" in resp
assert resp["EventStream"]["ApplicationId"] == app_id
assert resp["EventStream"]["DestinationStreamArn"] == "kinesis:arn"
assert "LastModifiedDate" in resp["EventStream"]
assert resp["EventStream"]["RoleArn"] == "iam:arn"
@mock_pinpoint
@ -41,11 +40,11 @@ def test_get_event_stream():
resp = client.get_event_stream(ApplicationId=app_id)
resp.should.have.key("EventStream")
resp["EventStream"].should.have.key("ApplicationId").equals(app_id)
resp["EventStream"].should.have.key("DestinationStreamArn").equals("kinesis:arn")
resp["EventStream"].should.have.key("LastModifiedDate")
resp["EventStream"].should.have.key("RoleArn").equals("iam:arn")
assert "EventStream" in resp
assert resp["EventStream"]["ApplicationId"] == app_id
assert resp["EventStream"]["DestinationStreamArn"] == "kinesis:arn"
assert "LastModifiedDate" in resp["EventStream"]
assert resp["EventStream"]["RoleArn"] == "iam:arn"
@mock_pinpoint
@ -61,14 +60,14 @@ def test_delete_event_stream():
resp = client.delete_event_stream(ApplicationId=app_id)
resp.should.have.key("EventStream")
resp["EventStream"].should.have.key("ApplicationId").equals(app_id)
resp["EventStream"].should.have.key("DestinationStreamArn").equals("kinesis:arn")
resp["EventStream"].should.have.key("LastModifiedDate")
resp["EventStream"].should.have.key("RoleArn").equals("iam:arn")
assert "EventStream" in resp
assert resp["EventStream"]["ApplicationId"] == app_id
assert resp["EventStream"]["DestinationStreamArn"] == "kinesis:arn"
assert "LastModifiedDate" in resp["EventStream"]
assert resp["EventStream"]["RoleArn"] == "iam:arn"
with pytest.raises(ClientError) as exc:
client.get_event_stream(ApplicationId=app_id)
err = exc.value.response["Error"]
err["Code"].should.equal("NotFoundException")
err["Message"].should.equal("Resource not found")
assert err["Code"] == "NotFoundException"
assert err["Message"] == "Resource not found"