fix: align all 212 tests with current API and add CI workflows
Some checks failed
Test / test (push) Failing after 1m4s

Update integration tests to match actual endpoint responses: remove
data wrappers, use snake_case fields, correct HTTP methods (PUT→POST
for directory create), status codes (200→204 for mutations), and
request formats (params→json for 2FA). Fix root-level and unit tests
for DatabaseManager migration, model CRUD patterns, and JWT setup.
Add GitHub Actions and Gitea CI configs with ubuntu-latest + Python 3.13.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 14:21:40 +08:00
parent 800c85bf8d
commit 69f852a4ce
20 changed files with 480 additions and 586 deletions

View File

@@ -8,102 +8,85 @@ from httpx import AsyncClient
@pytest.mark.asyncio
async def test_site_ping(async_client: AsyncClient):
"""测试 /api/site/ping 返回 200"""
response = await async_client.get("/api/site/ping")
response = await async_client.get("/api/v1/site/ping")
assert response.status_code == 200
@pytest.mark.asyncio
async def test_site_ping_response_format(async_client: AsyncClient):
"""测试 /api/site/ping 响应包含版本号"""
response = await async_client.get("/api/site/ping")
"""测试 /api/site/ping 响应包含 instance_id"""
response = await async_client.get("/api/v1/site/ping")
assert response.status_code == 200
data = response.json()
assert "data" in data
# BackendVersion 应该是字符串格式的版本号
assert isinstance(data["data"], str)
assert "instance_id" in data
@pytest.mark.asyncio
async def test_site_config(async_client: AsyncClient):
"""测试 /api/site/config 返回配置"""
response = await async_client.get("/api/site/config")
response = await async_client.get("/api/v1/site/config")
assert response.status_code == 200
data = response.json()
assert "data" in data
assert "title" in data
assert "register_enabled" in data
@pytest.mark.asyncio
async def test_site_config_contains_title(async_client: AsyncClient):
"""测试配置包含站点标题"""
response = await async_client.get("/api/site/config")
response = await async_client.get("/api/v1/site/config")
assert response.status_code == 200
data = response.json()
config = data["data"]
assert "title" in config
assert config["title"] == "DiskNext Test"
@pytest.mark.asyncio
async def test_site_config_contains_themes(async_client: AsyncClient):
"""测试配置包含主题设置"""
response = await async_client.get("/api/site/config")
assert response.status_code == 200
data = response.json()
config = data["data"]
assert "themes" in config
assert "defaultTheme" in config
assert "title" in data
assert data["title"] == "DiskNext Test"
@pytest.mark.asyncio
async def test_site_config_register_enabled(async_client: AsyncClient):
"""测试配置包含注册开关"""
response = await async_client.get("/api/site/config")
response = await async_client.get("/api/v1/site/config")
assert response.status_code == 200
data = response.json()
config = data["data"]
assert "registerEnabled" in config
assert config["registerEnabled"] is True
assert "register_enabled" in data
assert data["register_enabled"] is True
@pytest.mark.asyncio
async def test_site_config_captcha_settings(async_client: AsyncClient):
"""测试配置包含验证码设置"""
response = await async_client.get("/api/site/config")
response = await async_client.get("/api/v1/site/config")
assert response.status_code == 200
data = response.json()
config = data["data"]
assert "loginCaptcha" in config
assert "regCaptcha" in config
assert "forgetCaptcha" in config
assert "login_captcha" in data
assert "reg_captcha" in data
assert "forget_captcha" in data
@pytest.mark.asyncio
async def test_site_config_auth_methods(async_client: AsyncClient):
"""测试配置包含认证方式列表"""
response = await async_client.get("/api/site/config")
response = await async_client.get("/api/v1/site/config")
assert response.status_code == 200
data = response.json()
config = data["data"]
assert "authMethods" in config
assert isinstance(config["authMethods"], list)
assert len(config["authMethods"]) > 0
assert "auth_methods" in data
assert isinstance(data["auth_methods"], list)
assert len(data["auth_methods"]) > 0
# 每个认证方式应包含 provider 和 isEnabled
for method in config["authMethods"]:
# 每个认证方式应包含 provider 和 is_enabled
for method in data["auth_methods"]:
assert "provider" in method
assert "isEnabled" in method
assert "is_enabled" in method
@pytest.mark.asyncio
async def test_site_captcha_endpoint_exists(async_client: AsyncClient):
"""测试验证码端点存在(即使未实现也应返回有效响应)"""
response = await async_client.get("/api/site/captcha")
response = await async_client.get("/api/v1/site/captcha")
# 未实现的端点可能返回 404 或其他状态码
assert response.status_code in [200, 404, 501]