Quellcode durchsuchen

add intergration test

Khanh Nguyen vor 5 Monaten
Ursprung
Commit
e1326ac4f4
2 geänderte Dateien mit 55 neuen und 0 gelöschten Zeilen
  1. 14 0
      pyproject.toml
  2. 41 0
      tests/test_integration_get_resource.py

+ 14 - 0
pyproject.toml

@@ -20,6 +20,20 @@ dev = [
 ]
 
 [tool.pytest.ini_options]
+addopts = "--cov=src --cov-report=term-missing --cov-report=html"
 testpaths = ["tests"]
 pythonpath = ["."]
+markers = [
+    "integration: tests live necessitant .env et RUN_INTEGRATION_TESTS=1",
+]
+
+[tool.coverage.run]
+branch = true  # Tracks whether both True and False paths of "if" statements are tested
 
+[tool.coverage.report]
+exclude_lines = [
+    "pragma: no cover",
+    "def __repr__",
+    "if __name__ == .__main__.:",
+    "raise NotImplementedError"
+]

+ 41 - 0
tests/test_integration_get_resource.py

@@ -0,0 +1,41 @@
+"""Test d'integration live pour modx://resource/{id}."""
+
+from __future__ import annotations
+
+import os
+
+import pytest
+from mcp.client.session import ClientSession
+
+from src.server_mcp.resources import _GET_RESOURCE_WHITELIST
+from tests.conftest import read_resource_json
+
+# ID par defaut : Accueil (cf. .cursor/docs/architecture.md)
+DEFAULT_RESOURCE_ID = "10000"
+
+
+@pytest.mark.integration
+@pytest.mark.anyio
+async def test_get_resource_live_via_mcp_client_session(
+    live_mcp_session: ClientSession,
+) -> None:
+    """
+    Parcours complet : ClientSession MCP -> serveur FastMCP -> ClientRest -> API LWE.
+
+    Activation :
+        RUN_INTEGRATION_TESTS=1 uv run pytest tests/test_integration_get_resource.py -v --no-cov
+
+    Optionnel :
+        INTEGRATION_RESOURCE_ID=10000
+    """
+    resource_id = os.getenv("INTEGRATION_RESOURCE_ID", DEFAULT_RESOURCE_ID)
+
+    result = await read_resource_json(
+        live_mcp_session,
+        f"modx://resource/{resource_id}",
+    )
+
+    assert isinstance(result, dict)
+    assert result["id"] == int(resource_id)
+    assert set(result.keys()).issubset(_GET_RESOURCE_WHITELIST)
+    assert "pagetitle" in result or "alias" in result