"""Tests for ows_account model.""" from unittest.mock import MagicMock from owsrequest import request from owsrequest import test_utils from ows_accounting import response from ows_accounting.models import ows_account def test_check_vendor_exist(monkeypatch): """Test check_vendor_exists.""" call_specs = [{ 'service': ows_account.ACCOUNT_SERVICE, 'path': '/vendor/7123', 'status': 200}] monkeypatch.setattr( request, 'head', test_utils.mock_ows_requests(call_specs)) actual_response = ows_account.check_vendor_exists(7123) assert actual_response assert actual_response.message == 'Vendor exist.' def test_check_vendor_exist_invalid(monkeypatch): """Test check_vendor_exists for invalid id.""" call_specs = [{ 'service': ows_account.ACCOUNT_SERVICE, 'path': '/vendor/123456', 'status': 404}] monkeypatch.setattr( request, 'head', test_utils.mock_ows_requests(call_specs)) actual_response = ows_account.check_vendor_exists(123456) assert not actual_response assert actual_response.errors['message'] == 'No vendor found with this id.' def test_check_vendor_exist_server_error(monkeypatch): """Test check_vendor_exists for server_error.""" call_specs = [{ 'service': ows_account.ACCOUNT_SERVICE, 'path': '/vendor/7123', 'status': 500, 'json': {'server': 'error'}}] monkeypatch.setattr( request, 'head', test_utils.mock_ows_requests(call_specs)) monkeypatch.setattr( response, 'send_to_sentry', MagicMock(return_value=True)) expected_response = '{"server": "error"}' actual_response = ows_account.check_vendor_exists(7123) assert not actual_response assert actual_response.errors['message'] == expected_response