"""Test handler.""" from unittest.mock import MagicMock, patch from ddex_ingester_common.schemas.s3_schema import S3Schema from ddex_ingester_common.schemas.state_machine_schema import \ StateMachineSchema import index @patch('index.load_ddex_json') @patch('index.logger') @patch('index.graphql_gateway.execute') def test_handler( mock_graphql_execute, mock_current_logger, mock_load_ddex_json, mock_event): """Test the main handler.""" mock_logger = MagicMock(name='info') mock_current_logger.return_value = mock_logger mock_load_ddex_json.return_value = mock_event mock_graphql_execute.return_value = True response = index.handler(mock_event, None) assert response is True def test_construct_item(): """Test construct_item.""" item = index.construct_item( 23421, '3452452345432', '3452kl3kljll', 1, '2020-11-11' ) assert item == { 'productId': 23421, 'upc': '3452452345432', 'storeId': 1, 'storeInternalId': '3452kl3kljll', 'status': 'live', 'salesStartDate': '2020-11-11', 'storeInternalStatus': '', 'forcePolling': 0, 'receivedForPollingDate': 0, 'deliveryDate': 0, 'countryCodes': '', } def test_parse_store_links(mock_event): """Test parse_store_links.""" mock_context = StateMachineSchema().load(mock_event) mock_s3_context = S3Schema().load(mock_event) result = index.parse_store_links( mock_s3_context.product.stores, mock_context.product.product_id, mock_context.product.upc, mock_context.product.sale_start_date.strftime('%Y-%m-%d') ) assert result == [ { 'productId': 234324, 'upc': '245234523454', 'storeId': 286, 'storeInternalId': '368TKDyiyzFTwCyHJ0uWqc', 'status': 'live', 'salesStartDate': '2020-12-01', 'storeInternalStatus': '', 'forcePolling': 0, 'receivedForPollingDate': 0, 'deliveryDate': 0, 'countryCodes': '', }, { 'productId': 234324, 'upc': '245234523454', 'storeId': 1, 'storeInternalId': '186235393', 'status': 'live', 'salesStartDate': '2020-12-01', 'storeInternalStatus': '', 'forcePolling': 0, 'receivedForPollingDate': 0, 'deliveryDate': 0, 'countryCodes': '', }, { 'productId': 234324, 'upc': '245234523454', 'storeId': 348, 'storeInternalId': '186235392', 'status': 'live', 'salesStartDate': '2020-12-01', 'storeInternalStatus': '', 'forcePolling': 0, 'receivedForPollingDate': 0, 'deliveryDate': 0, 'countryCodes': '', }, ]