22from datetime import datetime , timedelta , timezone
33
44import pytest
5+ from botocore .exceptions import ClientError
56
67from localstack .testing .pytest import markers
78from localstack .utils .strings import short_uid
@@ -272,7 +273,7 @@ def test_create_archive_error_duplicate(
272273 EventPattern = json .dumps (TEST_EVENT_PATTERN ),
273274 RetentionDays = 1 ,
274275 )
275- with pytest .raises (Exception ) as error :
276+ with pytest .raises (ClientError ) as error :
276277 aws_client .events .create_archive (
277278 ArchiveName = archive_name ,
278279 EventSourceArn = event_bus_arn ,
@@ -282,7 +283,7 @@ def test_create_archive_error_duplicate(
282283 )
283284
284285 snapshot .add_transformer ([snapshot .transform .regex (archive_name , "<archive-name>" )])
285- snapshot .match ("create-archive-duplicate-error" , error )
286+ snapshot .match ("create-archive-duplicate-error" , error . value . response )
286287
287288 @markers .aws .validated
288289 @pytest .mark .skipif (is_old_provider (), reason = "not supported by the old provider" )
@@ -291,7 +292,7 @@ def test_create_archive_error_unknown_event_bus(self, aws_client, snapshot):
291292 non_existing_event_bus_arn = (
292293 f"arn:aws:events:us-east-1:123456789012:event-bus/{ not_existing_event_bus_name } "
293294 )
294- with pytest .raises (Exception ) as error :
295+ with pytest .raises (ClientError ) as error :
295296 aws_client .events .create_archive (
296297 ArchiveName = "test-archive" ,
297298 EventSourceArn = non_existing_event_bus_arn ,
@@ -303,19 +304,19 @@ def test_create_archive_error_unknown_event_bus(self, aws_client, snapshot):
303304 snapshot .add_transformer (
304305 [snapshot .transform .regex (not_existing_event_bus_name , "<event-bus-name>" )]
305306 )
306- snapshot .match ("create-archive-unknown-event-bus-error" , error )
307+ snapshot .match ("create-archive-unknown-event-bus-error" , error . value . response )
307308
308309 @markers .aws .validated
309310 @pytest .mark .skipif (is_old_provider (), reason = "not supported by the old provider" )
310311 def test_describe_archive_error_unknown_archive (self , aws_client , snapshot ):
311312 not_existing_archive_name = f"doesnotexist-{ short_uid ()} "
312- with pytest .raises (Exception ) as error :
313+ with pytest .raises (ClientError ) as error :
313314 aws_client .events .describe_archive (ArchiveName = not_existing_archive_name )
314315
315316 snapshot .add_transformer (
316317 [snapshot .transform .regex (not_existing_archive_name , "<archive-name>" )]
317318 )
318- snapshot .match ("describe-archive-unknown-archive-error" , error )
319+ snapshot .match ("describe-archive-unknown-archive-error" , error . value . response )
319320
320321 @markers .aws .validated
321322 @pytest .mark .skipif (is_old_provider (), reason = "not supported by the old provider" )
@@ -326,37 +327,37 @@ def test_list_archive_error_unknown_source_arn(
326327 non_existing_event_bus_arn = (
327328 f"arn:aws:events:{ region_name } :{ account_id } :event-bus/{ not_existing_event_bus_name } "
328329 )
329- with pytest .raises (Exception ) as error :
330+ with pytest .raises (ClientError ) as error :
330331 aws_client .events .list_archives (EventSourceArn = non_existing_event_bus_arn )
331332
332333 snapshot .add_transformer (
333334 [snapshot .transform .regex (not_existing_event_bus_name , "<event-bus-name>" )]
334335 )
335- snapshot .match ("list-archives-unknown-event-bus-error" , error )
336+ snapshot .match ("list-archives-unknown-event-bus-error" , error . value . response )
336337
337338 @markers .aws .validated
338339 @pytest .mark .skip (reason = "not possible to test with localstack" )
339340 def test_update_archive_error_unknown_archive (self , aws_client , snapshot ):
340341 not_existing_archive_name = f"doesnotexist-{ short_uid ()} "
341- with pytest .raises (Exception ) as error :
342+ with pytest .raises (ClientError ) as error :
342343 aws_client .events .update_archive (ArchiveName = not_existing_archive_name )
343344
344345 snapshot .add_transformer (
345346 [snapshot .transform .regex (not_existing_archive_name , "<archive-name>" )]
346347 )
347- snapshot .match ("update-archive-unknown-archive-error" , error )
348+ snapshot .match ("update-archive-unknown-archive-error" , error . value . response )
348349
349350 @markers .aws .validated
350351 @pytest .mark .skipif (is_old_provider (), reason = "not supported by the old provider" )
351352 def test_delete_archive_error_unknown_archive (self , aws_client , snapshot ):
352353 not_existing_archive_name = f"doesnotexist-{ short_uid ()} "
353- with pytest .raises (Exception ) as error :
354+ with pytest .raises (ClientError ) as error :
354355 aws_client .events .delete_archive (ArchiveName = not_existing_archive_name )
355356
356357 snapshot .add_transformer (
357358 [snapshot .transform .regex (not_existing_archive_name , "<archive-name>" )]
358359 )
359- snapshot .match ("delete-archive-unknown-archive-error" , error )
360+ snapshot .match ("delete-archive-unknown-archive-error" , error . value . response )
360361
361362
362363class TestReplay :
@@ -669,7 +670,7 @@ def test_start_replay_error_unknown_event_bus(
669670 end_time = datetime .now (timezone .utc )
670671
671672 replay_name = f"test-replay-{ short_uid ()} "
672- with pytest .raises (Exception ) as error :
673+ with pytest .raises (ClientError ) as error :
673674 aws_client .events .start_replay (
674675 ReplayName = replay_name ,
675676 Description = "description of the replay" ,
@@ -684,11 +685,11 @@ def test_start_replay_error_unknown_event_bus(
684685 snapshot .add_transformer (
685686 [snapshot .transform .regex (not_existing_event_bus_name , "<event-bus-name>" )]
686687 )
687- snapshot .match ("start-replay-unknown-event-bus-error" , error )
688+ snapshot .match ("start-replay-unknown-event-bus-error" , error . value . response )
688689
689690 event_bus_arn = events_create_event_bus (Name = not_existing_event_bus_name )["EventBusArn" ]
690691
691- with pytest .raises (Exception ) as error :
692+ with pytest .raises (ClientError ) as error :
692693 aws_client .events .start_replay (
693694 ReplayName = replay_name ,
694695 Description = "description of the replay" ,
@@ -700,7 +701,7 @@ def test_start_replay_error_unknown_event_bus(
700701 }, # the destination must be the exact same event bus the archive is created for
701702 )
702703
703- snapshot .match ("start-replay-wrong-event-bus-error" , error )
704+ snapshot .match ("start-replay-wrong-event-bus-error" , error . value . response )
704705
705706 @markers .aws .validated
706707 def test_start_replay_error_unknown_archive (
@@ -709,7 +710,7 @@ def test_start_replay_error_unknown_archive(
709710 not_existing_archive_name = f"doesnotexist-{ short_uid ()} "
710711 start_time = datetime .now (timezone .utc ) - timedelta (minutes = 1 )
711712 end_time = datetime .now (timezone .utc )
712- with pytest .raises (Exception ) as error :
713+ with pytest .raises (ClientError ) as error :
713714 aws_client .events .start_replay (
714715 ReplayName = "test-replay" ,
715716 Description = "description of the replay" ,
@@ -724,7 +725,7 @@ def test_start_replay_error_unknown_archive(
724725 snapshot .add_transformer (
725726 [snapshot .transform .regex (not_existing_archive_name , "<archive-name>" )]
726727 )
727- snapshot .match ("start-replay-unknown-archive-error" , error )
728+ snapshot .match ("start-replay-unknown-archive-error" , error . value . response )
728729
729730 @markers .aws .validated
730731 def test_start_replay_error_duplicate_name_same_archive (
@@ -751,7 +752,7 @@ def test_start_replay_error_duplicate_name_same_archive(
751752 },
752753 )
753754
754- with pytest .raises (Exception ) as error :
755+ with pytest .raises (ClientError ) as error :
755756 aws_client .events .start_replay (
756757 ReplayName = replay_name ,
757758 Description = "description of the replay" ,
@@ -764,7 +765,7 @@ def test_start_replay_error_duplicate_name_same_archive(
764765 )
765766
766767 snapshot .add_transformer ([snapshot .transform .regex (replay_name , "<replay-name>" )])
767- snapshot .match ("start-replay-duplicate-error" , error )
768+ snapshot .match ("start-replay-duplicate-error" , error . value . response )
768769
769770 @markers .aws .validated
770771 def test_start_replay_error_duplicate_different_archive (
@@ -800,7 +801,7 @@ def test_start_replay_error_duplicate_different_archive(
800801 },
801802 )
802803
803- with pytest .raises (Exception ) as error :
804+ with pytest .raises (ClientError ) as error :
804805 aws_client .events .start_replay (
805806 ReplayName = replay_name ,
806807 Description = "description of the replay" ,
@@ -813,7 +814,7 @@ def test_start_replay_error_duplicate_different_archive(
813814 )
814815
815816 snapshot .add_transformer ([snapshot .transform .regex (replay_name , "<replay-name>" )])
816- snapshot .match ("start-replay-duplicate-error" , error )
817+ snapshot .match ("start-replay-duplicate-error" , error . value . response )
817818
818819 @markers .aws .validated
819820 @pytest .mark .skipif (is_old_provider (), reason = "not supported by the old provider" )
@@ -833,7 +834,7 @@ def test_start_replay_error_invalid_end_time(
833834 )
834835
835836 replay_name = f"test-replay-{ short_uid ()} "
836- with pytest .raises (Exception ) as error :
837+ with pytest .raises (ClientError ) as error :
837838 aws_client .events .start_replay (
838839 ReplayName = replay_name ,
839840 Description = "description of the replay" ,
@@ -845,7 +846,7 @@ def test_start_replay_error_invalid_end_time(
845846 },
846847 )
847848
848- snapshot .match ("start-replay-invalid-end-time-error" , error )
849+ snapshot .match ("start-replay-invalid-end-time-error" , error . value . response )
849850
850851 @markers .aws .validated
851852 @pytest .mark .skip (reason = "currently no concurrency for replays in localstack" )
@@ -881,7 +882,7 @@ def tests_concurrency_error_too_many_active_replays(
881882 )
882883
883884 # only 10 replays are allowed to be in state STARTING or RUNNING at the same time
884- with pytest .raises (Exception ) as error :
885+ with pytest .raises (ClientError ) as error :
885886 replay_name = f"{ replay_name_prefix } -test-replay-{ num_replays } "
886887 aws_client .events .start_replay (
887888 ReplayName = replay_name ,
@@ -901,15 +902,15 @@ def tests_concurrency_error_too_many_active_replays(
901902 snapshot .transform .jsonpath ("$..NextToken" , "next_token" ),
902903 ]
903904 )
904- snapshot .match ("list-replays-with-limit" , error )
905+ snapshot .match ("list-replays-with-limit" , error . value . response )
905906
906907 @markers .aws .validated
907908 def test_describe_replay_error_unknown_replay (self , aws_client , snapshot ):
908909 not_existing_replay_name = f"doesnotexist-{ short_uid ()} "
909- with pytest .raises (Exception ) as error :
910+ with pytest .raises (ClientError ) as error :
910911 aws_client .events .describe_replay (ReplayName = not_existing_replay_name )
911912
912913 snapshot .add_transformer (
913914 [snapshot .transform .regex (not_existing_replay_name , "<replay-name>" )]
914915 )
915- snapshot .match ("describe-replay-unknown-replay-error" , error )
916+ snapshot .match ("describe-replay-unknown-replay-error" , error . value . response )
0 commit comments