"""Test approve-product handler.""" from unittest.mock import patch from constants import graphql_queries from ddex_ingester_common.lambda_exceptions import ApproveProductGraphQLException import index from lambdacommon.graphql import graphql import pytest @patch('index.graphql_gateway.execute') def test_handler(mock_graphql_execute, mock_event): """Test handler.""" result = index.handler(mock_event, None) mock_graphql_execute.assert_called_once_with( graphql_queries.APPROVE_AUDIO_PRODUCT, {'productId': 3141281} ) assert result['product']['status'] == 'in_content' @patch('index.graphql_gateway.execute') def test_handler_raises_exception(mock_graphql_execute, mock_event): """Test handler.""" mock_graphql_execute.side_effect = graphql.GraphQLError([{'error': 'message'}]) with pytest.raises(ApproveProductGraphQLException): index.handler(mock_event, None) mock_graphql_execute.assert_called_once_with( graphql_queries.APPROVE_AUDIO_PRODUCT, {'productId': 3141281} )