"""Unit testcases for request methods.""" import httpx from owsclient.test import OwsClientMock import pytest from adjustment_file_import import requests def test_get(ows_client_mock: OwsClientMock) -> None: """Test GET method.""" path = '/object/object_id' service = 'ows-service' options = {'timeout': 3} ows_client_mock.get( service, path, ).mock(return_value=httpx.Response(200, json={})) actual = requests.get(path, service, **options) assert actual.status_code == 200 assert actual.json() == {} def test_post(ows_client_mock: OwsClientMock) -> None: """Test post method.""" body = {'target_id': 666} path = '/object/object_id' service = 'ows-service' options = {'timeout': 3} ows_client_mock.post( service, path, json=body, ).mock(return_value=httpx.Response(201, json={})) actual = requests.post(body, path, service, **options) assert actual.status_code == 201 assert actual.json() == {} 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)