"""Unit tests for remove_ingestion_lock lambda.""" from unittest.mock import call, MagicMock, patch from src.index import handler @patch('src.index.s3_client') @patch('src.index.config') def test_handler_removes_placeholder_upc_lockfile(mock_config, mock_s3_client, context_event): """Test handler removes placeholder_upc lockfile.""" mock_delete_object = MagicMock() mock_s3_client.delete_object = mock_delete_object expected_bucket = 'bucket' expected_s3_path = 'path/' upc = context_event['product']['upc'] context_event['product']['display_upc'] = '88888888' expected_lockfile = f'{upc}.lock' expected_placeholder_upc_lockfile = '88888888.lock' mock_config.INGESTION_LOCK_S3_BUCKET = expected_bucket mock_config.INGESTION_LOCK_S3_PATH = expected_s3_path mock_config.INGESTION_S3_EXPECTED_OWNER = 'test_owner' handler(context_event, None) mock_delete_object.assert_has_calls( [call(Bucket=expected_bucket, Key=f'{expected_s3_path}{expected_lockfile}', ExpectedBucketOwner='test_owner'), call(Bucket=expected_bucket, Key=f'{expected_s3_path}{expected_placeholder_upc_lockfile}', ExpectedBucketOwner='test_owner') ])