"""Unit testcases for request methods.""" import httpx import pytest from owsclient.test import OwsClientMock from adjustment_file_validation import requests def test_get(ows_client_mock: OwsClientMock): """Test GET method.""" path = '/object/object_id' service = 'ows-service' options = {'headers': {'foo': 'bar'}} route = ows_client_mock.get(service, path, **options) route.mock(return_value=httpx.Response(200, json={})) requests.get(path=path, service=service, **options) assert route.call_count == 1 def test_put(ows_client_mock: OwsClientMock): """Test PUT method.""" body = {'target_id': 666} path = '/object/object_id' service = 'ows-service' options = {'headers': {'foo': 'bar'}} route = ows_client_mock.put(service_name=service, path=path, json=body, **options) route.mock(return_value=httpx.Response(200, json={})) requests.put(path=path, service=service, body=body, **options) assert route.call_count == 1 def test_raise_service_error(): """Test raise_service_error logs error and raises exception.""" error_msg = 'ERROR to GET /object/object_id' service = 'ows-service' with pytest.raises(requests.OwsServiceException) as e: requests.raise_service_error(error_msg, service) assert f'{service} failure: {error_msg}' in str(e.value) def test_raise_service_error_with_kwargs(): """Test raise_service_error logs error and raises exception with kwargs.""" data = {'target_id': 666} error_msg = 'ERROR to GET /object/object_id' service = 'ows-service' with pytest.raises(requests.OwsServiceException) as e: requests.raise_service_error(error_msg, service, **data) assert f'{service} failure: {error_msg} {data}' in str(e.value)