from atlas_um.audit.processors import ( EventBridgeAsyncProcessor, StructlogProcessor, ) from atlas_um.consts import SystemEvents from atlas_um.settings import Settings class TestStructlogProcessor: def test_process(self, mocker, faker): test_name = faker.pystr() test_event = SystemEvents.successful_logout test_context = {"cont_arg1": "cont_value1"} test_kwargs = {"arg1": "value1"} mocked_logger = mocker.patch("structlog.get_logger").return_value mocked_info = mocked_logger.bind.return_value.info processor = StructlogProcessor(test_name) processor.process(test_event, test_context, **test_kwargs) assert mocked_logger.bind.call_args_list == [ mocker.call(**test_context, **test_kwargs) ] assert mocked_info.call_args_list == [mocker.call(test_event.value)] class TestEventBridgeAsyncProcessor: def test_process(self, mocker, faker): test_event = SystemEvents.creating_dna_account test_context = {"cont_arg1": "cont_value1"} test_kwargs = {"arg1": "value1"} mocked_boto3 = mocker.patch("boto3.client").return_value processor = EventBridgeAsyncProcessor() processor.process(test_event, test_context, **test_kwargs) bus_conf = EventBridgeAsyncProcessor.EVENTS_SETTINGS.get( SystemEvents.creating_dna_account ) assert mocked_boto3.put_events.call_args_list == [ mocker.call( Entries=[ { "Source": Settings.EVENT_BUS_SOURCE, "EventBusName": Settings.EVENT_BUS_NAME, "DetailType": bus_conf.detail_type, "Detail": bus_conf.detail_schema().dumps({}), } ] ) ]