"""Test remove_ingestion_lock handler.""" from unittest.mock import MagicMock, patch from index import handler @patch('index.logger') @patch('index.StateMachineSchema') @patch('index.s3_client') @patch('index.config') def test_handler_removes_lockfile( mock_config, mock_s3_client, mock_state_machine_schema, mock_current_logger, context, deserialized_context ): """Test the main handler removes lockfile.""" mock_state_machine_schema.return_value.load = ( lambda _: deserialized_context) mock_state_machine_schema.return_value.dump = ( lambda _: context) mock_delete_object = MagicMock() mock_s3_client.delete_object = mock_delete_object expected_bucket = 'bucket' expected_s3_path = 'path/' expected_lockfile = f'{deserialized_context.product.upc}.lock' mock_config.INGESTION_LOCK_S3_BUCKET = expected_bucket mock_config.INGESTION_LOCK_S3_PATH = expected_s3_path output = handler(context, None) mock_delete_object.assert_called_once_with( Bucket=expected_bucket, Key=f'{expected_s3_path}{expected_lockfile}') assert output == context