mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-08 22:22:17 +02:00
test(mcp): cover dropping of unset query params
This commit is contained in:
parent
abbb43632f
commit
b2bf925f63
1 changed files with 38 additions and 0 deletions
38
surfsense_mcp/tests/test_client_params.py
Normal file
38
surfsense_mcp/tests/test_client_params.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
"""Unset query params must be omitted, not sent as empty strings."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
from surfsense_mcp.core.client import SurfSenseClient
|
||||||
|
|
||||||
|
|
||||||
|
def _capture(client: SurfSenseClient) -> dict:
|
||||||
|
"""Swap in a mock transport that records the request it receives."""
|
||||||
|
seen: dict = {}
|
||||||
|
|
||||||
|
async def handler(request: httpx.Request) -> httpx.Response:
|
||||||
|
seen["url"] = str(request.url)
|
||||||
|
seen["params"] = dict(request.url.params)
|
||||||
|
return httpx.Response(200, json={"ok": True})
|
||||||
|
|
||||||
|
client._http = httpx.AsyncClient(
|
||||||
|
base_url="http://test/api/v1", transport=httpx.MockTransport(handler)
|
||||||
|
)
|
||||||
|
return seen
|
||||||
|
|
||||||
|
|
||||||
|
def test_none_params_are_dropped():
|
||||||
|
client = SurfSenseClient(api_base="http://test/api/v1", pat="ss_pat_x", timeout=5)
|
||||||
|
seen = _capture(client)
|
||||||
|
asyncio.run(
|
||||||
|
client.request(
|
||||||
|
"GET",
|
||||||
|
"/documents",
|
||||||
|
params={"workspace_id": 1, "document_types": None, "folder_id": None},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert seen["params"] == {"workspace_id": "1"}
|
||||||
|
assert "folder_id" not in seen["url"]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue