"""Test poll_artwork_asset_status.""" from unittest.mock import patch import pytest from ddex_ingester_common.lambda_exceptions import (ArtworkException, ArtworkFatalException) from ddex_ingester_common.schemas.state_machine_schema import \ StateMachineSchema from index import check_artwork_valid, handler @patch('index.valid_artwork', return_value=True) @patch('index.graphql_gateway') def test_check_artwork_valid_v2_flag( mock_graphql_gateway, mock_valid_artwork): """Test check_artwork_valid with v2 flag.""" product_id = '12345' filename = 'image.jpg' check_artwork_valid(product_id, filename) mock_valid_artwork.assert_called_once_with( mock_graphql_gateway, product_id, False ) @patch('index.valid_artwork', return_value=False) @patch('index.graphql_gateway') def test_check_artwork_valid_raises_exception( mock_graphql_gateway, mock_valid_artwork): """Test check_artwork_valid raises exception when graphql returns False.""" product_id = '12345' filename = 'image.jpg' with pytest.raises(ArtworkException): check_artwork_valid(product_id, filename) mock_valid_artwork.assert_called_once_with( mock_graphql_gateway, product_id, False ) @patch('index.valid_artwork', return_value=False) @patch('index.graphql_gateway') def test_check_artwork_valid_raises_fatal_exception( mock_graphql_gateway, mock_valid_artwork): """Test check_artwork_valid when asset status is validation_error.""" product_id = '12345' filename = 'image.jpg' mock_graphql_gateway.execute.return_value = { 'data': { 'assetStatus': { 'status': 'validation_error' } } } with pytest.raises(ArtworkFatalException): check_artwork_valid(product_id, filename) mock_valid_artwork.assert_called_once_with( mock_graphql_gateway, product_id, False ) @patch('index.StateMachineSchema.load', wrap=StateMachineSchema.load) @patch('index.StateMachineSchema.dump', wrap=StateMachineSchema.dump) @patch('index.logger') @patch('index.check_artwork_valid') def test_handler(mock_check_artwork_valid, mock_logger, mock_context_schema_dump, mock_context_schema_load, context): """Test handler.""" handler(context, None) mock_check_artwork_valid.assert_called_once() mock_context_schema_load.assert_called_once() mock_context_schema_dump.assert_called_once()