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,46 @@
|
||||
import pytest
|
||||
import httpx
|
||||
import respx
|
||||
from server.gitea_mcp import list_instances, get_server_info, get_current_user
|
||||
|
||||
BASE = "https://gitea.test/api/v1"
|
||||
|
||||
|
||||
def test_list_instances():
|
||||
result = list_instances()
|
||||
assert result["default"] == "default"
|
||||
assert "default" in result["instances"]
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_get_server_info():
|
||||
route = respx.get(f"{BASE}/version").mock(
|
||||
return_value=httpx.Response(200, json={"version": "1.22.0"})
|
||||
)
|
||||
result = get_server_info()
|
||||
assert route.called
|
||||
assert result == {"version": "1.22.0"}
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_get_server_info_error():
|
||||
respx.get(f"{BASE}/version").mock(return_value=httpx.Response(500, json={"message": "internal error"}))
|
||||
with pytest.raises(RuntimeError, match="500"):
|
||||
get_server_info()
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_get_current_user():
|
||||
route = respx.get(f"{BASE}/user").mock(
|
||||
return_value=httpx.Response(200, json={"login": "alice", "id": 1})
|
||||
)
|
||||
result = get_current_user()
|
||||
assert route.called
|
||||
assert result["login"] == "alice"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_get_current_user_error():
|
||||
respx.get(f"{BASE}/user").mock(return_value=httpx.Response(401, json={"message": "unauthorized"}))
|
||||
with pytest.raises(RuntimeError, match="401"):
|
||||
get_current_user()
|
||||
Reference in New Issue
Block a user