"""Test for ows-account model.""" from unittest.mock import MagicMock from owsrequest import request as requests from features.constants import error from features.models import ows_account def test_get_subaccount_exists(monkeypatch): """Test successful retrieval of subaccount info.""" subaccount_id = 1 vendor_id = 16055 mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return_value = {'vendor_id': vendor_id} monkeypatch.setattr(requests, 'get', MagicMock(return_value=mock_response)) monkeypatch.setattr( 'features.models.ows_account.capture_message', MagicMock(), ) account_response = ows_account.get_subaccount_info(subaccount_id) assert account_response.status == 200 assert account_response.message['vendor_id'] == vendor_id def test_get_subaccount_nonexistent(monkeypatch): """Test failed retrieval of nonexistent subaccount.""" subaccount_id = 9999999999 mock_response = MagicMock() mock_response.status_code = 404 monkeypatch.setattr(requests, 'get', MagicMock(return_value=mock_response)) monkeypatch.setattr( 'features.models.ows_account.capture_message', MagicMock(), ) account_response = ows_account.get_subaccount_info(subaccount_id) assert account_response.status == 400 assert ( account_response.errors.get('code') == error.ERROR_CODE_SUBACCOUNT_DOES_NOT_EXIST ) assert ( account_response.errors.get('message') == error.ERROR_MESSAGE_SUBACCOUNT_DOES_NOT_EXIST ) def test_get_subaccount_unexpected(monkeypatch): """Test failed retrieval of nonexistent subaccount.""" subaccount_id = 'meh' mock_response = MagicMock() mock_response.status_code = 500 monkeypatch.setattr(requests, 'get', MagicMock(return_value=mock_response)) monkeypatch.setattr( 'features.models.ows_account.capture_message', MagicMock(), ) account_response = ows_account.get_subaccount_info(subaccount_id) assert account_response.status == 500