From 122dac4444880ed7a907a9bf44c6bd2e4ed1e03c Mon Sep 17 00:00:00 2001 From: kakakakakku Date: Tue, 3 Dec 2024 22:21:39 +0900 Subject: [PATCH 1/3] Add test for EventBridge Scheduler TagResource API and UntagResource API --- .../aws/services/scheduler/test_scheduler.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/aws/services/scheduler/test_scheduler.py b/tests/aws/services/scheduler/test_scheduler.py index a4fee86e9db50..592b75cbf5670 100644 --- a/tests/aws/services/scheduler/test_scheduler.py +++ b/tests/aws/services/scheduler/test_scheduler.py @@ -2,6 +2,7 @@ from localstack.testing.aws.util import in_default_partition from localstack.testing.pytest import markers +from localstack.utils.common import short_uid @pytest.mark.skipif( @@ -12,3 +13,50 @@ def test_list_schedules(aws_client): # simple smoke test to assert that the provider is available, without creating any schedules result = aws_client.scheduler.list_schedules() assert isinstance(result.get("Schedules"), list) + + +@markers.aws.validated +def test_tag_resource(aws_client): + name = short_uid() + + response = aws_client.scheduler.create_schedule_group(Name=name) + schedule_group_arn = response["ScheduleGroupArn"] + + response = aws_client.scheduler.tag_resource( + ResourceArn=schedule_group_arn, + Tags=[ + { + "Key": "TagKey", + "Value": "TagValue", + } + ], + ) + + response = aws_client.scheduler.list_tags_for_resource(ResourceArn=schedule_group_arn) + + assert response["Tags"][0]["Key"] == "TagKey" + assert response["Tags"][0]["Value"] == "TagValue" + + +@markers.aws.validated +def test_untag_resource(aws_client): + name = short_uid() + + response = aws_client.scheduler.create_schedule_group( + Name=name, + Tags=[ + { + "Key": "TagKey", + "Value": "TagValue", + } + ], + ) + schedule_group_arn = response["ScheduleGroupArn"] + + response = aws_client.scheduler.untag_resource( + ResourceArn=schedule_group_arn, TagKeys=["TagKey"] + ) + + response = aws_client.scheduler.list_tags_for_resource(ResourceArn=schedule_group_arn) + + assert response["Tags"] == [] From b0611cf48cafb17235b22eef7115aba0777dff65 Mon Sep 17 00:00:00 2001 From: maxhoheiser Date: Wed, 4 Dec 2024 11:09:10 +0100 Subject: [PATCH 2/3] feat: add fixture to delete resource --- tests/aws/services/scheduler/conftest.py | 29 ++++++++++++++++++ .../aws/services/scheduler/test_scheduler.py | 30 +++++++++---------- 2 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 tests/aws/services/scheduler/conftest.py diff --git a/tests/aws/services/scheduler/conftest.py b/tests/aws/services/scheduler/conftest.py new file mode 100644 index 0000000000000..3591951039e6b --- /dev/null +++ b/tests/aws/services/scheduler/conftest.py @@ -0,0 +1,29 @@ +import logging + +import pytest + +from localstack.utils.strings import short_uid + +LOG = logging.getLogger(__name__) + + +@pytest.fixture +def events_scheduler_create_schedule_group(aws_client): + schedule_group_arns = [] + + def _events_scheduler_create_schedule_group(name, **kwargs): + if not name: + name = f"events-test-schedule-groupe-{short_uid()}" + response = aws_client.scheduler.create_schedule_group(Name=name, **kwargs) + schedule_group_arn = response["ScheduleGroupArn"] + schedule_group_arns.append(schedule_group_arn) + + return schedule_group_arn + + yield _events_scheduler_create_schedule_group + + for schedule_group_arn in schedule_group_arns: + try: + aws_client.scheduler.delete_schedule_group(ScheduleGroupArn=schedule_group_arn) + except Exception: + LOG.info("Failed to delete schedule group %s", schedule_group_arn) diff --git a/tests/aws/services/scheduler/test_scheduler.py b/tests/aws/services/scheduler/test_scheduler.py index 592b75cbf5670..157c8addd4c14 100644 --- a/tests/aws/services/scheduler/test_scheduler.py +++ b/tests/aws/services/scheduler/test_scheduler.py @@ -16,11 +16,9 @@ def test_list_schedules(aws_client): @markers.aws.validated -def test_tag_resource(aws_client): +def test_tag_resource(aws_client, events_scheduler_create_schedule_group, snapshot): name = short_uid() - - response = aws_client.scheduler.create_schedule_group(Name=name) - schedule_group_arn = response["ScheduleGroupArn"] + schedule_group_arn = events_scheduler_create_schedule_group(name) response = aws_client.scheduler.tag_resource( ResourceArn=schedule_group_arn, @@ -37,21 +35,19 @@ def test_tag_resource(aws_client): assert response["Tags"][0]["Key"] == "TagKey" assert response["Tags"][0]["Value"] == "TagValue" + snapshot.match("list-tagged-schedule", response) + @markers.aws.validated -def test_untag_resource(aws_client): +def test_untag_resource(aws_client, events_scheduler_create_schedule_group, snapshot): name = short_uid() - - response = aws_client.scheduler.create_schedule_group( - Name=name, - Tags=[ - { - "Key": "TagKey", - "Value": "TagValue", - } - ], - ) - schedule_group_arn = response["ScheduleGroupArn"] + tags = [ + { + "Key": "TagKey", + "Value": "TagValue", + } + ] + schedule_group_arn = events_scheduler_create_schedule_group(name, Tags=tags) response = aws_client.scheduler.untag_resource( ResourceArn=schedule_group_arn, TagKeys=["TagKey"] @@ -60,3 +56,5 @@ def test_untag_resource(aws_client): response = aws_client.scheduler.list_tags_for_resource(ResourceArn=schedule_group_arn) assert response["Tags"] == [] + + snapshot.match("list-untagged-schedule", response) From acdacd188b26f15169868636ab1194cae990219a Mon Sep 17 00:00:00 2001 From: maxhoheiser Date: Wed, 4 Dec 2024 11:09:18 +0100 Subject: [PATCH 3/3] feat: add snapshot --- .../scheduler/test_scheduler.snapshot.json | 31 +++++++++++++++++++ .../scheduler/test_scheduler.validation.json | 6 ++++ 2 files changed, 37 insertions(+) create mode 100644 tests/aws/services/scheduler/test_scheduler.snapshot.json diff --git a/tests/aws/services/scheduler/test_scheduler.snapshot.json b/tests/aws/services/scheduler/test_scheduler.snapshot.json new file mode 100644 index 0000000000000..cb8ccf8a85b06 --- /dev/null +++ b/tests/aws/services/scheduler/test_scheduler.snapshot.json @@ -0,0 +1,31 @@ +{ + "tests/aws/services/scheduler/test_scheduler.py::test_tag_resource": { + "recorded-date": "04-12-2024, 10:07:28", + "recorded-content": { + "list-tagged-schedule": { + "Tags": [ + { + "Key": "TagKey", + "Value": "TagValue" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + }, + "tests/aws/services/scheduler/test_scheduler.py::test_untag_resource": { + "recorded-date": "04-12-2024, 10:08:11", + "recorded-content": { + "list-untagged-schedule": { + "Tags": [], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } + } +} diff --git a/tests/aws/services/scheduler/test_scheduler.validation.json b/tests/aws/services/scheduler/test_scheduler.validation.json index ce59d722d9340..487c07eaf3e43 100644 --- a/tests/aws/services/scheduler/test_scheduler.validation.json +++ b/tests/aws/services/scheduler/test_scheduler.validation.json @@ -1,5 +1,11 @@ { "tests/aws/services/scheduler/test_scheduler.py::test_list_schedules": { "last_validated_date": "2024-06-11T22:50:50+00:00" + }, + "tests/aws/services/scheduler/test_scheduler.py::test_tag_resource": { + "last_validated_date": "2024-12-04T10:07:28+00:00" + }, + "tests/aws/services/scheduler/test_scheduler.py::test_untag_resource": { + "last_validated_date": "2024-12-04T10:08:11+00:00" } }