mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
Rename the import package surfsense_mcp -> mcp_server and remove the src/ layer so the project mirrors the backend's shape (project folder != package name, e.g. surfsense_backend/app). Kills the redundant surfsense_mcp/src/surfsense_mcp nesting. Distribution name and console command (surfsense-mcp) are unchanged; only python -m and internal import paths move to mcp_server. Dockerfile CMD updated; no PYTHONPATH added since the editable install already makes the package importable.
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""HTTP failure translation: status hints, server detail, and body parsing."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import httpx
|
|
|
|
from mcp_server.core.client import SurfSenseClient
|
|
|
|
_REQUEST = httpx.Request("GET", "http://localhost:8000/api/v1/documents")
|
|
|
|
|
|
def _response(status: int, **kwargs) -> httpx.Response:
|
|
return httpx.Response(status, request=_REQUEST, **kwargs)
|
|
|
|
|
|
def test_explains_401_with_token_hint():
|
|
message = SurfSenseClient._explain_failure(_response(401, json={"detail": "bad"}))
|
|
assert "API key" in message
|
|
assert "bad" in message
|
|
|
|
|
|
def test_explains_403_as_access_or_api_disabled():
|
|
message = SurfSenseClient._explain_failure(_response(403, json={"detail": "no"}))
|
|
assert "API access" in message
|
|
|
|
|
|
def test_extracts_nested_detail_message():
|
|
response = _response(402, json={"detail": {"message": "out of credits"}})
|
|
assert "out of credits" in SurfSenseClient._explain_failure(response)
|
|
|
|
|
|
def test_unmapped_status_still_reports_detail():
|
|
message = SurfSenseClient._explain_failure(_response(500, json={"detail": "boom"}))
|
|
assert "500" in message and "boom" in message
|
|
|
|
|
|
def test_parses_json_body():
|
|
assert SurfSenseClient._parse_body(_response(200, json={"ok": 1})) == {"ok": 1}
|
|
|
|
|
|
def test_empty_body_parses_to_none():
|
|
assert SurfSenseClient._parse_body(_response(204, content=b"")) is None
|
|
|
|
|
|
def test_non_json_body_falls_back_to_text():
|
|
assert SurfSenseClient._parse_body(_response(200, text="hello")) == "hello"
|