From 390b8e810db5d9b3662e0c5d63b584ecb0a8f8f8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 17:42:34 +0000 Subject: [PATCH 1/2] Initial plan From 6a2166a1dfc4ff20cb797739e4a0ef8a730a4fef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 17:46:56 +0000 Subject: [PATCH 2/2] fix: remove websocket_connect and properly mock require_admin dependency Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/test_api_settings.py | 39 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/test_api_settings.py b/tests/test_api_settings.py index 8c3a79de..098d1295 100644 --- a/tests/test_api_settings.py +++ b/tests/test_api_settings.py @@ -88,26 +88,31 @@ class TestSettingsEndpointsWithAuth: @patch("app.api.settings.get_setting_metadata") def test_get_all_settings_success(self, mock_metadata, mock_categories, mock_db_settings, client, db_session): """Test GET /settings returns all settings.""" - # Mock admin session - with client as test_client: - with test_client.websocket_connect("/") as ws: - pass # Just to establish session - test_client.cookies.set("session", "test_session") + from app.api.settings import require_admin + from app.main import app as fastapi_app - # Mock the settings data - mock_db_settings.return_value = {"test_key": "test_value"} - mock_categories.return_value = {"General": ["workdir", "debug"]} - mock_metadata.return_value = {"type": "str", "description": "Test setting"} + # Mock the settings data + mock_db_settings.return_value = {"test_key": "test_value"} + mock_categories.return_value = {"General": ["workdir", "debug"]} + mock_metadata.return_value = {"type": "str", "description": "Test setting"} - # Create mock request with admin user - mock_request = Mock() - mock_request.session = {"user": {"id": "admin", "is_admin": True}} + # Override the require_admin dependency to return a mock admin user + def override_require_admin(): + return {"id": "admin", "is_admin": True} - # The endpoint requires admin auth, so this will fail without proper session setup - # We're testing the logic, not the full auth flow - response = test_client.get("/api/settings/") - # Should be 403 without proper admin session - assert response.status_code in [302, 401, 403] + fastapi_app.dependency_overrides[require_admin] = override_require_admin + + try: + # Make the request with the mocked admin dependency + response = client.get("/api/settings/") + assert response.status_code == 200 + data = response.json() + assert "settings" in data + assert "categories" in data + assert "db_settings" in data + finally: + # Clean up the override + fastapi_app.dependency_overrides.pop(require_admin, None) @patch("app.api.settings.get_setting_metadata") def test_get_single_setting_returns_metadata(self, mock_metadata, client):