"""Test the owsclient utility.""" import httpx from owsclient.test import OwsClientMock import pytest from moneyhub.utils import owsclient def test_get(ows_client_mock: OwsClientMock): """Test sending a GET request.""" example_response = {'success': 'yes'} ows_client_mock.get( 'ows-moneyhub', '/just/a/test' ).mock( return_value=httpx.Response(200, json=example_response) ) result = owsclient.get('ows-moneyhub', '/just/a/test') assert result.status_code == 200 assert result.json() == example_response def test_get_error(ows_client_mock: OwsClientMock): """Test sending a GET request and receiving a non-success response.""" ows_client_mock.get( 'ows-moneyhub', '/just/a/test' ).mock( return_value=httpx.Response(402, json={'error': 'yes'}) ) with pytest.raises(Exception) as excinfo: owsclient.get('ows-moneyhub', '/just/a/test') assert str(excinfo.value) == 'Unexpected response from ows-moneyhub (402): {"error":"yes"}'