Files
email-assistant/tests/test_webui_smoke.py
T

73 lines
2.0 KiB
Python

"""Smoke-тесты веб-интерфейса через FastAPI TestClient.
Запуск: .venv/bin/python -m pytest tests/ -q (или просто python tests/test_webui_smoke.py)
"""
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
os.environ.setdefault("WEBUI_PASSWORD", "test-pass")
from fastapi.testclient import TestClient # noqa: E402
from webui.app import app # noqa: E402
c = TestClient(app)
def _login():
return c.post("/login", data={"password": "test-pass"}, follow_redirects=False)
def test_unauth_redirects():
fresh = TestClient(app) # без cookie от предыдущих тестов
r = fresh.get("/", follow_redirects=False)
assert r.status_code == 303
assert r.headers["location"] == "/login"
def test_bad_password():
r = c.post("/login", data={"password": "nope"}, follow_redirects=False)
assert r.status_code == 200
assert "Неверный пароль" in r.text
def test_login_ok():
r = _login()
assert r.status_code == 303
def test_pages_render():
_login()
for url in ("/", "/emails", "/emails?folder=INBOX", "/search?q=КП"):
r = c.get(url, follow_redirects=False)
assert r.status_code == 200, url
def test_three_columns_and_ai_pane():
_login()
html = c.get("/emails?folder=INBOX").text
assert 'class="c1"' in html and 'class="c2"' in html and 'class="c3"' in html
assert "chatpane" in html
def test_search_body_fallback():
_login()
html = c.get("/search?q=Эвотор").text
assert "res-row" in html or "Ничего не найдено" in html
def test_ai_unauthenticated_401():
c2 = TestClient(app)
r = c2.post("/api/ai/ask", json={"question": "hi"})
assert r.status_code == 401
if __name__ == "__main__":
for name, fn in sorted(globals().items()):
if name.startswith("test_") and callable(fn):
fn()
print("OK", name)
print("all smoke tests passed")