Files
wecom-ai-assistant/backend/tests/test_auth.py
2026-02-05 16:36:32 +08:00

27 lines
831 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""登录接口测试。"""
import pytest
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_login_fail_wrong_password():
r = client.post("/api/auth/login", json={"username": "admin", "password": "wrong"})
assert r.status_code == 401
def test_login_fail_wrong_user():
r = client.post("/api/auth/login", json={"username": "nobody", "password": "admin"})
assert r.status_code == 401
def test_login_returns_json():
"""无 DB 时可能 401有 DB 且 admin 存在时 200。仅断言响应为 JSON 且含 code。"""
r = client.post("/api/auth/login", json={"username": "admin", "password": "admin"})
assert r.headers.get("content-type", "").startswith("application/json")
data = r.json()
assert "code" in data
assert "trace_id" in data