Spaces:
Running
Running
| import os | |
| import sys | |
| from fastapi.testclient import TestClient | |
| PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| if PROJECT_ROOT not in sys.path: | |
| sys.path.insert(0, PROJECT_ROOT) | |
| import main # noqa: E402 | |
| def _make_test_client(): | |
| # use test db | |
| main.db_path = os.path.join(PROJECT_ROOT, "test_focus_guard.db") | |
| if os.path.exists(main.db_path): | |
| os.remove(main.db_path) | |
| return TestClient(main.app) | |
| def test_get_settings_default_fields(): | |
| client = _make_test_client() | |
| with client: | |
| resp = client.get("/api/settings") | |
| assert resp.status_code == 200 | |
| data = resp.json() | |
| assert "model_name" in data | |
| assert "l2cs_boost" in data | |
| def test_update_settings_model_name(): | |
| client = _make_test_client() | |
| with client: | |
| r0 = client.get("/api/settings") | |
| assert r0.status_code == 200 | |
| payload = {"model_name": "xgboost"} | |
| r_put = client.put("/api/settings", json=payload) | |
| assert r_put.status_code == 200 | |
| body = r_put.json() | |
| assert body["status"] == "success" | |
| assert body["updated"] is True | |
| r1 = client.get("/api/settings") | |
| data = r1.json() | |
| assert data["model_name"] == "xgboost" | |