From 8dab23f6ac7dabe96825c7a614abdcd2a8cf473d Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Sat, 19 Sep 2026 13:10:43 -0700 Subject: [PATCH] test: cover the no-database and failed-reinit paths of the web search settings endpoints --- .../test_proxy_setting_endpoints.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py b/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py index 3288966e1e3..102b0657461 100644 --- a/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py +++ b/tests/test_litellm/proxy/ui_crud_endpoints/test_proxy_setting_endpoints.py @@ -3244,6 +3244,32 @@ class TestWebSearchInterceptionSettingsEndpoints: assert resp.status_code == 200, resp.text reapply.assert_awaited_once() + def test_get_reports_no_database_instead_of_empty_settings(self, mock_proxy_config, mock_auth, monkeypatch): + monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", None) + + resp = client.get("/get/websearch_interception_settings") + + assert resp.status_code == 500, resp.text + assert "Database not connected" in resp.json()["detail"]["error"] + + def test_update_still_saves_when_the_live_reinit_fails(self, mock_proxy_config, monkeypatch): + from unittest.mock import AsyncMock + + monkeypatch.setattr("litellm.proxy.proxy_server.store_model_in_db", True) + monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", object()) + monkeypatch.setattr( + "litellm.proxy.proxy_server.proxy_config.init_websearch_interception_settings_in_db", + AsyncMock(side_effect=RuntimeError("callback blew up")), + ) + self._override_auth(LitellmUserRoles.PROXY_ADMIN) + try: + resp = client.patch("/update/websearch_interception_settings", json={"enabled": True}) + finally: + app.dependency_overrides.clear() + + assert resp.status_code == 200, resp.text + assert mock_proxy_config["save_call_count"]() == 1 + def test_update_rejects_zero_max_agentic_loops(self, mock_proxy_config, monkeypatch): monkeypatch.setattr("litellm.proxy.proxy_server.store_model_in_db", True) self._override_auth(LitellmUserRoles.PROXY_ADMIN)