From da2a67bc91ddf16a0834b1cea23b7f8d6f2cab5d Mon Sep 17 00:00:00 2001 From: itqop Date: Thu, 25 Dec 2025 10:16:33 +0300 Subject: [PATCH] fixes --- coverage.xml | 16 ++++++++-------- static/api-client.js | 2 +- static/app.js | 10 +++++----- tests/unit/test_base_interface.py | 27 ++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/coverage.xml b/coverage.xml index f5a5b04..9ad0d56 100644 --- a/coverage.xml +++ b/coverage.xml @@ -1,5 +1,5 @@ - + @@ -339,13 +339,13 @@ - + - + @@ -415,11 +415,11 @@ - - - - - + + + + + diff --git a/static/api-client.js b/static/api-client.js index 5fed10d..2bce08d 100644 --- a/static/api-client.js +++ b/static/api-client.js @@ -135,7 +135,7 @@ class BriefBenchAPI { */ async updateSettings(settings) { return await this._request('/settings', { - method: 'PUT', + method: 'PATCH', headers: this._getHeaders(), body: JSON.stringify({ settings }) }) diff --git a/static/app.js b/static/app.js index 7d630ea..6ccc50d 100644 --- a/static/app.js +++ b/static/app.js @@ -346,11 +346,11 @@ async function saveSettingsToServer(settings) { function extractEnvironmentSettings(envSettings) { return { apiMode: envSettings.apiMode, - bearerToken: envSettings.bearerToken || '', - systemPlatform: envSettings.systemPlatform || '', - systemPlatformUser: envSettings.systemPlatformUser || '', - platformUserId: envSettings.platformUserId || '', - platformId: envSettings.platformId || '', + bearerToken: envSettings.bearerToken || null, + systemPlatform: envSettings.systemPlatform || null, + systemPlatformUser: envSettings.systemPlatformUser || null, + platformUserId: envSettings.platformUserId || null, + platformId: envSettings.platformId || null, withClassify: envSettings.withClassify || false, resetSessionMode: envSettings.resetSessionMode !== false } diff --git a/tests/unit/test_base_interface.py b/tests/unit/test_base_interface.py index 7c319f8..486ab58 100644 --- a/tests/unit/test_base_interface.py +++ b/tests/unit/test_base_interface.py @@ -296,7 +296,7 @@ class TestTgBackendInterface: mock_client = AsyncMock() mock_response = MagicMock() mock_response.status_code = 200 - mock_response.content = b'{"name": "updated", "value": 75}' + mock_response.content = b'{"name": "updated", "value": 75}' mock_response.json.return_value = {"name": "updated", "value": 75} mock_response.raise_for_status = MagicMock() mock_client.put.return_value = mock_response @@ -313,6 +313,31 @@ class TestTgBackendInterface: call_args = mock_client.put.call_args assert call_args[0][0] == "http://api.example.com/users/1" + @pytest.mark.asyncio + async def test_patch_success(self): + """Test successful PATCH request.""" + mock_client = AsyncMock() + mock_response = MagicMock() + mock_response.status_code = 200 + mock_response.content = b'{"name": "patched", "value": 150}' + mock_response.json.return_value = {"name": "patched", "value": 150} + mock_response.raise_for_status = MagicMock() + mock_client.patch = AsyncMock(return_value=mock_response) + + with patch('app.interfaces.base.httpx.AsyncClient', return_value=mock_client): + interface = TgBackendInterface(api_prefix="http://api.example.com") + body = SampleModel(name="patched", value=150) + + result = await interface.patch("/users/1", body=body, response_model=SampleModel) + + assert isinstance(result, SampleModel) + assert result.name == "patched" + assert result.value == 150 + mock_client.patch.assert_called_once() + call_args = mock_client.patch.call_args + assert call_args[0][0] == "http://api.example.com/users/1" + assert call_args[1]['json'] == {"name": "patched", "value": 150} + @pytest.mark.asyncio async def test_delete_success(self): """Test successful DELETE request."""