From 9b16a84bbcb87b51531bc927ec0af622425600b4 Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Tue, 18 Jun 2024 16:14:48 +0200 Subject: [PATCH 01/11] refactor: rename test integration to targets --- .test_durations | 30 +++++++++---------- .../test_events_integrations.validation.json | 17 ----------- ...integrations.py => test_events_targets.py} | 0 ...json => test_events_targets.snapshot.json} | 8 ++--- .../test_events_targets.validation.json | 17 +++++++++++ 5 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 tests/aws/services/events/test_events_integrations.validation.json rename tests/aws/services/events/{test_events_integrations.py => test_events_targets.py} (100%) rename tests/aws/services/events/{test_events_integrations.snapshot.json => test_events_targets.snapshot.json} (89%) create mode 100644 tests/aws/services/events/test_events_targets.validation.json diff --git a/.test_durations b/.test_durations index b7bdee05de234..caea8a23da46d 100644 --- a/.test_durations +++ b/.test_durations @@ -843,21 +843,21 @@ "tests/aws/services/events/test_events_inputs.py::TestInputTransformer::test_put_events_with_input_transformer_input_template_string[\"{[/Check with special starting characters for event of type\"]": 0.11936591799985763, "tests/aws/services/events/test_events_inputs.py::TestInputTransformer::test_put_events_with_input_transformer_missing_keys": 0.0006529859997499443, "tests/aws/services/events/test_events_inputs.py::test_put_event_input_path_and_input_transfomer": 0.0006545790001837304, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_firehose": 0.07406386900083817, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_kinesis": 0.9582597469998291, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_lambda": 4.074284712000008, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_lambda_list_entries_partial_match": 4.080728459999591, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_lambda_list_entry": 4.072307003000333, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sns[domain]": 0.05766030499989938, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sns[path]": 0.058427959999335144, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sns[standard]": 0.06193175200041878, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sqs": 0.05069734699964101, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sqs_event_detail_match": 5.064694446999965, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sqs_new_region": 0.021846191999884468, - "tests/aws/services/events/test_events_integrations.py::test_should_ignore_schedules_for_put_event": 11.069308752000325, - "tests/aws/services/events/test_events_integrations.py::test_trigger_event_on_ssm_change[domain]": 0.038843789999646106, - "tests/aws/services/events/test_events_integrations.py::test_trigger_event_on_ssm_change[path]": 0.040668131999609614, - "tests/aws/services/events/test_events_integrations.py::test_trigger_event_on_ssm_change[standard]": 0.041024010999535676, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_firehose": 0.07406386900083817, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_kinesis": 0.9582597469998291, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda": 4.074284712000008, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entries_partial_match": 4.080728459999591, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entry": 4.072307003000333, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sns[domain]": 0.05766030499989938, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sns[path]": 0.058427959999335144, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sns[standard]": 0.06193175200041878, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs": 0.05069734699964101, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs_event_detail_match": 5.064694446999965, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs_new_region": 0.021846191999884468, + "tests/aws/services/events/test_events_targets.py::test_should_ignore_schedules_for_put_event": 11.069308752000325, + "tests/aws/services/events/test_events_targets.py::test_trigger_event_on_ssm_change[domain]": 0.038843789999646106, + "tests/aws/services/events/test_events_targets.py::test_trigger_event_on_ssm_change[path]": 0.040668131999609614, + "tests/aws/services/events/test_events_targets.py::test_trigger_event_on_ssm_change[standard]": 0.041024010999535676, "tests/aws/services/events/test_events_rules.py::test_put_event_with_content_base_rule_in_pattern": 3.05817666799976, "tests/aws/services/events/test_events_rules.py::test_put_events_with_rule_anything_but_to_sqs": 5.094898402000126, "tests/aws/services/events/test_events_rules.py::test_put_events_with_rule_exists_false_to_sqs": 5.073232123999787, diff --git a/tests/aws/services/events/test_events_integrations.validation.json b/tests/aws/services/events/test_events_integrations.validation.json deleted file mode 100644 index bf2860707799f..0000000000000 --- a/tests/aws/services/events/test_events_integrations.validation.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_lambda_list_entries_partial_match": { - "last_validated_date": "2024-04-08T17:36:24+00:00" - }, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_lambda_list_entry": { - "last_validated_date": "2024-04-08T17:33:44+00:00" - }, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sqs": { - "last_validated_date": "2024-04-26T08:43:27+00:00" - }, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sqs_event_detail_match": { - "last_validated_date": "2024-05-07T10:40:38+00:00" - }, - "tests/aws/services/events/test_events_integrations.py::test_should_ignore_schedules_for_put_event": { - "last_validated_date": "2024-03-26T15:51:47+00:00" - } -} diff --git a/tests/aws/services/events/test_events_integrations.py b/tests/aws/services/events/test_events_targets.py similarity index 100% rename from tests/aws/services/events/test_events_integrations.py rename to tests/aws/services/events/test_events_targets.py diff --git a/tests/aws/services/events/test_events_integrations.snapshot.json b/tests/aws/services/events/test_events_targets.snapshot.json similarity index 89% rename from tests/aws/services/events/test_events_integrations.snapshot.json rename to tests/aws/services/events/test_events_targets.snapshot.json index e27cdb2a10e9e..f0c1205f7775a 100644 --- a/tests/aws/services/events/test_events_integrations.snapshot.json +++ b/tests/aws/services/events/test_events_targets.snapshot.json @@ -1,5 +1,5 @@ { - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_lambda_list_entry": { + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entry": { "recorded-date": "08-04-2024, 17:32:58", "recorded-content": { "events": [ @@ -47,7 +47,7 @@ ] } }, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_lambda_list_entries_partial_match": { + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entries_partial_match": { "recorded-date": "03-04-2024, 20:00:13", "recorded-content": { "events": [ @@ -101,7 +101,7 @@ ] } }, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sqs": { + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs": { "recorded-date": "26-04-2024, 08:43:27", "recorded-content": { "message": [ @@ -130,7 +130,7 @@ ] } }, - "tests/aws/services/events/test_events_integrations.py::test_put_events_with_target_sqs_event_detail_match": { + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs_event_detail_match": { "recorded-date": "07-05-2024, 10:40:38", "recorded-content": { "messages": [ diff --git a/tests/aws/services/events/test_events_targets.validation.json b/tests/aws/services/events/test_events_targets.validation.json new file mode 100644 index 0000000000000..0f85f5b3a5af8 --- /dev/null +++ b/tests/aws/services/events/test_events_targets.validation.json @@ -0,0 +1,17 @@ +{ + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entries_partial_match": { + "last_validated_date": "2024-04-08T17:36:24+00:00" + }, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entry": { + "last_validated_date": "2024-04-08T17:33:44+00:00" + }, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs": { + "last_validated_date": "2024-04-26T08:43:27+00:00" + }, + "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs_event_detail_match": { + "last_validated_date": "2024-05-07T10:40:38+00:00" + }, + "tests/aws/services/events/test_events_targets.py::test_should_ignore_schedules_for_put_event": { + "last_validated_date": "2024-03-26T15:51:47+00:00" + } +} From d2d0f6eb587baf4a5556ef2c9b830e99058e1a52 Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Tue, 18 Jun 2024 16:21:16 +0200 Subject: [PATCH 02/11] refactor: move sqs target tests to separate test class --- .../services/events/test_events_targets.py | 196 +++++++++--------- .../events/test_events_targets.snapshot.json | 4 +- .../test_events_targets.validation.json | 4 +- 3 files changed, 102 insertions(+), 102 deletions(-) diff --git a/tests/aws/services/events/test_events_targets.py b/tests/aws/services/events/test_events_targets.py index 2a492729ddc6b..ffd1c2b16ef28 100644 --- a/tests/aws/services/events/test_events_targets.py +++ b/tests/aws/services/events/test_events_targets.py @@ -18,104 +18,6 @@ from tests.aws.services.events.test_events import EVENT_DETAIL, TEST_EVENT_PATTERN from tests.aws.services.lambda_.test_lambda import TEST_LAMBDA_PYTHON_ECHO - -@markers.aws.validated -def test_put_events_with_target_sqs(put_events_with_filter_to_sqs, snapshot): - entries = [ - { - "Source": TEST_EVENT_PATTERN["source"][0], - "DetailType": TEST_EVENT_PATTERN["detail-type"][0], - "Detail": json.dumps(EVENT_DETAIL), - } - ] - message = put_events_with_filter_to_sqs( - pattern=TEST_EVENT_PATTERN, - entries_asserts=[(entries, True)], - ) - snapshot.add_transformers_list( - [ - snapshot.transform.key_value("ReceiptHandle", reference_replacement=False), - snapshot.transform.key_value("MD5OfBody", reference_replacement=False), - ], - ) - snapshot.match("message", message) - - -@markers.aws.unknown -@pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") -def test_put_events_with_target_sqs_new_region(aws_client_factory): - events_client = aws_client_factory(region_name="eu-west-1").events - queue_name = "queue-{}".format(short_uid()) - rule_name = "rule-{}".format(short_uid()) - target_id = "target-{}".format(short_uid()) - bus_name = "bus-{}".format(short_uid()) - - sqs_client = aws_client_factory(region_name="eu-west-1").sqs - sqs_client.create_queue(QueueName=queue_name) - queue_arn = arns.sqs_queue_arn(queue_name, TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME) - - events_client.create_event_bus(Name=bus_name) - - events_client.put_rule( - Name=rule_name, - EventBusName=bus_name, - EventPattern=json.dumps(TEST_EVENT_PATTERN), - ) - - events_client.put_targets( - Rule=rule_name, - EventBusName=bus_name, - Targets=[{"Id": target_id, "Arn": queue_arn}], - ) - - response = events_client.put_events( - Entries=[ - { - "Source": "com.mycompany.myapp", - "Detail": '{ "key1": "value1", "key": "value2" }', - "Resources": [], - "DetailType": "myDetailType", - } - ] - ) - assert "Entries" in response - assert len(response.get("Entries")) == 1 - assert "EventId" in response.get("Entries")[0] - - -@markers.aws.validated -@pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") -def test_put_events_with_target_sqs_event_detail_match(put_events_with_filter_to_sqs, snapshot): - entries1 = [ - { - "Source": TEST_EVENT_PATTERN["source"][0], - "DetailType": TEST_EVENT_PATTERN["detail-type"][0], - "Detail": json.dumps({"EventType": "1"}), - } - ] - entries2 = [ - { - "Source": TEST_EVENT_PATTERN["source"][0], - "DetailType": TEST_EVENT_PATTERN["detail-type"][0], - "Detail": json.dumps({"EventType": "2"}), - } - ] - entries_asserts = [(entries1, True), (entries2, False)] - messages = put_events_with_filter_to_sqs( - pattern={"detail": {"EventType": ["0", "1"]}}, - entries_asserts=entries_asserts, - input_path="$.detail", - ) - - snapshot.add_transformers_list( - [ - snapshot.transform.key_value("ReceiptHandle", reference_replacement=False), - snapshot.transform.key_value("MD5OfBody", reference_replacement=False), - ], - ) - snapshot.match("messages", messages) - - # TODO: further unify/parameterize the tests for the different target types below @@ -697,3 +599,101 @@ def assert_message(): # clean up clean_up(rule_name=rule_name, target_ids=target_id) + + +class TestTargetSqs: + @markers.aws.validated + def test_put_events_with_target_sqs(self, put_events_with_filter_to_sqs, snapshot): + entries = [ + { + "Source": TEST_EVENT_PATTERN["source"][0], + "DetailType": TEST_EVENT_PATTERN["detail-type"][0], + "Detail": json.dumps(EVENT_DETAIL), + } + ] + message = put_events_with_filter_to_sqs( + pattern=TEST_EVENT_PATTERN, + entries_asserts=[(entries, True)], + ) + snapshot.add_transformers_list( + [ + snapshot.transform.key_value("ReceiptHandle", reference_replacement=False), + snapshot.transform.key_value("MD5OfBody", reference_replacement=False), + ], + ) + snapshot.match("message", message) + + @markers.aws.unknown + @pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") + def test_put_events_with_target_sqs_new_region(self, aws_client_factory): + events_client = aws_client_factory(region_name="eu-west-1").events + queue_name = "queue-{}".format(short_uid()) + rule_name = "rule-{}".format(short_uid()) + target_id = "target-{}".format(short_uid()) + bus_name = "bus-{}".format(short_uid()) + + sqs_client = aws_client_factory(region_name="eu-west-1").sqs + sqs_client.create_queue(QueueName=queue_name) + queue_arn = arns.sqs_queue_arn(queue_name, TEST_AWS_ACCOUNT_ID, TEST_AWS_REGION_NAME) + + events_client.create_event_bus(Name=bus_name) + + events_client.put_rule( + Name=rule_name, + EventBusName=bus_name, + EventPattern=json.dumps(TEST_EVENT_PATTERN), + ) + + events_client.put_targets( + Rule=rule_name, + EventBusName=bus_name, + Targets=[{"Id": target_id, "Arn": queue_arn}], + ) + + response = events_client.put_events( + Entries=[ + { + "Source": "com.mycompany.myapp", + "Detail": '{ "key1": "value1", "key": "value2" }', + "Resources": [], + "DetailType": "myDetailType", + } + ] + ) + assert "Entries" in response + assert len(response.get("Entries")) == 1 + assert "EventId" in response.get("Entries")[0] + + @markers.aws.validated + @pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") + def test_put_events_with_target_sqs_event_detail_match( + self, put_events_with_filter_to_sqs, snapshot + ): + entries1 = [ + { + "Source": TEST_EVENT_PATTERN["source"][0], + "DetailType": TEST_EVENT_PATTERN["detail-type"][0], + "Detail": json.dumps({"EventType": "1"}), + } + ] + entries2 = [ + { + "Source": TEST_EVENT_PATTERN["source"][0], + "DetailType": TEST_EVENT_PATTERN["detail-type"][0], + "Detail": json.dumps({"EventType": "2"}), + } + ] + entries_asserts = [(entries1, True), (entries2, False)] + messages = put_events_with_filter_to_sqs( + pattern={"detail": {"EventType": ["0", "1"]}}, + entries_asserts=entries_asserts, + input_path="$.detail", + ) + + snapshot.add_transformers_list( + [ + snapshot.transform.key_value("ReceiptHandle", reference_replacement=False), + snapshot.transform.key_value("MD5OfBody", reference_replacement=False), + ], + ) + snapshot.match("messages", messages) diff --git a/tests/aws/services/events/test_events_targets.snapshot.json b/tests/aws/services/events/test_events_targets.snapshot.json index f0c1205f7775a..ec0450b183915 100644 --- a/tests/aws/services/events/test_events_targets.snapshot.json +++ b/tests/aws/services/events/test_events_targets.snapshot.json @@ -101,7 +101,7 @@ ] } }, - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs": { + "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs": { "recorded-date": "26-04-2024, 08:43:27", "recorded-content": { "message": [ @@ -130,7 +130,7 @@ ] } }, - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs_event_detail_match": { + "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs_event_detail_match": { "recorded-date": "07-05-2024, 10:40:38", "recorded-content": { "messages": [ diff --git a/tests/aws/services/events/test_events_targets.validation.json b/tests/aws/services/events/test_events_targets.validation.json index 0f85f5b3a5af8..01e7235683281 100644 --- a/tests/aws/services/events/test_events_targets.validation.json +++ b/tests/aws/services/events/test_events_targets.validation.json @@ -5,10 +5,10 @@ "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entry": { "last_validated_date": "2024-04-08T17:33:44+00:00" }, - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs": { + "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs": { "last_validated_date": "2024-04-26T08:43:27+00:00" }, - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_sqs_event_detail_match": { + "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs_event_detail_match": { "last_validated_date": "2024-05-07T10:40:38+00:00" }, "tests/aws/services/events/test_events_targets.py::test_should_ignore_schedules_for_put_event": { From 35d165ed879f2b99a603c1a8221818e1027f76df Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Tue, 18 Jun 2024 16:36:31 +0200 Subject: [PATCH 03/11] feat: remove skip for new provider --- .../services/events/test_events_targets.py | 3 +- .../events/test_events_targets.snapshot.json | 34 +++++++++---------- .../test_events_targets.validation.json | 12 +++---- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/tests/aws/services/events/test_events_targets.py b/tests/aws/services/events/test_events_targets.py index ffd1c2b16ef28..fccc07f5d5f7c 100644 --- a/tests/aws/services/events/test_events_targets.py +++ b/tests/aws/services/events/test_events_targets.py @@ -601,7 +601,7 @@ def assert_message(): clean_up(rule_name=rule_name, target_ids=target_id) -class TestTargetSqs: +class TestEventTargetSqs: @markers.aws.validated def test_put_events_with_target_sqs(self, put_events_with_filter_to_sqs, snapshot): entries = [ @@ -665,7 +665,6 @@ def test_put_events_with_target_sqs_new_region(self, aws_client_factory): assert "EventId" in response.get("Entries")[0] @markers.aws.validated - @pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") def test_put_events_with_target_sqs_event_detail_match( self, put_events_with_filter_to_sqs, snapshot ): diff --git a/tests/aws/services/events/test_events_targets.snapshot.json b/tests/aws/services/events/test_events_targets.snapshot.json index ec0450b183915..b1178c64a9810 100644 --- a/tests/aws/services/events/test_events_targets.snapshot.json +++ b/tests/aws/services/events/test_events_targets.snapshot.json @@ -101,8 +101,23 @@ ] } }, - "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs": { - "recorded-date": "26-04-2024, 08:43:27", + "tests/aws/services/events/test_events_targets.py::TestEventTargetSqs::test_put_events_with_target_sqs_event_detail_match": { + "recorded-date": "07-05-2024, 10:40:38", + "recorded-content": { + "messages": [ + { + "MessageId": "", + "ReceiptHandle": "receipt-handle", + "MD5OfBody": "m-d5-of-body", + "Body": { + "EventType": "1" + } + } + ] + } + }, + "tests/aws/services/events/test_events_targets.py::TestEventTargetSqs::test_put_events_with_target_sqs": { + "recorded-date": "18-06-2024, 14:34:29", "recorded-content": { "message": [ { @@ -129,20 +144,5 @@ } ] } - }, - "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs_event_detail_match": { - "recorded-date": "07-05-2024, 10:40:38", - "recorded-content": { - "messages": [ - { - "MessageId": "", - "ReceiptHandle": "receipt-handle", - "MD5OfBody": "m-d5-of-body", - "Body": { - "EventType": "1" - } - } - ] - } } } diff --git a/tests/aws/services/events/test_events_targets.validation.json b/tests/aws/services/events/test_events_targets.validation.json index 01e7235683281..84348a9e6b471 100644 --- a/tests/aws/services/events/test_events_targets.validation.json +++ b/tests/aws/services/events/test_events_targets.validation.json @@ -1,16 +1,16 @@ { + "tests/aws/services/events/test_events_targets.py::TestEventTargetSqs::test_put_events_with_target_sqs": { + "last_validated_date": "2024-06-18T14:34:29+00:00" + }, + "tests/aws/services/events/test_events_targets.py::TestEventTargetSqs::test_put_events_with_target_sqs_event_detail_match": { + "last_validated_date": "2024-05-07T10:40:38+00:00" + }, "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entries_partial_match": { "last_validated_date": "2024-04-08T17:36:24+00:00" }, "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entry": { "last_validated_date": "2024-04-08T17:33:44+00:00" }, - "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs": { - "last_validated_date": "2024-04-26T08:43:27+00:00" - }, - "tests/aws/services/events/test_events_targets.py::TestTargetSqs::test_put_events_with_target_sqs_event_detail_match": { - "last_validated_date": "2024-05-07T10:40:38+00:00" - }, "tests/aws/services/events/test_events_targets.py::test_should_ignore_schedules_for_put_event": { "last_validated_date": "2024-03-26T15:51:47+00:00" } From 914be0f8665efacf064d7096b3ff8d94d1fdf728 Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Tue, 18 Jun 2024 16:45:45 +0200 Subject: [PATCH 04/11] refactor: move test target lambda in separate class --- .../services/events/test_events_targets.py | 519 +++++++++--------- .../events/test_events_targets.snapshot.json | 4 +- .../test_events_targets.validation.json | 4 +- 3 files changed, 268 insertions(+), 259 deletions(-) diff --git a/tests/aws/services/events/test_events_targets.py b/tests/aws/services/events/test_events_targets.py index fccc07f5d5f7c..df3e24f4bf277 100644 --- a/tests/aws/services/events/test_events_targets.py +++ b/tests/aws/services/events/test_events_targets.py @@ -90,261 +90,6 @@ def test_put_events_with_target_sns( ) -@markers.aws.needs_fixing -def test_put_events_with_target_lambda(create_lambda_function, cleanups, aws_client, clean_up): - rule_name = f"rule-{short_uid()}" - function_name = f"lambda-func-{short_uid()}" - target_id = f"target-{short_uid()}" - bus_name = f"bus-{short_uid()}" - - # clean up - cleanups.append(lambda: aws_client.lambda_.delete_function(FunctionName=function_name)) - cleanups.append(lambda: clean_up(bus_name=bus_name, rule_name=rule_name, target_ids=target_id)) - - rs = create_lambda_function( - handler_file=TEST_LAMBDA_PYTHON_ECHO, - func_name=function_name, - runtime=Runtime.python3_9, - ) - - func_arn = rs["CreateFunctionResponse"]["FunctionArn"] - - aws_client.events.create_event_bus(Name=bus_name) - aws_client.events.put_rule( - Name=rule_name, - EventBusName=bus_name, - EventPattern=json.dumps(TEST_EVENT_PATTERN), - ) - rs = aws_client.events.put_targets( - Rule=rule_name, - EventBusName=bus_name, - Targets=[{"Id": target_id, "Arn": func_arn}], - ) - - assert "FailedEntryCount" in rs - assert "FailedEntries" in rs - assert rs["FailedEntryCount"] == 0 - assert rs["FailedEntries"] == [] - - aws_client.events.put_events( - Entries=[ - { - "EventBusName": bus_name, - "Source": TEST_EVENT_PATTERN["source"][0], - "DetailType": TEST_EVENT_PATTERN["detail-type"][0], - "Detail": json.dumps(EVENT_DETAIL), - } - ] - ) - - # Get lambda's log events - events = retry( - check_expected_lambda_log_events_length, - retries=3, - sleep=1, - function_name=function_name, - expected_length=1, - logs_client=aws_client.logs, - ) - actual_event = events[0] - assert_valid_event(actual_event) - assert actual_event["detail"] == EVENT_DETAIL - - -@markers.aws.validated -def test_put_events_with_target_lambda_list_entry( - create_lambda_function, cleanups, aws_client, clean_up, snapshot -): - rule_name = f"rule-{short_uid()}" - function_name = f"lambda-func-{short_uid()}" - target_id = f"target-{short_uid()}" - bus_name = f"bus-{short_uid()}" - - # clean up - cleanups.append(lambda: clean_up(bus_name=bus_name, rule_name=rule_name, target_ids=target_id)) - - create_lambda_response = create_lambda_function( - handler_file=TEST_LAMBDA_PYTHON_ECHO, - func_name=function_name, - runtime=Runtime.python3_12, - ) - - func_arn = create_lambda_response["CreateFunctionResponse"]["FunctionArn"] - - event_pattern = {"detail": {"payload": {"automations": {"id": [{"exists": True}]}}}} - - aws_client.events.create_event_bus(Name=bus_name) - put_rule_response = aws_client.events.put_rule( - Name=rule_name, - EventBusName=bus_name, - EventPattern=json.dumps(event_pattern), - ) - aws_client.lambda_.add_permission( - FunctionName=function_name, - StatementId=f"{rule_name}-Event", - Action="lambda:InvokeFunction", - Principal="events.amazonaws.com", - SourceArn=put_rule_response["RuleArn"], - ) - put_target_response = aws_client.events.put_targets( - Rule=rule_name, - EventBusName=bus_name, - Targets=[{"Id": target_id, "Arn": func_arn}], - ) - - assert "FailedEntryCount" in put_target_response - assert "FailedEntries" in put_target_response - assert put_target_response["FailedEntryCount"] == 0 - assert put_target_response["FailedEntries"] == [] - - event_detail = { - "payload": { - "userId": 10, - "businessId": 3, - "channelId": 6, - "card": {"foo": "bar"}, - "targetEntity": True, - "entityAuditTrailEvent": {"foo": "bar"}, - "automations": [ - { - "id": "123", - "actions": [ - { - "id": "321", - "type": "SEND_NOTIFICATION", - "settings": { - "message": "", - "recipientEmails": [], - "subject": "", - "type": "SEND_NOTIFICATION", - }, - } - ], - } - ], - } - } - aws_client.events.put_events( - Entries=[ - { - "EventBusName": bus_name, - "Source": TEST_EVENT_PATTERN["source"][0], - "DetailType": TEST_EVENT_PATTERN["detail-type"][0], - "Detail": json.dumps(event_detail), - } - ] - ) - - # Get lambda's log events - events = retry( - check_expected_lambda_log_events_length, - retries=15, - sleep=1, - function_name=function_name, - expected_length=1, - logs_client=aws_client.logs, - ) - snapshot.match("events", events) - - -@markers.aws.validated -def test_put_events_with_target_lambda_list_entries_partial_match( - create_lambda_function, cleanups, aws_client, clean_up, snapshot -): - rule_name = f"rule-{short_uid()}" - function_name = f"lambda-func-{short_uid()}" - target_id = f"target-{short_uid()}" - bus_name = f"bus-{short_uid()}" - - # clean up - cleanups.append(lambda: clean_up(bus_name=bus_name, rule_name=rule_name, target_ids=target_id)) - - rs = create_lambda_function( - handler_file=TEST_LAMBDA_PYTHON_ECHO, - func_name=function_name, - runtime=Runtime.python3_12, - ) - - func_arn = rs["CreateFunctionResponse"]["FunctionArn"] - - event_pattern = {"detail": {"payload": {"automations": {"id": [{"exists": True}]}}}} - - aws_client.events.create_event_bus(Name=bus_name) - rs = aws_client.events.put_rule( - Name=rule_name, - EventBusName=bus_name, - EventPattern=json.dumps(event_pattern), - ) - aws_client.lambda_.add_permission( - FunctionName=function_name, - StatementId=f"{rule_name}-Event", - Action="lambda:InvokeFunction", - Principal="events.amazonaws.com", - SourceArn=rs["RuleArn"], - ) - rs = aws_client.events.put_targets( - Rule=rule_name, - EventBusName=bus_name, - Targets=[{"Id": target_id, "Arn": func_arn}], - ) - - assert "FailedEntryCount" in rs - assert "FailedEntries" in rs - assert rs["FailedEntryCount"] == 0 - assert rs["FailedEntries"] == [] - - event_detail_partial_match = { - "payload": { - "userId": 10, - "businessId": 3, - "channelId": 6, - "card": {"foo": "bar"}, - "targetEntity": True, - "entityAuditTrailEvent": {"foo": "bar"}, - "automations": [ - {"foo": "bar"}, - { - "id": "123", - "actions": [ - { - "id": "321", - "type": "SEND_NOTIFICATION", - "settings": { - "message": "", - "recipientEmails": [], - "subject": "", - "type": "SEND_NOTIFICATION", - }, - } - ], - }, - {"bar": "foo"}, - ], - } - } - aws_client.events.put_events( - Entries=[ - { - "EventBusName": bus_name, - "Source": TEST_EVENT_PATTERN["source"][0], - "DetailType": TEST_EVENT_PATTERN["detail-type"][0], - "Detail": json.dumps(event_detail_partial_match), - }, - ] - ) - - # Get lambda's log events - events = retry( - check_expected_lambda_log_events_length, - retries=15, - sleep=1, - function_name=function_name, - expected_length=1, - logs_client=aws_client.logs, - ) - snapshot.match("events", events) - - @markers.aws.validated @pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") def test_should_ignore_schedules_for_put_event(create_lambda_function, cleanups, aws_client): @@ -601,6 +346,270 @@ def assert_message(): clean_up(rule_name=rule_name, target_ids=target_id) +class TestEventTargetLambda: + @markers.aws.needs_fixing + def test_put_events_with_target_lambda( + self, + create_lambda_function, + cleanups, + events_create_event_bus, + events_put_rule, + aws_client, + ): + rule_name = f"rule-{short_uid()}" + function_name = f"lambda-func-{short_uid()}" + target_id = f"target-{short_uid()}" + bus_name = f"bus-{short_uid()}" + + # clean up + cleanups.append(lambda: aws_client.lambda_.delete_function(FunctionName=function_name)) + + rs = create_lambda_function( + handler_file=TEST_LAMBDA_PYTHON_ECHO, + func_name=function_name, + runtime=Runtime.python3_9, + ) + + func_arn = rs["CreateFunctionResponse"]["FunctionArn"] + + events_create_event_bus(Name=bus_name) + events_put_rule( + Name=rule_name, + EventBusName=bus_name, + EventPattern=json.dumps(TEST_EVENT_PATTERN), + ) + rs = aws_client.events.put_targets( + Rule=rule_name, + EventBusName=bus_name, + Targets=[{"Id": target_id, "Arn": func_arn}], + ) + + assert "FailedEntryCount" in rs + assert "FailedEntries" in rs + assert rs["FailedEntryCount"] == 0 + assert rs["FailedEntries"] == [] + + aws_client.events.put_events( + Entries=[ + { + "EventBusName": bus_name, + "Source": TEST_EVENT_PATTERN["source"][0], + "DetailType": TEST_EVENT_PATTERN["detail-type"][0], + "Detail": json.dumps(EVENT_DETAIL), + } + ] + ) + + # Get lambda's log events + events = retry( + check_expected_lambda_log_events_length, + retries=3, + sleep=1, + function_name=function_name, + expected_length=1, + logs_client=aws_client.logs, + ) + actual_event = events[0] + assert_valid_event(actual_event) + assert actual_event["detail"] == EVENT_DETAIL + + @markers.aws.validated + def test_put_events_with_target_lambda_list_entry( + self, create_lambda_function, cleanups, aws_client, clean_up, snapshot + ): + rule_name = f"rule-{short_uid()}" + function_name = f"lambda-func-{short_uid()}" + target_id = f"target-{short_uid()}" + bus_name = f"bus-{short_uid()}" + + # clean up + cleanups.append( + lambda: clean_up(bus_name=bus_name, rule_name=rule_name, target_ids=target_id) + ) + + create_lambda_response = create_lambda_function( + handler_file=TEST_LAMBDA_PYTHON_ECHO, + func_name=function_name, + runtime=Runtime.python3_12, + ) + + func_arn = create_lambda_response["CreateFunctionResponse"]["FunctionArn"] + + event_pattern = {"detail": {"payload": {"automations": {"id": [{"exists": True}]}}}} + + aws_client.events.create_event_bus(Name=bus_name) + put_rule_response = aws_client.events.put_rule( + Name=rule_name, + EventBusName=bus_name, + EventPattern=json.dumps(event_pattern), + ) + aws_client.lambda_.add_permission( + FunctionName=function_name, + StatementId=f"{rule_name}-Event", + Action="lambda:InvokeFunction", + Principal="events.amazonaws.com", + SourceArn=put_rule_response["RuleArn"], + ) + put_target_response = aws_client.events.put_targets( + Rule=rule_name, + EventBusName=bus_name, + Targets=[{"Id": target_id, "Arn": func_arn}], + ) + + assert "FailedEntryCount" in put_target_response + assert "FailedEntries" in put_target_response + assert put_target_response["FailedEntryCount"] == 0 + assert put_target_response["FailedEntries"] == [] + + event_detail = { + "payload": { + "userId": 10, + "businessId": 3, + "channelId": 6, + "card": {"foo": "bar"}, + "targetEntity": True, + "entityAuditTrailEvent": {"foo": "bar"}, + "automations": [ + { + "id": "123", + "actions": [ + { + "id": "321", + "type": "SEND_NOTIFICATION", + "settings": { + "message": "", + "recipientEmails": [], + "subject": "", + "type": "SEND_NOTIFICATION", + }, + } + ], + } + ], + } + } + aws_client.events.put_events( + Entries=[ + { + "EventBusName": bus_name, + "Source": TEST_EVENT_PATTERN["source"][0], + "DetailType": TEST_EVENT_PATTERN["detail-type"][0], + "Detail": json.dumps(event_detail), + } + ] + ) + + # Get lambda's log events + events = retry( + check_expected_lambda_log_events_length, + retries=15, + sleep=1, + function_name=function_name, + expected_length=1, + logs_client=aws_client.logs, + ) + snapshot.match("events", events) + + @markers.aws.validated + def test_put_events_with_target_lambda_list_entries_partial_match( + self, create_lambda_function, cleanups, aws_client, clean_up, snapshot + ): + rule_name = f"rule-{short_uid()}" + function_name = f"lambda-func-{short_uid()}" + target_id = f"target-{short_uid()}" + bus_name = f"bus-{short_uid()}" + + # clean up + cleanups.append( + lambda: clean_up(bus_name=bus_name, rule_name=rule_name, target_ids=target_id) + ) + + rs = create_lambda_function( + handler_file=TEST_LAMBDA_PYTHON_ECHO, + func_name=function_name, + runtime=Runtime.python3_12, + ) + + func_arn = rs["CreateFunctionResponse"]["FunctionArn"] + + event_pattern = {"detail": {"payload": {"automations": {"id": [{"exists": True}]}}}} + + aws_client.events.create_event_bus(Name=bus_name) + rs = aws_client.events.put_rule( + Name=rule_name, + EventBusName=bus_name, + EventPattern=json.dumps(event_pattern), + ) + aws_client.lambda_.add_permission( + FunctionName=function_name, + StatementId=f"{rule_name}-Event", + Action="lambda:InvokeFunction", + Principal="events.amazonaws.com", + SourceArn=rs["RuleArn"], + ) + rs = aws_client.events.put_targets( + Rule=rule_name, + EventBusName=bus_name, + Targets=[{"Id": target_id, "Arn": func_arn}], + ) + + assert "FailedEntryCount" in rs + assert "FailedEntries" in rs + assert rs["FailedEntryCount"] == 0 + assert rs["FailedEntries"] == [] + + event_detail_partial_match = { + "payload": { + "userId": 10, + "businessId": 3, + "channelId": 6, + "card": {"foo": "bar"}, + "targetEntity": True, + "entityAuditTrailEvent": {"foo": "bar"}, + "automations": [ + {"foo": "bar"}, + { + "id": "123", + "actions": [ + { + "id": "321", + "type": "SEND_NOTIFICATION", + "settings": { + "message": "", + "recipientEmails": [], + "subject": "", + "type": "SEND_NOTIFICATION", + }, + } + ], + }, + {"bar": "foo"}, + ], + } + } + aws_client.events.put_events( + Entries=[ + { + "EventBusName": bus_name, + "Source": TEST_EVENT_PATTERN["source"][0], + "DetailType": TEST_EVENT_PATTERN["detail-type"][0], + "Detail": json.dumps(event_detail_partial_match), + }, + ] + ) + + # Get lambda's log events + events = retry( + check_expected_lambda_log_events_length, + retries=15, + sleep=1, + function_name=function_name, + expected_length=1, + logs_client=aws_client.logs, + ) + snapshot.match("events", events) + + class TestEventTargetSqs: @markers.aws.validated def test_put_events_with_target_sqs(self, put_events_with_filter_to_sqs, snapshot): diff --git a/tests/aws/services/events/test_events_targets.snapshot.json b/tests/aws/services/events/test_events_targets.snapshot.json index b1178c64a9810..ff08ce08a91c6 100644 --- a/tests/aws/services/events/test_events_targets.snapshot.json +++ b/tests/aws/services/events/test_events_targets.snapshot.json @@ -1,5 +1,5 @@ { - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entry": { + "tests/aws/services/events/test_events_targets.py::TestEventTargetLambda::test_put_events_with_target_lambda_list_entry": { "recorded-date": "08-04-2024, 17:32:58", "recorded-content": { "events": [ @@ -47,7 +47,7 @@ ] } }, - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entries_partial_match": { + "tests/aws/services/events/test_events_targets.py::TestEventTargetLambda::test_put_events_with_target_lambda_list_entries_partial_match": { "recorded-date": "03-04-2024, 20:00:13", "recorded-content": { "events": [ diff --git a/tests/aws/services/events/test_events_targets.validation.json b/tests/aws/services/events/test_events_targets.validation.json index 84348a9e6b471..6ca0fd0eefc33 100644 --- a/tests/aws/services/events/test_events_targets.validation.json +++ b/tests/aws/services/events/test_events_targets.validation.json @@ -5,10 +5,10 @@ "tests/aws/services/events/test_events_targets.py::TestEventTargetSqs::test_put_events_with_target_sqs_event_detail_match": { "last_validated_date": "2024-05-07T10:40:38+00:00" }, - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entries_partial_match": { + "tests/aws/services/events/test_events_targets.py::TestEventTargetLambda::test_put_events_with_target_lambda_list_entries_partial_match": { "last_validated_date": "2024-04-08T17:36:24+00:00" }, - "tests/aws/services/events/test_events_targets.py::test_put_events_with_target_lambda_list_entry": { + "tests/aws/services/events/test_events_targets.py::TestEventTargetLambda::test_put_events_with_target_lambda_list_entry": { "last_validated_date": "2024-04-08T17:33:44+00:00" }, "tests/aws/services/events/test_events_targets.py::test_should_ignore_schedules_for_put_event": { From ec063b825aff802efdb5771c1891e8365a474583 Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Tue, 18 Jun 2024 16:51:15 +0200 Subject: [PATCH 05/11] refactor: move schedule test to schedule test file --- .../services/events/test_events_schedule.py | 58 +++++++++++++++++++ .../test_events_schedule.validation.json | 3 + .../services/events/test_events_targets.py | 50 ---------------- .../test_events_targets.validation.json | 3 - 4 files changed, 61 insertions(+), 53 deletions(-) diff --git a/tests/aws/services/events/test_events_schedule.py b/tests/aws/services/events/test_events_schedule.py index 3594ac38f76ae..2e872df82ebbd 100644 --- a/tests/aws/services/events/test_events_schedule.py +++ b/tests/aws/services/events/test_events_schedule.py @@ -5,6 +5,7 @@ import pytest from botocore.exceptions import ClientError +from localstack.aws.api.lambda_ import Runtime from localstack.testing.aws.eventbus_utils import trigger_scheduled_rule from localstack.testing.pytest import markers from localstack.testing.snapshots.transformer_utility import TransformerUtility @@ -13,8 +14,10 @@ from tests.aws.services.events.helper_functions import ( events_time_string_to_timestamp, get_cron_expression, + is_v2_provider, sqs_collect_messages, ) +from tests.aws.services.lambda_.test_lambda import TEST_LAMBDA_PYTHON_ECHO class TestScheduleRate: @@ -267,6 +270,61 @@ def _get_events(): snapshot.match("log-events", events) + @markers.aws.validated + @pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") + def test_should_ignore_schedules_for_put_event( + self, create_lambda_function, cleanups, aws_client + ): + """Regression test for https://github.com/localstack/localstack/issues/7847""" + fn_name = f"test-event-fn-{short_uid()}" + create_lambda_function( + func_name=fn_name, + handler_file=TEST_LAMBDA_PYTHON_ECHO, + runtime=Runtime.python3_9, + client=aws_client.lambda_, + ) + + aws_client.lambda_.add_permission( + FunctionName=fn_name, + StatementId="AllowFnInvokeStatement", + Action="lambda:InvokeFunction", + Principal="events.amazonaws.com", + ) + + fn_arn = aws_client.lambda_.get_function(FunctionName=fn_name)["Configuration"][ + "FunctionArn" + ] + aws_client.events.put_rule( + Name="ScheduledLambda", ScheduleExpression="rate(1 minute)" + ) # every minute, can't go lower than that + cleanups.append(lambda: aws_client.events.delete_rule(Name="ScheduledLambda")) + aws_client.events.put_targets( + Rule="ScheduledLambda", Targets=[{"Id": "calllambda1", "Arn": fn_arn}] + ) + cleanups.append( + lambda: aws_client.events.remove_targets(Rule="ScheduledLambda", Ids=["calllambda1"]) + ) + + aws_client.events.put_events( + Entries=[ + { + "Source": "MySource", + "DetailType": "CustomType", + "Detail": json.dumps({"message": "manually invoked"}), + } + ] + ) + + def check_invocation(): + events_after = aws_client.logs.filter_log_events(logGroupName=f"/aws/lambda/{fn_name}") + # the custom sent event should NOT trigger the lambda (!) + assert len([e for e in events_after["events"] if "START" in e["message"]]) >= 1 + assert ( + len([e for e in events_after["events"] if "manually invoked" in e["message"]]) == 0 + ) + + retry(check_invocation, sleep=5, retries=15) + class TestScheduleCron: @markers.aws.validated diff --git a/tests/aws/services/events/test_events_schedule.validation.json b/tests/aws/services/events/test_events_schedule.validation.json index a21ca78f556dd..36ce7e905bad9 100644 --- a/tests/aws/services/events/test_events_schedule.validation.json +++ b/tests/aws/services/events/test_events_schedule.validation.json @@ -86,6 +86,9 @@ "tests/aws/services/events/test_events_schedule.py::TestScheduleRate::test_put_rule_with_schedule_rate": { "last_validated_date": "2024-05-14T11:23:22+00:00" }, + "tests/aws/services/events/test_events_schedule.py::TestScheduleRate::test_should_ignore_schedules_for_put_event": { + "last_validated_date": "2024-06-18T14:50:01+00:00" + }, "tests/aws/services/events/test_events_schedule.py::TestScheduleRate::tests_put_rule_with_schedule_custom_event_bus": { "last_validated_date": "2024-05-14T11:38:21+00:00" }, diff --git a/tests/aws/services/events/test_events_targets.py b/tests/aws/services/events/test_events_targets.py index df3e24f4bf277..440f8dc502a15 100644 --- a/tests/aws/services/events/test_events_targets.py +++ b/tests/aws/services/events/test_events_targets.py @@ -90,56 +90,6 @@ def test_put_events_with_target_sns( ) -@markers.aws.validated -@pytest.mark.skipif(is_v2_provider(), reason="V2 provider does not support this feature yet") -def test_should_ignore_schedules_for_put_event(create_lambda_function, cleanups, aws_client): - """Regression test for https://github.com/localstack/localstack/issues/7847""" - fn_name = f"test-event-fn-{short_uid()}" - create_lambda_function( - func_name=fn_name, - handler_file=TEST_LAMBDA_PYTHON_ECHO, - runtime=Runtime.python3_9, - client=aws_client.lambda_, - ) - - aws_client.lambda_.add_permission( - FunctionName=fn_name, - StatementId="AllowFnInvokeStatement", - Action="lambda:InvokeFunction", - Principal="events.amazonaws.com", - ) - - fn_arn = aws_client.lambda_.get_function(FunctionName=fn_name)["Configuration"]["FunctionArn"] - aws_client.events.put_rule( - Name="ScheduledLambda", ScheduleExpression="rate(1 minute)" - ) # every minute, can't go lower than that - cleanups.append(lambda: aws_client.events.delete_rule(Name="ScheduledLambda")) - aws_client.events.put_targets( - Rule="ScheduledLambda", Targets=[{"Id": "calllambda1", "Arn": fn_arn}] - ) - cleanups.append( - lambda: aws_client.events.remove_targets(Rule="ScheduledLambda", Ids=["calllambda1"]) - ) - - aws_client.events.put_events( - Entries=[ - { - "Source": "MySource", - "DetailType": "CustomType", - "Detail": json.dumps({"message": "manually invoked"}), - } - ] - ) - - def check_invocation(): - events_after = aws_client.logs.filter_log_events(logGroupName=f"/aws/lambda/{fn_name}") - # the custom sent event should NOT trigger the lambda (!) - assert len([e for e in events_after["events"] if "START" in e["message"]]) >= 1 - assert len([e for e in events_after["events"] if "manually invoked" in e["message"]]) == 0 - - retry(check_invocation, sleep=5, retries=15) - - @markers.aws.needs_fixing def test_put_events_with_target_firehose(aws_client, clean_up): s3_bucket = "s3-{}".format(short_uid()) diff --git a/tests/aws/services/events/test_events_targets.validation.json b/tests/aws/services/events/test_events_targets.validation.json index 6ca0fd0eefc33..3efe7cdd43b6f 100644 --- a/tests/aws/services/events/test_events_targets.validation.json +++ b/tests/aws/services/events/test_events_targets.validation.json @@ -10,8 +10,5 @@ }, "tests/aws/services/events/test_events_targets.py::TestEventTargetLambda::test_put_events_with_target_lambda_list_entry": { "last_validated_date": "2024-04-08T17:33:44+00:00" - }, - "tests/aws/services/events/test_events_targets.py::test_should_ignore_schedules_for_put_event": { - "last_validated_date": "2024-03-26T15:51:47+00:00" } } From aba4f02fd3b95f8b47fa13faf89a3f9d0600ec85 Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Wed, 19 Jun 2024 11:16:29 +0200 Subject: [PATCH 06/11] feat: add test create connection --- tests/aws/services/events/conftest.py | 18 +++++++++++++ tests/aws/services/events/test_events.py | 25 +++++++++++++++++++ .../services/events/test_events.snapshot.json | 15 +++++++++++ .../events/test_events.validation.json | 3 +++ 4 files changed, 61 insertions(+) diff --git a/tests/aws/services/events/conftest.py b/tests/aws/services/events/conftest.py index 9c2692b8e3d9d..4b1113412e00c 100644 --- a/tests/aws/services/events/conftest.py +++ b/tests/aws/services/events/conftest.py @@ -416,3 +416,21 @@ def _add_resource_policy_logs_events_access(log_group_arn: str): for policy_name in policies: aws_client.logs.delete_resource_policy(policyName=policy_name) + + +@pytest.fixture +def events_create_connection(aws_client): + connections = [] + + def _create_connection(**kwargs): + response = aws_client.events.create_connection(**kwargs) + connections.append(kwargs["Name"]) + return response + + yield _create_connection + + for connection in connections: + try: + aws_client.events.delete_connection(ConnectionArn=connection) + except Exception as e: + LOG.warning(f"Failed to delete connection {connection}: {e}") diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index e8d2d8512fe84..cfd12a8ad21d6 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -1347,3 +1347,28 @@ def test_put_target_id_validation( {"Id": target_id, "Arn": queue_arn, "InputPath": "$.detail"}, ], ) + + +class TestConnection: + @markers.aws.validated + def test_create_list_describe_update_delete_connection( + self, events_create_connection, snapshot + ): + connection_name = f"test-connection-{short_uid()}" + response = events_create_connection( + Name=connection_name, + Description="test description", + AuthorizationType="API_KEY", + AuthParameters={"ApiKeyAuthParameters": {"ApiKeyName": "test", "ApiKeyValue": "test"}}, + ) + + snapshot.add_transformer(snapshot.transform.regex(connection_name, "")) + snapshot.match("create-connection", response) + + @markers.aws.validated + def test_list_connections_with_prefix(self, aws_client): + pass + + @markers.aws.validated + def test_list_connections_with_limit(self, aws_client): + pass diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index 424fa08196021..39653bbad00fb 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1208,5 +1208,20 @@ } } } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection": { + "recorded-date": "18-06-2024, 15:29:18", + "recorded-content": { + "create-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//ebe99901-153c-495a-b8c5-7f789a0bb127", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } } } diff --git a/tests/aws/services/events/test_events.validation.json b/tests/aws/services/events/test_events.validation.json index dd22b7d3333c7..e131e0e0a28a1 100644 --- a/tests/aws/services/events/test_events.validation.json +++ b/tests/aws/services/events/test_events.validation.json @@ -1,4 +1,7 @@ { + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection": { + "last_validated_date": "2024-06-18T15:29:18+00:00" + }, "tests/aws/services/events/test_events.py::TestEventBus::test_create_list_describe_delete_custom_event_buses[regions0]": { "last_validated_date": "2024-04-29T13:15:44+00:00" }, From 113e57f6376caf03f5475ae882d08fa25ad4177b Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Wed, 19 Jun 2024 15:51:07 +0200 Subject: [PATCH 07/11] feat: add test create connection --- tests/aws/services/events/test_events.py | 92 ++++++++++++++++++- .../services/events/test_events.snapshot.json | 90 ++++++++++++++++++ .../events/test_events.validation.json | 18 ++++ 3 files changed, 196 insertions(+), 4 deletions(-) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index cfd12a8ad21d6..284323d6b5453 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -83,6 +83,14 @@ } } +API_CONNECTION_TEST_PASSWORD = "test_pw_1984%&" +API_CONNECTION_TEST_USERNAME = "test_user_1984" + +API_CONNECTION_TEST_KEY_NAME = "test_key_1984" +API_CONNECTION_TEST_KEY_VALUE = "test_value_1984" + +OAUTH_PLAYGROUND_URL = "https://oauth.pstmn.io/v1/callback" + class TestEvents: @markers.aws.validated @@ -1351,18 +1359,94 @@ def test_put_target_id_validation( class TestConnection: @markers.aws.validated + @pytest.mark.parametrize("auth_type", ["BASIC", "OAUTH_CLIENT_CREDENTIALS", "API_KEY"]) + @pytest.mark.parametrize("invocation_parameters", [True, False]) def test_create_list_describe_update_delete_connection( - self, events_create_connection, snapshot + self, auth_type, invocation_parameters, events_create_connection, snapshot ): + # Specify auth parameters + if auth_type == "BASIC": + auth_parameters = { + "BasicAuthParameters": { + "Username": API_CONNECTION_TEST_USERNAME, + "Password": API_CONNECTION_TEST_PASSWORD, + } + } + if auth_type == "OAUTH_CLIENT_CREDENTIALS": + auth_parameters = { + "OAuthParameters": { + "ClientParameters": {"ClientID": "string", "ClientSecret": "string"}, + "AuthorizationEndpoint": OAUTH_PLAYGROUND_URL, + "HttpMethod": "PUT", # TODO test "GET" | "POST" + "OAuthHttpParameters": { + "HeaderParameters": [ + { + "Key": "Content_Type", + "Value": "'application/x-www-form-urlencoded'", + "IsValueSecret": False, + }, + ], + "QueryStringParameters": [ + { + "Key": "some_test_key", + "Value": "some_test_value", + "IsValueSecret": False, + }, + ], + "BodyParameters": [ + {"Key": "grant_type", "Value": "string", "IsValueSecret": True}, + { + "Key": "user", + "Value": API_CONNECTION_TEST_USERNAME, + "IsValueSecret": True, + }, + { + "Key": "password", + "Value": API_CONNECTION_TEST_PASSWORD, + "IsValueSecret": True, + }, + ], + }, + } + } + if auth_type == "API_KEY": + auth_parameters = { + "ApiKeyAuthParameters": { + "ApiKeyName": API_CONNECTION_TEST_KEY_NAME, + "ApiKeyValue": API_CONNECTION_TEST_KEY_VALUE, + } + } + + # Specify invocation parameters + if invocation_parameters: + invocation_http_parameters = { + "HeaderParameters": [ + {"Key": "string", "Value": "string", "IsValueSecret": True}, + ], + "QueryStringParameters": [ + {"Key": "string", "Value": "string", "IsValueSecret": False}, + ], + "BodyParameters": [ + {"Key": "string", "Value": "string", "IsValueSecret": True}, + ], + } + auth_parameters["InvocationHttpParameters"] = invocation_http_parameters + connection_name = f"test-connection-{short_uid()}" response = events_create_connection( Name=connection_name, Description="test description", - AuthorizationType="API_KEY", - AuthParameters={"ApiKeyAuthParameters": {"ApiKeyName": "test", "ApiKeyValue": "test"}}, + AuthorizationType=auth_type, + AuthParameters=auth_parameters, ) + connection_arn_id = response["ConnectionArn"].split("/")[-1] - snapshot.add_transformer(snapshot.transform.regex(connection_name, "")) + snapshot.add_transformers_list( + [ + snapshot.transform.regex(connection_name, ""), + snapshot.transform.regex(connection_arn_id, ""), + ] + ) snapshot.match("create-connection", response) @markers.aws.validated diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index 39653bbad00fb..3f2ca5aac310a 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1223,5 +1223,95 @@ } } } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-BASIC]": { + "recorded-date": "19-06-2024, 13:50:29", + "recorded-content": { + "create-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-OAUTH_CLIENT_CREDENTIALS]": { + "recorded-date": "19-06-2024, 13:50:29", + "recorded-content": { + "create-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZING", + "CreationTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-API_KEY]": { + "recorded-date": "19-06-2024, 13:50:29", + "recorded-content": { + "create-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-BASIC]": { + "recorded-date": "19-06-2024, 13:50:30", + "recorded-content": { + "create-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-OAUTH_CLIENT_CREDENTIALS]": { + "recorded-date": "19-06-2024, 13:50:30", + "recorded-content": { + "create-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZING", + "CreationTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-API_KEY]": { + "recorded-date": "19-06-2024, 13:50:31", + "recorded-content": { + "create-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } } } diff --git a/tests/aws/services/events/test_events.validation.json b/tests/aws/services/events/test_events.validation.json index e131e0e0a28a1..d02a6f656007b 100644 --- a/tests/aws/services/events/test_events.validation.json +++ b/tests/aws/services/events/test_events.validation.json @@ -2,6 +2,24 @@ "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection": { "last_validated_date": "2024-06-18T15:29:18+00:00" }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-API_KEY]": { + "last_validated_date": "2024-06-19T13:50:31+00:00" + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-BASIC]": { + "last_validated_date": "2024-06-19T13:50:30+00:00" + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-OAUTH_CLIENT_CREDENTIALS]": { + "last_validated_date": "2024-06-19T13:50:30+00:00" + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-API_KEY]": { + "last_validated_date": "2024-06-19T13:50:29+00:00" + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-BASIC]": { + "last_validated_date": "2024-06-19T13:50:29+00:00" + }, + "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-OAUTH_CLIENT_CREDENTIALS]": { + "last_validated_date": "2024-06-19T13:50:29+00:00" + }, "tests/aws/services/events/test_events.py::TestEventBus::test_create_list_describe_delete_custom_event_buses[regions0]": { "last_validated_date": "2024-04-29T13:15:44+00:00" }, From bd067a180e59041da09f609ace516212fc36583e Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Wed, 19 Jun 2024 16:10:17 +0200 Subject: [PATCH 08/11] feat: extend test list describe delete connection --- tests/aws/services/events/helper_functions.py | 11 + tests/aws/services/events/test_events.py | 36 +- .../services/events/test_events.snapshot.json | 473 +++++++++++++++++- .../events/test_events.validation.json | 12 +- 4 files changed, 518 insertions(+), 14 deletions(-) diff --git a/tests/aws/services/events/helper_functions.py b/tests/aws/services/events/helper_functions.py index 68856d4d636f1..048b6ea031b02 100644 --- a/tests/aws/services/events/helper_functions.py +++ b/tests/aws/services/events/helper_functions.py @@ -70,3 +70,14 @@ def collect_events() -> None: retry(collect_events, retries=retries, sleep=0.01) return events + + +def events_connection_wait_for_deleted(aws_client, connection_name: str) -> None: + def _wait_for_deleted(): + try: + aws_client.events.describe_connection(Name=connection_name) + except aws_client.events.exceptions.ResourceNotFoundException: + return + raise AssertionError(f"Connection {connection_name} was not deleted") + + retry(_wait_for_deleted, retries=3, sleep=1) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index 284323d6b5453..156b443eec656 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -24,6 +24,7 @@ from localstack.utils.sync import poll_condition, retry from tests.aws.services.events.conftest import assert_valid_event from tests.aws.services.events.helper_functions import ( + events_connection_wait_for_deleted, is_old_provider, is_v2_provider, sqs_collect_messages, @@ -1362,7 +1363,12 @@ class TestConnection: @pytest.mark.parametrize("auth_type", ["BASIC", "OAUTH_CLIENT_CREDENTIALS", "API_KEY"]) @pytest.mark.parametrize("invocation_parameters", [True, False]) def test_create_list_describe_update_delete_connection( - self, auth_type, invocation_parameters, events_create_connection, snapshot + self, + auth_type, + invocation_parameters, + events_create_connection, + aws_client, + snapshot, ): # Specify auth parameters if auth_type == "BASIC": @@ -1432,6 +1438,7 @@ def test_create_list_describe_update_delete_connection( } auth_parameters["InvocationHttpParameters"] = invocation_http_parameters + # Test create connection connection_name = f"test-connection-{short_uid()}" response = events_create_connection( Name=connection_name, @@ -1439,7 +1446,8 @@ def test_create_list_describe_update_delete_connection( AuthorizationType=auth_type, AuthParameters=auth_parameters, ) - connection_arn_id = response["ConnectionArn"].split("/")[-1] + connection_arn = response["ConnectionArn"] + connection_arn_id = connection_arn.split("/")[-1] snapshot.add_transformers_list( [ @@ -1449,6 +1457,26 @@ def test_create_list_describe_update_delete_connection( ) snapshot.match("create-connection", response) + response = aws_client.events.list_connections(NamePrefix=connection_name) + snapshot.match("list-connections", response) + + response = aws_client.events.describe_connection( + Name=connection_name, + ) + secret_arn = response["SecretArn"] + secret_arn_id = secret_arn.split("/")[-1] + + snapshot.add_transformer(snapshot.transform.regex(secret_arn_id, "")) + snapshot.match("describe-connection", response) + + response = aws_client.events.delete_connection(Name=connection_name) + snapshot.match("delete-connection", response) + + events_connection_wait_for_deleted(aws_client, connection_name) + + response = aws_client.events.list_connections(NamePrefix=connection_name) + snapshot.match("list-connections-after-delete", response) + @markers.aws.validated def test_list_connections_with_prefix(self, aws_client): pass @@ -1456,3 +1484,7 @@ def test_list_connections_with_prefix(self, aws_client): @markers.aws.validated def test_list_connections_with_limit(self, aws_client): pass + + @markers.aws.validated + def test_list_connection_with_state(self, aws_client): + pass diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index 3f2ca5aac310a..509ed533daf61 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1225,7 +1225,7 @@ } }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-BASIC]": { - "recorded-date": "19-06-2024, 13:50:29", + "recorded-date": "19-06-2024, 14:09:43", "recorded-content": { "create-connection": { "ConnectionArn": "arn:aws:events::111111111111:connection//", @@ -1236,11 +1236,87 @@ "HTTPHeaders": {}, "HTTPStatusCode": 200 } + }, + "list-connections": { + "Connections": [ + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "describe-connection": { + "AuthParameters": { + "BasicAuthParameters": { + "Username": "test_user_1984" + }, + "InvocationHttpParameters": { + "BodyParameters": [ + { + "IsValueSecret": true, + "Key": "string" + } + ], + "HeaderParameters": [ + { + "IsValueSecret": true, + "Key": "string" + } + ], + "QueryStringParameters": [ + { + "IsValueSecret": false, + "Key": "string", + "Value": "string" + } + ] + } + }, + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "Description": "test description", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "", + "SecretArn": "arn:aws:secretsmanager::111111111111:secret:events!connection//", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "delete-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "DELETING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-after-delete": { + "Connections": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } } } }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-OAUTH_CLIENT_CREDENTIALS]": { - "recorded-date": "19-06-2024, 13:50:29", + "recorded-date": "19-06-2024, 14:09:47", "recorded-content": { "create-connection": { "ConnectionArn": "arn:aws:events::111111111111:connection//", @@ -1251,11 +1327,121 @@ "HTTPHeaders": {}, "HTTPStatusCode": 200 } + }, + "list-connections": { + "Connections": [ + { + "AuthorizationType": "OAUTH_CLIENT_CREDENTIALS", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "describe-connection": { + "AuthParameters": { + "InvocationHttpParameters": { + "BodyParameters": [ + { + "IsValueSecret": true, + "Key": "string" + } + ], + "HeaderParameters": [ + { + "IsValueSecret": true, + "Key": "string" + } + ], + "QueryStringParameters": [ + { + "IsValueSecret": false, + "Key": "string", + "Value": "string" + } + ] + }, + "OAuthParameters": { + "AuthorizationEndpoint": "https://oauth.pstmn.io/v1/callback", + "ClientParameters": { + "ClientID": "string" + }, + "HttpMethod": "PUT", + "OAuthHttpParameters": { + "BodyParameters": [ + { + "IsValueSecret": true, + "Key": "grant_type" + }, + { + "IsValueSecret": true, + "Key": "user" + }, + { + "IsValueSecret": true, + "Key": "password" + } + ], + "HeaderParameters": [ + { + "IsValueSecret": false, + "Key": "Content_Type", + "Value": "'application/x-www-form-urlencoded'" + } + ], + "QueryStringParameters": [ + { + "IsValueSecret": false, + "Key": "some_test_key", + "Value": "some_test_value" + } + ] + } + } + }, + "AuthorizationType": "OAUTH_CLIENT_CREDENTIALS", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZING", + "CreationTime": "datetime", + "Description": "test description", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "", + "SecretArn": "arn:aws:secretsmanager::111111111111:secret:events!connection//", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "delete-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "DELETING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-after-delete": { + "Connections": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } } } }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-API_KEY]": { - "recorded-date": "19-06-2024, 13:50:29", + "recorded-date": "19-06-2024, 14:09:50", "recorded-content": { "create-connection": { "ConnectionArn": "arn:aws:events::111111111111:connection//", @@ -1266,11 +1452,87 @@ "HTTPHeaders": {}, "HTTPStatusCode": 200 } + }, + "list-connections": { + "Connections": [ + { + "AuthorizationType": "API_KEY", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "describe-connection": { + "AuthParameters": { + "ApiKeyAuthParameters": { + "ApiKeyName": "test_key_1984" + }, + "InvocationHttpParameters": { + "BodyParameters": [ + { + "IsValueSecret": true, + "Key": "string" + } + ], + "HeaderParameters": [ + { + "IsValueSecret": true, + "Key": "string" + } + ], + "QueryStringParameters": [ + { + "IsValueSecret": false, + "Key": "string", + "Value": "string" + } + ] + } + }, + "AuthorizationType": "API_KEY", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "Description": "test description", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "", + "SecretArn": "arn:aws:secretsmanager::111111111111:secret:events!connection//", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "delete-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "DELETING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-after-delete": { + "Connections": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } } } }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-BASIC]": { - "recorded-date": "19-06-2024, 13:50:30", + "recorded-date": "19-06-2024, 14:09:53", "recorded-content": { "create-connection": { "ConnectionArn": "arn:aws:events::111111111111:connection//", @@ -1281,11 +1543,66 @@ "HTTPHeaders": {}, "HTTPStatusCode": 200 } + }, + "list-connections": { + "Connections": [ + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "describe-connection": { + "AuthParameters": { + "BasicAuthParameters": { + "Username": "test_user_1984" + } + }, + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "Description": "test description", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "", + "SecretArn": "arn:aws:secretsmanager::111111111111:secret:events!connection//", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "delete-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "DELETING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-after-delete": { + "Connections": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } } } }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-OAUTH_CLIENT_CREDENTIALS]": { - "recorded-date": "19-06-2024, 13:50:30", + "recorded-date": "19-06-2024, 14:09:55", "recorded-content": { "create-connection": { "ConnectionArn": "arn:aws:events::111111111111:connection//", @@ -1296,11 +1613,100 @@ "HTTPHeaders": {}, "HTTPStatusCode": 200 } + }, + "list-connections": { + "Connections": [ + { + "AuthorizationType": "OAUTH_CLIENT_CREDENTIALS", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "describe-connection": { + "AuthParameters": { + "OAuthParameters": { + "AuthorizationEndpoint": "https://oauth.pstmn.io/v1/callback", + "ClientParameters": { + "ClientID": "string" + }, + "HttpMethod": "PUT", + "OAuthHttpParameters": { + "BodyParameters": [ + { + "IsValueSecret": true, + "Key": "grant_type" + }, + { + "IsValueSecret": true, + "Key": "user" + }, + { + "IsValueSecret": true, + "Key": "password" + } + ], + "HeaderParameters": [ + { + "IsValueSecret": false, + "Key": "Content_Type", + "Value": "'application/x-www-form-urlencoded'" + } + ], + "QueryStringParameters": [ + { + "IsValueSecret": false, + "Key": "some_test_key", + "Value": "some_test_value" + } + ] + } + } + }, + "AuthorizationType": "OAUTH_CLIENT_CREDENTIALS", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZING", + "CreationTime": "datetime", + "Description": "test description", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "", + "SecretArn": "arn:aws:secretsmanager::111111111111:secret:events!connection//", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "delete-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "DELETING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-after-delete": { + "Connections": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } } } }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-API_KEY]": { - "recorded-date": "19-06-2024, 13:50:31", + "recorded-date": "19-06-2024, 14:09:58", "recorded-content": { "create-connection": { "ConnectionArn": "arn:aws:events::111111111111:connection//", @@ -1311,6 +1717,61 @@ "HTTPHeaders": {}, "HTTPStatusCode": 200 } + }, + "list-connections": { + "Connections": [ + { + "AuthorizationType": "API_KEY", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "describe-connection": { + "AuthParameters": { + "ApiKeyAuthParameters": { + "ApiKeyName": "test_key_1984" + } + }, + "AuthorizationType": "API_KEY", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "Description": "test description", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "", + "SecretArn": "arn:aws:secretsmanager::111111111111:secret:events!connection//", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "delete-connection": { + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "DELETING", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-after-delete": { + "Connections": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } } } } diff --git a/tests/aws/services/events/test_events.validation.json b/tests/aws/services/events/test_events.validation.json index d02a6f656007b..e2e53d055e42f 100644 --- a/tests/aws/services/events/test_events.validation.json +++ b/tests/aws/services/events/test_events.validation.json @@ -3,22 +3,22 @@ "last_validated_date": "2024-06-18T15:29:18+00:00" }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-API_KEY]": { - "last_validated_date": "2024-06-19T13:50:31+00:00" + "last_validated_date": "2024-06-19T14:09:58+00:00" }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-BASIC]": { - "last_validated_date": "2024-06-19T13:50:30+00:00" + "last_validated_date": "2024-06-19T14:09:53+00:00" }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[False-OAUTH_CLIENT_CREDENTIALS]": { - "last_validated_date": "2024-06-19T13:50:30+00:00" + "last_validated_date": "2024-06-19T14:09:55+00:00" }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-API_KEY]": { - "last_validated_date": "2024-06-19T13:50:29+00:00" + "last_validated_date": "2024-06-19T14:09:50+00:00" }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-BASIC]": { - "last_validated_date": "2024-06-19T13:50:29+00:00" + "last_validated_date": "2024-06-19T14:09:43+00:00" }, "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-OAUTH_CLIENT_CREDENTIALS]": { - "last_validated_date": "2024-06-19T13:50:29+00:00" + "last_validated_date": "2024-06-19T14:09:47+00:00" }, "tests/aws/services/events/test_events.py::TestEventBus::test_create_list_describe_delete_custom_event_buses[regions0]": { "last_validated_date": "2024-04-29T13:15:44+00:00" From 3f871a164412a674e2be1047c57c5d61d47386d3 Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Wed, 19 Jun 2024 16:23:06 +0200 Subject: [PATCH 09/11] feat: add test list connection with prefix --- tests/aws/services/events/test_events.py | 46 +++++++++++++++++-- .../services/events/test_events.snapshot.json | 39 ++++++++++++++++ .../events/test_events.validation.json | 3 ++ 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index 156b443eec656..d0bac6faaf312 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -601,7 +601,7 @@ def test_list_event_buses_with_prefix(self, create_event_bus, aws_client, snapsh bus_name = f"unique-prefix-1234567890-{short_uid()}" snapshot.add_transformer(snapshot.transform.regex(bus_name, "")) - bus_name_not_match = "no-prefix-match" + bus_name_not_match = f"no-prefix-match-{short_uid()}" snapshot.add_transformer(snapshot.transform.regex(bus_name_not_match, "")) create_event_bus(Name=bus_name) @@ -1478,8 +1478,48 @@ def test_create_list_describe_update_delete_connection( snapshot.match("list-connections-after-delete", response) @markers.aws.validated - def test_list_connections_with_prefix(self, aws_client): - pass + def test_list_connections_with_prefix(self, events_create_connection, aws_client, snapshot): + events = aws_client.events + connection_name = f"unique-prefix-1234567890-{short_uid()}" + snapshot.add_transformer(snapshot.transform.regex(connection_name, "")) + + connection_name_not_match = f"no-prefix-match-{short_uid()}" + snapshot.add_transformer( + snapshot.transform.regex(connection_name_not_match, "") + ) + + response = events_create_connection( + Name=connection_name, + Description="test description", + AuthorizationType="BASIC", + AuthParameters={ + "BasicAuthParameters": { + "Username": API_CONNECTION_TEST_USERNAME, + "Password": API_CONNECTION_TEST_PASSWORD, + } + }, + ) + connection_arn = response["ConnectionArn"] + connection_arn_id = connection_arn.split("/")[-1] + snapshot.add_transformer(snapshot.transform.regex(connection_arn_id, "")) + + events_create_connection( + Name=connection_name_not_match, + Description="test description", + AuthorizationType="BASIC", + AuthParameters={ + "BasicAuthParameters": { + "Username": API_CONNECTION_TEST_USERNAME, + "Password": API_CONNECTION_TEST_PASSWORD, + } + }, + ) + + response = events.list_connections(NamePrefix=connection_name) + snapshot.match("list-connections-prefix-complete-name", response) + + response = events.list_connections(NamePrefix=connection_name.split("-")[0]) + snapshot.match("list-connections-prefix", response) @markers.aws.validated def test_list_connections_with_limit(self, aws_client): diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index 509ed533daf61..aaa3fd0726eff 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1774,5 +1774,44 @@ } } } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_list_connections_with_prefix": { + "recorded-date": "19-06-2024, 14:22:55", + "recorded-content": { + "list-connections-prefix-complete-name": { + "Connections": [ + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-prefix": { + "Connections": [ + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } } } diff --git a/tests/aws/services/events/test_events.validation.json b/tests/aws/services/events/test_events.validation.json index e2e53d055e42f..b4c6eac16e8c2 100644 --- a/tests/aws/services/events/test_events.validation.json +++ b/tests/aws/services/events/test_events.validation.json @@ -20,6 +20,9 @@ "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-OAUTH_CLIENT_CREDENTIALS]": { "last_validated_date": "2024-06-19T14:09:47+00:00" }, + "tests/aws/services/events/test_events.py::TestConnection::test_list_connections_with_prefix": { + "last_validated_date": "2024-06-19T14:22:55+00:00" + }, "tests/aws/services/events/test_events.py::TestEventBus::test_create_list_describe_delete_custom_event_buses[regions0]": { "last_validated_date": "2024-04-29T13:15:44+00:00" }, From e135e9bf6287e911af721f60c2195404aea0288e Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Wed, 19 Jun 2024 16:32:19 +0200 Subject: [PATCH 10/11] feat: add test list connections with limit --- tests/aws/services/events/conftest.py | 2 +- tests/aws/services/events/test_events.py | 40 +++++++++- .../services/events/test_events.snapshot.json | 76 +++++++++++++++++++ .../events/test_events.validation.json | 3 + 4 files changed, 118 insertions(+), 3 deletions(-) diff --git a/tests/aws/services/events/conftest.py b/tests/aws/services/events/conftest.py index 4b1113412e00c..aaa34f563683b 100644 --- a/tests/aws/services/events/conftest.py +++ b/tests/aws/services/events/conftest.py @@ -431,6 +431,6 @@ def _create_connection(**kwargs): for connection in connections: try: - aws_client.events.delete_connection(ConnectionArn=connection) + aws_client.events.delete_connection(Name=connection) except Exception as e: LOG.warning(f"Failed to delete connection {connection}: {e}") diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index d0bac6faaf312..814d8eeff9df5 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -1522,8 +1522,44 @@ def test_list_connections_with_prefix(self, events_create_connection, aws_client snapshot.match("list-connections-prefix", response) @markers.aws.validated - def test_list_connections_with_limit(self, aws_client): - pass + def test_list_connections_with_limit(self, events_create_connection, aws_client, snapshot): + snapshot.add_transformer(snapshot.transform.jsonpath("$..NextToken", "next_token")) + connection_name_prefix = f"test-connection-{short_uid()}" + snapshot.add_transformer( + snapshot.transform.regex(connection_name_prefix, "") + ) + count = 6 + + for i in range(count): + connection_name = f"{connection_name_prefix}-{i}" + response = events_create_connection( + Name=connection_name, + Description="test description", + AuthorizationType="BASIC", + AuthParameters={ + "BasicAuthParameters": { + "Username": API_CONNECTION_TEST_USERNAME, + "Password": API_CONNECTION_TEST_PASSWORD, + } + }, + ) + connection_arn = response["ConnectionArn"] + connection_arn_id = connection_arn.split("/")[-1] + snapshot.add_transformer( + snapshot.transform.regex(connection_arn_id, "") + ) + + response = aws_client.events.list_connections( + Limit=int(count / 2), NamePrefix=connection_name_prefix + ) + snapshot.match("list-connections-limit", response) + + response = aws_client.events.list_connections( + Limit=int(count / 2) + 2, + NextToken=response["NextToken"], + NamePrefix=connection_name_prefix, + ) + snapshot.match("list-connections-limit-next-token", response) @markers.aws.validated def test_list_connection_with_state(self, aws_client): diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index aaa3fd0726eff..c09bb74776030 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1813,5 +1813,81 @@ } } } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_list_connections_with_limit": { + "recorded-date": "19-06-2024, 14:31:49", + "recorded-content": { + "list-connections-limit": { + "Connections": [ + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection/-0/", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "-0" + }, + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection/-1/", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "-1" + }, + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection/-2/", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "-2" + } + ], + "NextToken": "", + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-limit-next-token": { + "Connections": [ + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection/-3/", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "-3" + }, + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection/-4/", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "-4" + }, + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection/-5/", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "-5" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } } } diff --git a/tests/aws/services/events/test_events.validation.json b/tests/aws/services/events/test_events.validation.json index b4c6eac16e8c2..a26aff1d94964 100644 --- a/tests/aws/services/events/test_events.validation.json +++ b/tests/aws/services/events/test_events.validation.json @@ -20,6 +20,9 @@ "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-OAUTH_CLIENT_CREDENTIALS]": { "last_validated_date": "2024-06-19T14:09:47+00:00" }, + "tests/aws/services/events/test_events.py::TestConnection::test_list_connections_with_limit": { + "last_validated_date": "2024-06-19T14:31:49+00:00" + }, "tests/aws/services/events/test_events.py::TestConnection::test_list_connections_with_prefix": { "last_validated_date": "2024-06-19T14:22:55+00:00" }, From aa2b44b2912a101c4fa61e93984be1d449022af5 Mon Sep 17 00:00:00 2001 From: Maximilian Hoheiser Date: Wed, 19 Jun 2024 16:39:05 +0200 Subject: [PATCH 11/11] feat: add test list connection with filter state --- tests/aws/services/events/test_events.py | 35 +++++++++++++++++-- .../services/events/test_events.snapshot.json | 29 +++++++++++++++ .../events/test_events.validation.json | 3 ++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/tests/aws/services/events/test_events.py b/tests/aws/services/events/test_events.py index 814d8eeff9df5..4262706d43e21 100644 --- a/tests/aws/services/events/test_events.py +++ b/tests/aws/services/events/test_events.py @@ -1562,5 +1562,36 @@ def test_list_connections_with_limit(self, events_create_connection, aws_client, snapshot.match("list-connections-limit-next-token", response) @markers.aws.validated - def test_list_connection_with_state(self, aws_client): - pass + def test_list_connection_with_state(self, events_create_connection, aws_client, snapshot): + connection_name = f"test-connection-{short_uid()}" + response = events_create_connection( + Name=connection_name, + Description="test description", + AuthorizationType="BASIC", + AuthParameters={ + "BasicAuthParameters": { + "Username": API_CONNECTION_TEST_USERNAME, + "Password": API_CONNECTION_TEST_PASSWORD, + } + }, + ) + connection_arn = response["ConnectionArn"] + connection_arn_id = connection_arn.split("/")[-1] + snapshot.add_transformers_list( + [ + snapshot.transform.regex(connection_arn_id, ""), + snapshot.transform.regex(connection_name, ""), + ] + ) + + def _wait_for_active(): + response = aws_client.events.describe_connection(Name=connection_name) + return response["ConnectionState"] == "AUTHORIZED" + + retry(_wait_for_active, retries=5, sleep=1) + + response = aws_client.events.list_connections(ConnectionState="AUTHORIZED") + snapshot.match("list-connections-state", response) + + response = aws_client.events.list_connections(ConnectionState="CREATING") + snapshot.match("list-connections-state-empty", response) diff --git a/tests/aws/services/events/test_events.snapshot.json b/tests/aws/services/events/test_events.snapshot.json index c09bb74776030..bbd421083d545 100644 --- a/tests/aws/services/events/test_events.snapshot.json +++ b/tests/aws/services/events/test_events.snapshot.json @@ -1889,5 +1889,34 @@ } } } + }, + "tests/aws/services/events/test_events.py::TestConnection::test_list_connection_with_state": { + "recorded-date": "19-06-2024, 14:38:29", + "recorded-content": { + "list-connections-state": { + "Connections": [ + { + "AuthorizationType": "BASIC", + "ConnectionArn": "arn:aws:events::111111111111:connection//", + "ConnectionState": "AUTHORIZED", + "CreationTime": "datetime", + "LastAuthorizedTime": "datetime", + "LastModifiedTime": "datetime", + "Name": "" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + }, + "list-connections-state-empty": { + "Connections": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } } } diff --git a/tests/aws/services/events/test_events.validation.json b/tests/aws/services/events/test_events.validation.json index a26aff1d94964..abc660072fd2c 100644 --- a/tests/aws/services/events/test_events.validation.json +++ b/tests/aws/services/events/test_events.validation.json @@ -20,6 +20,9 @@ "tests/aws/services/events/test_events.py::TestConnection::test_create_list_describe_update_delete_connection[True-OAUTH_CLIENT_CREDENTIALS]": { "last_validated_date": "2024-06-19T14:09:47+00:00" }, + "tests/aws/services/events/test_events.py::TestConnection::test_list_connection_with_state": { + "last_validated_date": "2024-06-19T14:38:29+00:00" + }, "tests/aws/services/events/test_events.py::TestConnection::test_list_connections_with_limit": { "last_validated_date": "2024-06-19T14:31:49+00:00" },