签入版本
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""集成冒烟测试:登录链路 + 各模块只读接口(需 MySQL/Redis 运行,默认跳过)。"""
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_flow(client):
|
||||
"""完整登录链路:/api/v1/captcha → 解析验证码 → /api/v1/login 获取 token。"""
|
||||
import redis as redis_lib
|
||||
|
||||
from core.config import REDIS_AUTH, REDIS_HOST, REDIS_INDEX, REDIS_PASSWORD, REDIS_PORT
|
||||
|
||||
r = await client.get("/api/v1/captcha")
|
||||
body = r.json()
|
||||
assert body["code"] == 0
|
||||
idkey = body.get("idkey")
|
||||
assert idkey
|
||||
|
||||
# 从 Redis 读取验证码明文(带认证参数,与 app 连接一致)
|
||||
redis_client = redis_lib.Redis(
|
||||
host=REDIS_HOST, port=REDIS_PORT,
|
||||
password=REDIS_PASSWORD if REDIS_AUTH else None,
|
||||
db=REDIS_INDEX,
|
||||
)
|
||||
code = redis_client.get(idkey).decode()
|
||||
|
||||
resp = await client.post("/api/v1/login", json={
|
||||
"username": "admin", "password": "123456",
|
||||
"code": code, "key": idkey,
|
||||
})
|
||||
login = resp.json()
|
||||
assert login["code"] == 0
|
||||
assert login["data"]["access_token"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_read_endpoints(client, admin_headers):
|
||||
"""管理员 token 可访问代表性只读接口。"""
|
||||
for path in ("/api/v1/user/page", "/api/v1/dept/list", "/api/v1/menu/list",
|
||||
"/api/v1/index/menu", "/api/v1/job/page"):
|
||||
resp = await client.get(path, headers=admin_headers)
|
||||
assert resp.json()["code"] == 0, f"{path} failed"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unauthorized_blocked(client):
|
||||
"""无 token 访问受保护接口应返回 401。"""
|
||||
resp = await client.get("/api/v1/user/page")
|
||||
assert resp.json()["code"] == 401
|
||||
Reference in New Issue
Block a user