"""Tests for artist_info logic.""" import pytest import const # noqa import index # noqa from logic import artist_info from models import ows_artist def test_prepare_doc_artistinfo_add( mocker, artist_document_fixture, artist_cloudsearch_document, converted_artist_event_fixture): """Test prepare cloudsearch document.""" mocker.patch.object( ows_artist, 'get_artist_document', return_value=artist_document_fixture) doc = artist_info.prepare_doc(converted_artist_event_fixture) assert doc == artist_cloudsearch_document def test_prepare_doc_artistinfo_delete( artist_cloudsearch_document, converted_artist_event_fixture): """Test prepare cloudsearch document for deletion.""" delete_event = converted_artist_event_fixture.copy() delete_doc = artist_cloudsearch_document.copy() delete_event['type'] = 'delete' delete_doc['type'] = 'delete' delete_doc.pop('fields') doc = artist_info.prepare_doc(delete_event) assert doc == delete_doc def test_prepare_doc_artist_incompatible( mocker, converted_artist_event_fixture): """Test prepare cloudsearch document with incompatible format.""" delete_event = converted_artist_event_fixture.copy() del delete_event['type'] doc = artist_info.prepare_doc(delete_event) assert doc == {} @pytest.mark.parametrize( 'mock_object,mock_method,exception_message', [ (ows_artist, 'get_artist_document', const.OWS_ARTIST_ERROR) ] ) def test_prepare_doc_artist_error( mocker, converted_artist_event_fixture, mock_object, mock_method, exception_message): """Test prepare cloudsearch document ows-artist error.""" mocker.patch.object( mock_object, mock_method, side_effect=Exception(exception_message)) with pytest.raises(Exception, match=exception_message): ows_artist.get_artist_document(converted_artist_event_fixture)