"""Tests for vendor logic.""" import pytest import const # noqa import index # noqa from logic import vendor from models import ows_account def test_prepare_doc_vendor_add( mocker, vendor_document_fixture, vendor_cloudsearch_document, converted_vendor_event_fixture): """Test prepare cloudsearch document.""" mocker.patch.object( ows_account, 'get_account_document', return_value=vendor_document_fixture) doc = vendor.prepare_doc(converted_vendor_event_fixture) assert doc == vendor_cloudsearch_document def test_prepare_doc_vendor_delete( vendor_cloudsearch_document, converted_vendor_event_fixture): """Test prepare cloudsearch document for deletion.""" delete_event = converted_vendor_event_fixture.copy() delete_doc = vendor_cloudsearch_document.copy() delete_event['type'] = 'delete' delete_doc['type'] = 'delete' delete_doc.pop('fields') doc = vendor.prepare_doc(delete_event) assert doc == delete_doc def test_prepare_doc_vendor_incompatible( mocker, converted_vendor_event_fixture): """Test prepare cloudsearch document with incompatible format.""" delete_event = converted_vendor_event_fixture.copy() del delete_event['type'] doc = vendor.prepare_doc(delete_event) assert doc == {} @pytest.mark.parametrize( 'mock_object,mock_method,exception_message', [ (ows_account, 'get_account_document', const.OWS_ACCOUNT_ERROR.format('vendor')) ] ) def test_prepare_doc_vendor_error( mocker, converted_vendor_event_fixture, mock_object, mock_method, exception_message): """Test prepare cloudsearch document ows-account error.""" mocker.patch.object( mock_object, mock_method, side_effect=Exception(exception_message)) with pytest.raises(Exception, match=exception_message): vendor.prepare_doc(converted_vendor_event_fixture)