refactor: tests目录精简重构 + 脏数据清理脚本

- 删除16个旧Python测试文件(970行→400行)
- 重写conftest.py适配真实种子用户(admin/test123/test234/testtest/logan)
- 5个精简测试文件覆盖核心API:
  - test_auth.py: 登录/鉴权/种子用户验证 (6 tests)
  - test_instances.py: 实例列表/详情/连接测试 (6 tests)
  - test_tickets.py: 工单CRUD/只读SQL拦截/auditor权限 (7 tests)
  - test_workflow.py: E2E完整审批流/拒绝/撤销 (3 tests)
  - test_permissions.py: 角色权限/执行权限/workflow权限 (6 tests)
- 新增 cleanup_test_data.py 清理测试脏数据(支持--dry-run)
- 全量29测试3.27s通过
This commit is contained in:
logan committed 2026-06-03 02:24:40 +08:00
1 parent bec2cafec2
commit 2984f11181
22 files changed
+408 -978

No files matched your search

+22 -10
View File
@@ -1,39 +1,51 @@
"""Auth endpoint tests — Go/Gin backend."""
"""Auth API tests"""
import pytest
from httpx import AsyncClient
from tests.conftest import auth_header
def auth_header(token: str) -> dict:
return {"Authorization": f"Bearer {token}"}
class TestLogin:
async def test_admin_login(self, client: AsyncClient):
resp = await client.post("/api/v1/auth/login", json={
"username": "admin", "password": "admin123"
"username": "admin", "password": "admin123",
})
assert resp.status_code == 200
data = resp.json()
assert "access_token" in data
assert "access_token" in resp.json()
async def test_all_seed_users_login(self, client: AsyncClient):
"""验证所有种子用户都能登录"""
users = {
"admin": "admin123", "test123": "test123",
"test234": "test234", "testtest": "testtest", "logan": "zxc987",
}
for username, password in users.items():
resp = await client.post("/api/v1/auth/login", json={
"username": username, "password": password,
})
assert resp.status_code == 200, f"{username} login failed"
assert "access_token" in resp.json()
async def test_wrong_password(self, client: AsyncClient):
resp = await client.post("/api/v1/auth/login", json={
"username": "admin", "password": "wrong"
"username": "admin", "password": "wrong",
})
assert resp.status_code == 401
async def test_nonexistent_user(self, client: AsyncClient):
resp = await client.post("/api/v1/auth/login", json={
"username": "nobody", "password": "test"
"username": "nobody", "password": "xxx",
})
assert resp.status_code == 401
class TestGetMe:
async def test_get_me(self, client: AsyncClient, admin_token: str):
async def test_get_me(self, client: AsyncClient, admin_token):
resp = await client.get("/api/v1/auth/me", headers=auth_header(admin_token))
assert resp.status_code == 200
data = resp.json()
assert data["username"] == "admin"
assert "role" in data
assert "id" in data
assert data["role"] == "admin"
async def test_no_token(self, client: AsyncClient):
resp = await client.get("/api/v1/auth/me")