Techdebt: Replace sure with regular assertions in Events (#6564)
This commit is contained in:
parent
8cc5155cc6
commit
689c93376a
@ -1,5 +1,4 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from moto.events.models import EventPattern
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,6 @@ import boto3
|
||||
import json
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_cloudformation, mock_events
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
|
||||
@ -86,12 +85,12 @@ def test_create_archive():
|
||||
# then
|
||||
archive_arn = f"arn:aws:events:eu-central-1:{ACCOUNT_ID}:archive/{name}"
|
||||
stack = cfn_client.describe_stacks(StackName=stack_name)["Stacks"][0]
|
||||
stack["Outputs"][0]["OutputValue"].should.equal(archive_arn)
|
||||
assert stack["Outputs"][0]["OutputValue"] == archive_arn
|
||||
|
||||
events_client = boto3.client("events", region_name="eu-central-1")
|
||||
response = events_client.describe_archive(ArchiveName=name)
|
||||
|
||||
response["ArchiveArn"].should.equal(archive_arn)
|
||||
assert response["ArchiveArn"] == archive_arn
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -118,10 +117,11 @@ def test_update_archive():
|
||||
events_client = boto3.client("events", region_name="eu-central-1")
|
||||
response = events_client.describe_archive(ArchiveName=name)
|
||||
|
||||
response["ArchiveArn"].should.equal(
|
||||
f"arn:aws:events:eu-central-1:{ACCOUNT_ID}:archive/{name}"
|
||||
assert (
|
||||
response["ArchiveArn"]
|
||||
== f"arn:aws:events:eu-central-1:{ACCOUNT_ID}:archive/{name}"
|
||||
)
|
||||
response["Description"].should.equal("test archive")
|
||||
assert response["Description"] == "test archive"
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -140,7 +140,7 @@ def test_delete_archive():
|
||||
# then
|
||||
events_client = boto3.client("events", region_name="eu-central-1")
|
||||
response = events_client.list_archives(NamePrefix="test")["Archives"]
|
||||
response.should.have.length_of(0)
|
||||
assert len(response) == 0
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -158,13 +158,13 @@ def test_create_rule():
|
||||
# then
|
||||
rule_arn = f"arn:aws:events:eu-central-1:{ACCOUNT_ID}:rule/{name}"
|
||||
stack = cfn_client.describe_stacks(StackName=stack_name)["Stacks"][0]
|
||||
stack["Outputs"][0]["OutputValue"].should.equal(rule_arn)
|
||||
assert stack["Outputs"][0]["OutputValue"] == rule_arn
|
||||
|
||||
events_client = boto3.client("events", region_name="eu-central-1")
|
||||
response = events_client.describe_rule(Name=name)
|
||||
|
||||
response["Arn"].should.equal(rule_arn)
|
||||
response["EventPattern"].should.equal('{"detail-type": ["SomeDetailType"]}')
|
||||
assert response["Arn"] == rule_arn
|
||||
assert response["EventPattern"] == '{"detail-type": ["SomeDetailType"]}'
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -186,5 +186,5 @@ def test_delete_rule():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
events_client.describe_rule(Name=name)
|
||||
err = exc.value.response["Error"]
|
||||
err["Code"].should.equal("ResourceNotFoundException")
|
||||
err["Message"].should.equal("Rule test-rule does not exist.")
|
||||
assert err["Code"] == "ResourceNotFoundException"
|
||||
assert err["Message"] == "Rule test-rule does not exist."
|
||||
|
@ -5,8 +5,6 @@ from unittest import SkipTest, mock
|
||||
import boto3
|
||||
import os
|
||||
|
||||
import sure # noqa # pylint: disable=unused-import
|
||||
|
||||
from moto import mock_events, mock_sqs, mock_logs, settings
|
||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
from moto.core.utils import iso_8601_datetime_without_milliseconds
|
||||
@ -51,22 +49,22 @@ def test_send_to_cw_log_group():
|
||||
|
||||
# then
|
||||
response = client_logs.filter_log_events(logGroupName=log_group_name)
|
||||
response["events"].should.have.length_of(1)
|
||||
assert len(response["events"]) == 1
|
||||
event = response["events"][0]
|
||||
event["logStreamName"].should_not.equal(None)
|
||||
event["timestamp"].should.be.a(float)
|
||||
event["ingestionTime"].should.be.a(int)
|
||||
event["eventId"].should_not.equal(None)
|
||||
assert event["logStreamName"] is not None
|
||||
assert isinstance(event["timestamp"], float)
|
||||
assert isinstance(event["ingestionTime"], int)
|
||||
assert event["eventId"] is not None
|
||||
|
||||
message = json.loads(event["message"])
|
||||
message["version"].should.equal("0")
|
||||
message["id"].should_not.equal(None)
|
||||
message["detail-type"].should.equal("type")
|
||||
message["source"].should.equal("source")
|
||||
message["time"].should.equal(iso_8601_datetime_without_milliseconds(event_time))
|
||||
message["region"].should.equal("eu-central-1")
|
||||
message["resources"].should.equal([])
|
||||
message["detail"].should.equal({"key": "value"})
|
||||
assert message["version"] == "0"
|
||||
assert message["id"] is not None
|
||||
assert message["detail-type"] == "type"
|
||||
assert message["source"] == "source"
|
||||
assert message["time"] == iso_8601_datetime_without_milliseconds(event_time)
|
||||
assert message["region"] == "eu-central-1"
|
||||
assert message["resources"] == []
|
||||
assert message["detail"] == {"key": "value"}
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -130,31 +128,31 @@ def test_send_to_sqs_fifo_queue():
|
||||
QueueUrl=queue_url_dedup,
|
||||
AttributeNames=["MessageDeduplicationId", "MessageGroupId"],
|
||||
)
|
||||
response["Messages"].should.have.length_of(1)
|
||||
assert len(response["Messages"]) == 1
|
||||
message = response["Messages"][0]
|
||||
message["MessageId"].should_not.equal(None)
|
||||
message["ReceiptHandle"].should_not.equal(None)
|
||||
message["MD5OfBody"].should_not.equal(None)
|
||||
assert message["MessageId"] is not None
|
||||
assert message["ReceiptHandle"] is not None
|
||||
assert message["MD5OfBody"] is not None
|
||||
|
||||
message["Attributes"]["MessageDeduplicationId"].should_not.equal(None)
|
||||
message["Attributes"]["MessageGroupId"].should.equal("group-id")
|
||||
assert message["Attributes"]["MessageDeduplicationId"] is not None
|
||||
assert message["Attributes"]["MessageGroupId"] == "group-id"
|
||||
|
||||
body = json.loads(message["Body"])
|
||||
body["version"].should.equal("0")
|
||||
body["id"].should_not.equal(None)
|
||||
body["detail-type"].should.equal("type")
|
||||
body["source"].should.equal("source")
|
||||
body["time"].should.equal(iso_8601_datetime_without_milliseconds(event_time))
|
||||
body["region"].should.equal("eu-central-1")
|
||||
body["resources"].should.equal([])
|
||||
body["detail"].should.equal({"key": "value"})
|
||||
assert body["version"] == "0"
|
||||
assert body["id"] is not None
|
||||
assert body["detail-type"] == "type"
|
||||
assert body["source"] == "source"
|
||||
assert body["time"] == iso_8601_datetime_without_milliseconds(event_time)
|
||||
assert body["region"] == "eu-central-1"
|
||||
assert body["resources"] == []
|
||||
assert body["detail"] == {"key": "value"}
|
||||
|
||||
# A FIFO queue without content-based deduplication enabled
|
||||
# does not receive any event from the Event Bus
|
||||
response = client_sqs.receive_message(
|
||||
QueueUrl=queue_url, AttributeNames=["MessageDeduplicationId", "MessageGroupId"]
|
||||
)
|
||||
response.should_not.have.key("Messages")
|
||||
assert "Messages" not in response
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -190,21 +188,21 @@ def test_send_to_sqs_queue():
|
||||
|
||||
# then
|
||||
response = client_sqs.receive_message(QueueUrl=queue_url)
|
||||
response["Messages"].should.have.length_of(1)
|
||||
assert len(response["Messages"]) == 1
|
||||
message = response["Messages"][0]
|
||||
message["MessageId"].should_not.equal(None)
|
||||
message["ReceiptHandle"].should_not.equal(None)
|
||||
message["MD5OfBody"].should_not.equal(None)
|
||||
assert message["MessageId"] is not None
|
||||
assert message["ReceiptHandle"] is not None
|
||||
assert message["MD5OfBody"] is not None
|
||||
|
||||
body = json.loads(message["Body"])
|
||||
body["version"].should.equal("0")
|
||||
body["id"].should_not.equal(None)
|
||||
body["detail-type"].should.equal("type")
|
||||
body["source"].should.equal("source")
|
||||
body["time"].should.equal(iso_8601_datetime_without_milliseconds(event_time))
|
||||
body["region"].should.equal("eu-central-1")
|
||||
body["resources"].should.equal([])
|
||||
body["detail"].should.equal({"key": "value"})
|
||||
assert body["version"] == "0"
|
||||
assert body["id"] is not None
|
||||
assert body["detail-type"] == "type"
|
||||
assert body["source"] == "source"
|
||||
assert body["time"] == iso_8601_datetime_without_milliseconds(event_time)
|
||||
assert body["region"] == "eu-central-1"
|
||||
assert body["resources"] == []
|
||||
assert body["detail"] == {"key": "value"}
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -249,7 +247,7 @@ def test_send_to_sqs_queue_with_custom_event_bus():
|
||||
assert len(response["Messages"]) == 1
|
||||
|
||||
body = json.loads(response["Messages"][0]["Body"])
|
||||
body["detail"].should.equal({"key": "value"})
|
||||
assert body["detail"] == {"key": "value"}
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -313,12 +311,10 @@ def test_moto_matches_none_value_with_exists_filter():
|
||||
)
|
||||
event_details = [json.loads(x["message"])["detail"] for x in events]
|
||||
|
||||
event_details.should.equal(
|
||||
[
|
||||
{"foo": "123", "bar": "123"},
|
||||
{"foo": None, "bar": "123"},
|
||||
],
|
||||
)
|
||||
assert event_details == [
|
||||
{"foo": "123", "bar": "123"},
|
||||
{"foo": None, "bar": "123"},
|
||||
]
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -406,9 +402,9 @@ def test_put_events_event_bus_forwarding_rules():
|
||||
|
||||
response = sqs_client.receive_message(QueueUrl=queue_url)
|
||||
|
||||
response["Messages"].should.have.length_of(1)
|
||||
assert len(response["Messages"]) == 1
|
||||
|
||||
message = json.loads(response["Messages"][0]["Body"])
|
||||
message["source"].should.equal("source1")
|
||||
message["detail-type"].should.equal("test-detail-type")
|
||||
message["detail"].should.equal({"test": "true"})
|
||||
assert message["source"] == "source1"
|
||||
assert message["detail-type"] == "test-detail-type"
|
||||
assert message["detail"] == {"test": "true"}
|
||||
|
@ -81,12 +81,12 @@ def test_creating_bucket__invokes_lambda():
|
||||
|
||||
event = json.loads(list([line for line in all_logs if expected_msg in line])[-1])
|
||||
|
||||
event.should.have.key("detail-type").equals("Object Created")
|
||||
event.should.have.key("source").equals("aws.s3")
|
||||
event.should.have.key("account").equals(ACCOUNT_ID)
|
||||
event.should.have.key("time")
|
||||
event.should.have.key("region").equals("us-east-1")
|
||||
event.should.have.key("resources").equals([f"arn:aws:s3:::{bucket_name}"])
|
||||
assert event["detail-type"] == "Object Created"
|
||||
assert event["source"] == "aws.s3"
|
||||
assert event["account"] == ACCOUNT_ID
|
||||
assert "time" in event
|
||||
assert event["region"] == "us-east-1"
|
||||
assert event["resources"] == [f"arn:aws:s3:::{bucket_name}"]
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -155,7 +155,7 @@ def test_create_disabled_rule():
|
||||
expected_msg = '"detail-type":"Object Created"'
|
||||
log_group = f"/aws/lambda/{bucket_name}"
|
||||
msg_showed_up, _ = wait_for_log_msg(expected_msg, log_group, wait_time=5)
|
||||
msg_showed_up.should.equal(False)
|
||||
assert msg_showed_up is False
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -214,7 +214,7 @@ def test_create_rule_for_unsupported_target_arn():
|
||||
expected_msg = '"detail-type":"Object Created"'
|
||||
log_group = f"/aws/lambda/{bucket_name}"
|
||||
msg_showed_up, _ = wait_for_log_msg(expected_msg, log_group, wait_time=5)
|
||||
msg_showed_up.should.equal(False)
|
||||
assert msg_showed_up is False
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -280,7 +280,7 @@ def test_creating_bucket__but_invoke_lambda_on_create_object():
|
||||
expected_msg = '"detail-type":"Object Created"'
|
||||
log_group = f"/aws/lambda/{bucket_name}"
|
||||
msg_showed_up, _ = wait_for_log_msg(expected_msg, log_group, wait_time=5)
|
||||
msg_showed_up.should.equal(False)
|
||||
assert msg_showed_up is False
|
||||
|
||||
|
||||
@mock_events
|
||||
@ -334,4 +334,4 @@ def test_creating_bucket__succeeds_despite_unknown_lambda():
|
||||
ACL="public-read-write",
|
||||
Bucket=bucket_name,
|
||||
)
|
||||
bucket.shouldnt.equal(None)
|
||||
assert bucket is not None
|
||||
|
Loading…
Reference in New Issue
Block a user