From fd46492012da77a932d2f1757ca1c2e3c7243de5 Mon Sep 17 00:00:00 2001 From: liumangmang Date: Wed, 1 Jul 2026 18:02:10 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A1=A5=E5=85=85=E5=9F=BA=E4=BA=8E=20?= =?UTF-8?q?TestClient=20=E7=9A=84=E8=B7=AF=E7=94=B1=E7=BA=A7=E9=9B=86?= =?UTF-8?q?=E6=88=90=E6=B5=8B=E8=AF=95=EF=BC=8C=E9=94=81=E6=AD=BB=E5=B9=B6?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=20group=5Fid=20=E5=8C=85=E5=90=AB=E6=96=9C?= =?UTF-8?q?=E6=9D=A0=E6=97=B6=E7=9A=84=E8=B7=AF=E5=BE=84=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=99=A8=E5=8C=B9=E9=85=8D=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/test_website_group_mgmt.py | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/backend/test_website_group_mgmt.py b/backend/test_website_group_mgmt.py index 5ec1fa0..7905eeb 100644 --- a/backend/test_website_group_mgmt.py +++ b/backend/test_website_group_mgmt.py @@ -92,3 +92,57 @@ def test_create_and_update_website_group(db_session, monkeypatch): # Verify that local binding was updated db_session.refresh(b) assert b.target_group_name == "UpdatedGroup" + + +def test_update_website_group_route_handles_slash(db_session, monkeypatch): + from fastapi.testclient import TestClient + from app.main import app + from app.database import get_db + from app.utils.auth import get_current_user + + w = Website( + name="W1", + site_type="sub2api", + base_url="http://w1", + enabled=True, + auth_config_json="{}", + timeout_seconds=30 + ) + db_session.add(w) + db_session.commit() + db_session.refresh(w) + + called_update = [] + + class FakeClient: + def __init__(self, *args, **kwargs): + pass + def __enter__(self): + return self + def __exit__(self, *args): + pass + def update_group(self, endpoint_template, group_id, body): + called_update.append((endpoint_template, group_id, body)) + return {"id": group_id, "name": body["name"], "description": body.get("description")} + + monkeypatch.setattr("app.routers.websites._client", lambda website: FakeClient()) + + # Set dependency overrides + app.dependency_overrides[get_db] = lambda: db_session + app.dependency_overrides[get_current_user] = lambda: None + + try: + client = TestClient(app) + # request URL with urlencoded slash: g%2F123 + resp = client.put( + f"/api/websites/{w.id}/groups/g%2F123", + json={"name": "UpdatedGroup", "description": "UpdatedDesc"} + ) + assert resp.status_code == 200 + data = resp.json() + assert data["id"] == "g/123" + assert data["name"] == "UpdatedGroup" + assert len(called_update) == 1 + assert called_update[0][1] == "g/123" + finally: + app.dependency_overrides.clear()