mirror of
https://gitverse.ru/kpa39l/email-assistant.git
synced 2026-11-27 06:30:08 +00:00
docs: session close 2026-10-22 — Docker, metrics, auth-log, Task 6 (VTODO-create). feat: webui/radicale.py create/toggle_task, CalDAV REPORT, api endpoints. fix: login cookie (HTMX, method=post, stale cleanup). fix: SQLite WAL read-only mount.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
"""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")
|
||||
Reference in New Issue
Block a user