"""Test handler.""" import json from unittest.mock import MagicMock, patch from ddex_ingester_common.constants.ddex_providers import SME from index import handler @patch('index.uuid.uuid4', return_value='uuid') @patch('index.boto3') @patch('index.config') def test_handler(mock_config, mock_boto3, mock_uuid, event): """Test the main handler.""" mock_config.DDEX_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 updated_event = event.copy() updated_event['detail']['requestParameters'] = { 'bucketName': event['detail']['bucket']['name'], 'key': event['detail']['object']['key'], 'correlation_id': 'uuid', 'ddex_provider': SME } sfn_client.start_execution.assert_called_once_with( stateMachineArn=mock_config.DDEX_STATE_MACHINE_ARN, name='delivery-folder-1-uuid', input=json.dumps(updated_event) ) @patch('index.uuid.uuid4', return_value='uuid') @patch('index.boto3') @patch('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-ddex.flac' assert not handler(event, None) @patch('index.uuid.uuid4', return_value='uuid') @patch('index.boto3') @patch('index.config') def test_handler_xml_in_resources_path( mock_config, mock_boto3, mock_uuid, event): """Test the main handler with an xml inside resources path.""" event['detail']['object']['key'] = ( 'sme_ddex/resources/extended-metadata.xml' ) assert not handler(event, None)