|
| 1 | +from unittest import SkipTest |
| 2 | +from unittest.case import skipIf |
| 3 | + |
| 4 | +from parameterized import parameterized |
| 5 | +from tenacity import retry, retry_if_exception, stop_after_attempt |
| 6 | + |
| 7 | +from integration.config.service_names import EVENT_RULE_WITH_EVENT_BUS |
| 8 | +from integration.conftest import clean_bucket |
| 9 | +from integration.helpers.base_test import BaseTest |
| 10 | +from integration.helpers.resource import current_region_does_not_support |
| 11 | + |
| 12 | +retry_once = retry( |
| 13 | + stop=stop_after_attempt(2), |
| 14 | + # unittest raises SkipTest for skipping tests |
| 15 | + retry=retry_if_exception(lambda e: not isinstance(e, SkipTest)), |
| 16 | +) |
| 17 | + |
| 18 | + |
| 19 | +@skipIf( |
| 20 | + current_region_does_not_support([EVENT_RULE_WITH_EVENT_BUS]), |
| 21 | + "EVENT_RULE_WITH_EVENT_BUS is not supported in this testing region", |
| 22 | +) |
| 23 | +class TestConnectorsWithEventRuleToEB(BaseTest): |
| 24 | + def tearDown(self): |
| 25 | + # Some tests will create items in S3 Bucket, which result in stack DELETE_FAILED state |
| 26 | + # manually empty the bucket to allow stacks to be deleted successfully. |
| 27 | + bucket_name = self.get_physical_id_by_type("AWS::S3::Bucket") |
| 28 | + if bucket_name: |
| 29 | + clean_bucket(bucket_name, self.client_provider.s3_client) |
| 30 | + super().tearDown() |
| 31 | + |
| 32 | + @parameterized.expand( |
| 33 | + [ |
| 34 | + ("combination/connector_event_rule_to_eb_default_write",), |
| 35 | + ("combination/connector_event_rule_to_eb_custom_write",), |
| 36 | + ] |
| 37 | + ) |
| 38 | + @retry_once |
| 39 | + def test_connector_event_rule_eb_by_invoking_a_function(self, template_file_path): |
| 40 | + self.skip_using_service_detector(template_file_path) |
| 41 | + self.create_and_verify_stack(template_file_path) |
| 42 | + |
| 43 | + lambda_function_name = self.get_physical_id_by_logical_id("TriggerFunction") |
| 44 | + lambda_client = self.client_provider.lambda_client |
| 45 | + |
| 46 | + request_params = { |
| 47 | + "FunctionName": lambda_function_name, |
| 48 | + "InvocationType": "RequestResponse", |
| 49 | + "Payload": "{}", |
| 50 | + } |
| 51 | + response = lambda_client.invoke(**request_params) |
| 52 | + self.assertEqual(response.get("StatusCode"), 200) |
| 53 | + self.assertEqual(response.get("FunctionError"), None) |
0 commit comments