"""Lambda test module.""" import pytest from src import app as index from src.logic.check_ddex_generation import DDEX_ERROR from src.logic.check_ddex_generation import DDEX_UNKNOWN from src.logic.check_ddex_generation import DDEX_OK class TestHandler: """Test handler class.""" @pytest.fixture def mock_failed_ddex(self, mocker): """Mock function on ddex failed.""" mock = mocker.patch.object(index, 'check_ddex_generation') mock.return_value = (DDEX_ERROR, 'Error Message') return mock def test_handler_failed_ddex(self, mock_failed_ddex): """Test handler on ddex failed.""" event = {'upc': 123} with pytest.raises(index.DDEXCheckException): index.handler(event, None) @pytest.fixture def mock_empty_ddex(self, mocker): """Mock function on ddex empty.""" mock = mocker.patch.object(index, 'check_ddex_generation') mock.return_value = (DDEX_UNKNOWN, '') return mock def test_handler_empty_ddex(self, mock_empty_ddex): """Test handler on ddex empty.""" event = {'upc': 123} with pytest.raises(index.DDEXCheckUnknown): index.handler(event, None) def test_handler(self, mocker): """Test handler function.""" mock = mocker.patch.object(index, 'check_ddex_generation') mock.return_value = (DDEX_OK, '') product_metadata_event = {'upc': 123} result = index.handler(product_metadata_event, None) assert result.get('status') == 'OK' assert result.get('DDEX_CHECK_RESULT') == DDEX_OK