"""Test handler.""" import json from unittest.mock import MagicMock from unittest.mock import patch from src.index import handler @patch('src.index.shortuuid.encode', return_value='uuid') @patch('src.index.boto3') @patch('src.index.config') def test_handler(mock_config, mock_boto3, mock_uuid, event): """Test the main handler.""" mock_config.BULK_ASSETS_STATE_MACHINE_ARN = 'state-machine-arn' execution_arn = '12345' start_execution_output = { 'executionArn': execution_arn } sfn_client = MagicMock() sfn_client.start_execution.return_value = start_execution_output mock_boto3.client.return_value = sfn_client output = handler(event, None) assert output == execution_arn sfn_client.start_execution.assert_called_once_with( stateMachineArn=mock_config.BULK_ASSETS_STATE_MACHINE_ARN, name='BULK_test_file-uuid', input=json.dumps(event) ) @patch('src.index.shortuuid.encode', return_value='uuid') @patch('src.index.boto3') @patch('src.index.config') def test_handler_none_xml_event(mock_config, mock_boto3, mock_uuid, event): """Test the main handler with a none xml event key.""" event['detail']['object']['key'] = 'not-bulk-assets.flac' assert not handler(event, None) @patch('src.index.shortuuid.encode', return_value='uuid') @patch('src.index.boto3') @patch('src.index.config') def test_handler_json_in_resources_path( mock_config, mock_boto3, mock_uuid, event): """Test the main handler with an xml inside resources path.""" event['detail']['object']['key'] = ( 'bulk_assets/resources/extended-metadata.json' ) assert not handler(event, None)