"""Test process_purged_release handler.""" from unittest.mock import patch from ddex_ingester_common.constants.status import IN_CONTENT from ddex_ingester_common.constants.swb_deal_types import \ SME_ANALYTICS_NOT_FOR_DISTRIBUTION from ddex_ingester_common.lambda_exceptions import LambdaException import index import pytest @patch('index.get_product_by_upc') @patch('index.product_soft_delete') def test_handler(product_soft_delete_mock, get_product_by_upc_mock, purged_context_object): """Test handler.""" test_product_id = 123 get_product_by_upc_mock.return_value = \ {'product_id': test_product_id, 'deletions': 'N', 'status': IN_CONTENT, 'not_for_distribution': SME_ANALYTICS_NOT_FOR_DISTRIBUTION} index.handler(purged_context_object, None) product_soft_delete_mock.assert_called_with(test_product_id) get_product_by_upc_mock.assert_called_with( purged_context_object['product']['upc']) @patch('index.get_product_by_upc') def test_soft_delete_for_non_sme_product(get_product_by_upc_mock, purged_context_object): """Test soft delete attempt for non sme product.""" test_product_id = 123 test_product = {'product_id': test_product_id, 'deletions': 'N', 'status': IN_CONTENT, 'not_for_distribution': 'N'} get_product_by_upc_mock.return_value = test_product with pytest.raises(LambdaException) as exc_info: index.handler(purged_context_object, None) assert exc_info.value.args[0] == \ 'It is only allowed to soft delete sme_analytics products.' \ f'Actual product: {test_product}'