"""Tests for ows_moneyhub module.""" from unittest.mock import patch import httpx from owsclient.test import OwsClientMock from src.connectors.ows_service import OwsService from src.utils.constants import DEFAULT_HEADERS FAKE_SERVICE = 'fake-service' def test_get(ows_client_mock: OwsClientMock, report_custom_fixture): """Testing GET requests.""" path = f'/report-custom/{42}' OwsService._service = FAKE_SERVICE ows_client_mock.get(FAKE_SERVICE, path=path).mock( return_value=httpx.Response(status_code=200, json=report_custom_fixture) ) res = OwsService.get(path) assert res == report_custom_fixture def test_put(ows_client_mock: OwsClientMock): """Testing PUT requests.""" path = f'/report-custom/{1}' data = { 'file_location': 's3://filename.csv', 'report_custom_status': 'complete', } response_json = {'success': True} OwsService._service = FAKE_SERVICE ows_client_mock.put(FAKE_SERVICE, path=path, json=data).mock( return_value=httpx.Response(status_code=200, json=response_json) ) res = OwsService.put(path, **data) assert res == response_json @patch('src.connectors.ows_service.OWS_CLIENT_TOKEN', new=None) def test_get_request_headers_without_token(): """Test getting request headers without a token set.""" result = OwsService._get_request_headers() assert result == DEFAULT_HEADERS @patch('src.connectors.ows_service.OWS_CLIENT_TOKEN', new='abcdef') def test_get_request_headers_with_token(): """Test getting request headers with a token set.""" expected = DEFAULT_HEADERS | {'authorization': 'Bearer abcdef'} result = OwsService._get_request_headers() assert result == expected