35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from app.db import auth_db
|
|
from app.web import web_server
|
|
|
|
|
|
def _login_admin(email: str = "chat-log-admin@example.com", password: str = "StrongPass123") -> str:
|
|
reg = auth_db.register_user(email, password)
|
|
auth_db.verify_email(email, reg["verification_code"])
|
|
auth_db.set_user_admin(email, True)
|
|
return auth_db.login_user(email, password)["token"]
|
|
|
|
|
|
def test_chat_logs_page_requires_admin():
|
|
client = TestClient(web_server.app)
|
|
resp = client.get("/chat-logs")
|
|
assert resp.status_code in (200, 307)
|
|
|
|
|
|
def test_chat_logs_admin_page_and_api():
|
|
token = _login_admin()
|
|
client = TestClient(web_server.app)
|
|
client.cookies.set("altcoin_session", token)
|
|
|
|
page = client.get("/chat-logs")
|
|
overview = client.get("/api/admin/chat-logs/overview")
|
|
listing = client.get("/api/admin/chat-logs")
|
|
|
|
assert page.status_code == 200
|
|
assert "问答日志" in page.text
|
|
assert overview.status_code == 200
|
|
assert "total_questions" in overview.json()
|
|
assert listing.status_code == 200
|
|
assert "items" in listing.json()
|