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