test: add 106 unit + smoke tests, 93% coverage
- pytest + respx + pytest-cov added as dev dependencies - tests/smoke/test_registration.py: verify all 66 tools registered and unique - tests/unit/: 12 files covering every tool — HTTP method, URL, params/body, errors - tests/config.test.json + conftest.py: zero-network test setup via GITEA_CONFIG - CLAUDE.md: developer guide with testing philosophy, pyramid, and commands - server/gitea_mcp.py: get_commit, list_pr_files tools added - README.md: tool count corrected to 66
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import json
|
||||
import pytest
|
||||
import httpx
|
||||
import respx
|
||||
from server.gitea_mcp import list_notifications, mark_all_notifications_read
|
||||
|
||||
BASE = "https://gitea.test/api/v1"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_list_notifications_defaults():
|
||||
route = respx.get(f"{BASE}/notifications").mock(
|
||||
return_value=httpx.Response(200, json=[{"id": 1, "unread": True}])
|
||||
)
|
||||
result = list_notifications()
|
||||
assert route.called
|
||||
params = dict(route.calls[0].request.url.params)
|
||||
assert params["limit"] == "20"
|
||||
assert params["all"] == "false"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_list_notifications_include_read():
|
||||
route = respx.get(f"{BASE}/notifications").mock(
|
||||
return_value=httpx.Response(200, json=[])
|
||||
)
|
||||
list_notifications(include_read=True)
|
||||
params = dict(route.calls[0].request.url.params)
|
||||
assert params["all"] == "true"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_list_notifications_error():
|
||||
respx.get(f"{BASE}/notifications").mock(
|
||||
return_value=httpx.Response(401, json={"message": "unauthorized"})
|
||||
)
|
||||
with pytest.raises(RuntimeError, match="401"):
|
||||
list_notifications()
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_mark_all_notifications_read():
|
||||
route = respx.put(f"{BASE}/notifications").mock(
|
||||
return_value=httpx.Response(205)
|
||||
)
|
||||
result = mark_all_notifications_read()
|
||||
assert route.called
|
||||
Reference in New Issue
Block a user