"""Tests for ows_product model.""" from unittest.mock import MagicMock import pytest import requests import const # noqa import index # noqa from models import ows_account def test_get_account_document_for_subaccount( mocker, subaccount_document_fixture, subaccount_id): """Test get subaccount info from ows-account successfully.""" mocker.patch( 'requests.get', return_value=MagicMock( spec=requests.models.Response, status_code=200, json=lambda: subaccount_document_fixture)) result = ows_account.get_account_document(subaccount_id, 'subaccount') assert result == subaccount_document_fixture def test_get_account_document_for_subaccount_not_found( mocker, ows_not_found_response, subaccount_id): """Test get account document for subaccount from ows-account not found.""" mocker.patch( 'requests.get', return_value=ows_not_found_response) result = ows_account.get_account_document(subaccount_id, 'subaccount') assert result == {} def test_get_account_document_for_subaccount_error( mocker, ows_error_response, subaccount_id): """Test get account document for subaccount from ows-account error.""" mocker.patch( 'requests.get', return_value=ows_error_response) with pytest.raises(Exception, match=const.OWS_ACCOUNT_ERROR.format('subaccount')): ows_account.get_account_document(subaccount_id, 'subaccount') def test_get_account_document_for_vendor( mocker, vendor_document_fixture, vendor_id): """Test get vendor info from ows-account successfully.""" mocker.patch( 'requests.get', return_value=MagicMock( spec=requests.models.Response, status_code=200, json=lambda: vendor_document_fixture)) result = ows_account.get_account_document(vendor_id, 'vendor') assert result == vendor_document_fixture def test_get_account_document_for_vendor_not_found( mocker, ows_not_found_response, vendor_id): """Test get account document for vendor from ows-account not found.""" mocker.patch( 'requests.get', return_value=ows_not_found_response) result = ows_account.get_account_document(vendor_id, 'vendor') assert result == {} def test_get_account_document_for_vendor_error( mocker, ows_error_response, vendor_id): """Test get account document for vendor from ows-account error.""" mocker.patch( 'requests.get', return_value=ows_error_response) with pytest.raises(Exception, match=const.OWS_ACCOUNT_ERROR.format('vendor')): ows_account.get_account_document(vendor_id, 'vendor')