from .....src.logic.producer import handler def test_run(mocker): # IMPORTANT: PREVENT THE TEST FROM PUBLISHING TO SNS! mock_sns_client = mocker.Mock() mocker.patch.object( handler.aws, "new_sns_client", autospec=True, return_value=mock_sns_client, ) mocker.patch.object( handler.aws.utils, "get_sns_topic_arn", autospec=True, return_value="arn:aws:sns:eu-west-1:123456789012:test-topic", ) # Consider all periods to be available for processing, so that there are more # potential messages to be sent (as the reports aren't yet in S3). mocker.patch.object(handler, "EARLIEST_PERIOD_TO_PROCESS", 0) handler.run() assert mock_sns_client.publish.call_count > 50, ( "Should publish more than 50 messages to SNS (as of April 2024, even " " more than 150 messages are expected)." ) def test_get_existing_reports_in_s3(): result = handler._get_existing_reports_in_s3( handler.aws.new_s3_client(handler.config.AWS_REGION), handler.config.S3_BUCKET ) assert isinstance(result, dict), "The result should be a dict" assert all( isinstance(key, int) for key in result.keys() ), "Any key in the result should be an integer (label ID)" assert all( isinstance(value, list) for value in result.values() ), "Any value in the result should be a list" if any(result.values()): assert all( isinstance(item, int) for sublist in result.values() for item in sublist ), "All items in the lists should be integers (period IDs)" assert all( len(value) > 0 for value in result.values() ), "There should be no empty lists in the values of the result"