Skip to content

Commit a5ce64c

Browse files
committed
feat: test limit listing to context of test
1 parent 344f54c commit a5ce64c

File tree

3 files changed

+103
-132
lines changed

3 files changed

+103
-132
lines changed

tests/aws/services/events/test_events.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ def test_create_list_describe_delete_custom_event_buses(
725725
response = events.create_event_bus(Name=bus_name)
726726
snapshot.match(f"create-custom-event-bus-{region}", response)
727727

728-
response = events.list_event_buses()
728+
response = events.list_event_buses(NamePrefix=bus_name)
729729
snapshot.match(f"list-event-buses-after-create-{region}", response)
730730

731731
response = events.describe_event_bus(Name=bus_name)
@@ -738,7 +738,7 @@ def test_create_list_describe_delete_custom_event_buses(
738738
response = events.delete_event_bus(Name=bus_name)
739739
snapshot.match(f"delete-custom-event-bus-{region}", response)
740740

741-
response = events.list_event_buses()
741+
response = events.list_event_buses(NamePrefix=bus_name)
742742
snapshot.match(f"list-event-buses-after-delete-{region}", response)
743743

744744
@markers.aws.validated
@@ -772,7 +772,7 @@ def test_delete_default_event_bus(self, aws_client, snapshot):
772772
@markers.aws.validated
773773
def test_list_event_buses_with_prefix(self, create_event_bus, aws_client, snapshot):
774774
events = aws_client.events
775-
bus_name = f"test-bus-{short_uid()}"
775+
bus_name = f"unique-prefix-1234567890-{short_uid()}"
776776
snapshot.add_transformer(snapshot.transform.regex(bus_name, "<bus-name>"))
777777

778778
bus_name_not_match = "no-prefix-match"
@@ -803,11 +803,11 @@ def test_list_event_buses_with_limit(self, create_event_bus, aws_client, snapsho
803803
bus_name = f"{bus_name_prefix}-{i}"
804804
create_event_bus(Name=bus_name)
805805

806-
response = events.list_event_buses(Limit=int(count / 2))
806+
response = events.list_event_buses(Limit=int(count / 2), NamePrefix=bus_name_prefix)
807807
snapshot.match("list-event-buses-limit", response)
808808

809809
response = events.list_event_buses(
810-
Limit=int(count / 2) + 2, NextToken=response["NextToken"]
810+
Limit=int(count / 2) + 2, NextToken=response["NextToken"], NamePrefix=bus_name_prefix
811811
)
812812
snapshot.match("list-event-buses-limit-next-token", response)
813813

@@ -883,6 +883,7 @@ def test_put_events_into_event_bus(
883883

884884
@markers.aws.validated
885885
@pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet")
886+
# TODO simplify and use sqs as target
886887
def test_put_events_to_default_eventbus_for_custom_eventbus(
887888
self,
888889
events_create_event_bus,
@@ -1035,8 +1036,6 @@ def test_put_events_nonexistent_event_bus(
10351036
snapshot.transform.regex(nonexistent_event_bus, "<custom-event-bus>"),
10361037
]
10371038
)
1038-
# create SQS queue + add rules & targets so that we can check the default event bus received the message
1039-
# even if one entry was wrong
10401039

10411040
queue_url = sqs_create_queue()
10421041
queue_arn = sqs_get_queue_arn(queue_url)
@@ -1059,16 +1058,14 @@ def test_put_events_nonexistent_event_bus(
10591058
Targets=[{"Id": default_bus_target_id, "Arn": queue_arn}],
10601059
)
10611060

1062-
# create two entries, one with no EventBus specified (so it will target the default one)
1063-
# and one with a nonexistent EventBusName, which should be ignored
10641061
entries = [
10651062
{
10661063
"Source": "MySource",
10671064
"DetailType": "CustomType",
10681065
"Detail": json.dumps({"message": "for the default event bus"}),
10691066
},
10701067
{
1071-
"EventBusName": nonexistent_event_bus,
1068+
"EventBusName": nonexistent_event_bus, # nonexistent EventBusName, message should be ignored
10721069
"Source": "MySource",
10731070
"DetailType": "CustomType",
10741071
"Detail": json.dumps({"message": "for the custom event bus"}),
@@ -1077,7 +1074,7 @@ def test_put_events_nonexistent_event_bus(
10771074
response = aws_client.events.put_events(Entries=entries)
10781075
snapshot.match("put-events", response)
10791076

1080-
def _get_sqs_messages():
1077+
def _get_sqs_messages(): # TODO cleanup use exiting fixture
10811078
resp = aws_client.sqs.receive_message(
10821079
QueueUrl=queue_url, VisibilityTimeout=0, WaitTimeSeconds=1
10831080
)
@@ -1091,7 +1088,6 @@ def _get_sqs_messages():
10911088
messages = retry(_get_sqs_messages, retries=10, sleep=0.1)
10921089
snapshot.match("get-events", messages)
10931090

1094-
# try to get the custom EventBus we passed the Event to
10951091
with pytest.raises(ClientError) as e:
10961092
aws_client.events.describe_event_bus(Name=nonexistent_event_bus)
10971093
snapshot.match("non-existent-bus-error", e.value.response)
@@ -1131,44 +1127,59 @@ def test_put_list_with_prefix_describe_delete_rule(
11311127
snapshot.match("list-rules-after-delete", response)
11321128

11331129
@markers.aws.validated
1134-
def test_put_multiple_rules_with_same_name(self, put_rule, aws_client, snapshot):
1130+
def test_put_multiple_rules_with_same_name(
1131+
self, create_event_bus, put_rule, aws_client, snapshot
1132+
):
1133+
event_bus_name = f"bus-{short_uid()}"
1134+
create_event_bus(Name=event_bus_name)
1135+
snapshot.add_transformer(snapshot.transform.regex(event_bus_name, "<bus-name>"))
1136+
11351137
rule_name = f"test-rule-{short_uid()}"
11361138
snapshot.add_transformer(snapshot.transform.regex(rule_name, "<rule-name>"))
11371139

11381140
response = put_rule(
11391141
Name=rule_name,
1142+
EventBusName=event_bus_name,
11401143
EventPattern=json.dumps(TEST_EVENT_PATTERN),
11411144
)
11421145
snapshot.match("put-rule", response)
11431146

11441147
# put_rule updates the rule if it already exists
11451148
response = put_rule(
11461149
Name=rule_name,
1150+
EventBusName=event_bus_name,
11471151
EventPattern=json.dumps(TEST_EVENT_PATTERN),
11481152
)
11491153
snapshot.match("re-put-rule", response)
11501154

1151-
response = aws_client.events.list_rules(NamePrefix=rule_name)
1155+
response = aws_client.events.list_rules(EventBusName=event_bus_name)
11521156
snapshot.match("list-rules", response)
11531157

11541158
@markers.aws.validated
1155-
def test_list_rule_with_limit(self, put_rule, aws_client, snapshot):
1159+
def test_list_rule_with_limit(self, create_event_bus, put_rule, aws_client, snapshot):
11561160
snapshot.add_transformer(snapshot.transform.jsonpath("$..NextToken", "next_token"))
1157-
rule_name_prefix = "test-rule"
1161+
1162+
event_bus_name = f"bus-{short_uid()}"
1163+
create_event_bus(Name=event_bus_name)
1164+
snapshot.add_transformer(snapshot.transform.regex(event_bus_name, "<bus-name>"))
1165+
1166+
rule_name_prefix = f"test-rule-{short_uid()}"
1167+
snapshot.add_transformer(snapshot.transform.regex(rule_name_prefix, "<rule-name-prefix>"))
11581168
count = 6
11591169

11601170
for i in range(count):
11611171
rule_name = f"{rule_name_prefix}-{i}"
11621172
put_rule(
11631173
Name=rule_name,
1174+
EventBusName=event_bus_name,
11641175
EventPattern=json.dumps(TEST_EVENT_PATTERN),
11651176
)
11661177

1167-
response = aws_client.events.list_rules(Limit=int(count / 2))
1178+
response = aws_client.events.list_rules(Limit=int(count / 2), EventBusName=event_bus_name)
11681179
snapshot.match("list-rules-limit", response)
11691180

11701181
response = aws_client.events.list_rules(
1171-
Limit=int(count / 2) + 2, NextToken=response["NextToken"]
1182+
Limit=int(count / 2) + 2, NextToken=response["NextToken"], EventBusName=event_bus_name
11721183
)
11731184
snapshot.match("list-rules-limit-next-token", response)
11741185

0 commit comments

Comments
 (0)