feat(админка): Мой день с очередью
This commit is contained in:
@@ -68,7 +68,8 @@ def test_dashboard_is_cached_for_15_seconds(env, monkeypatch):
|
||||
assert calls["n"] == 1
|
||||
client.post("/api/admin/v2/visit", headers=h)
|
||||
assert client.get("/api/admin/v2/dashboard", headers=h).status_code == 200
|
||||
assert calls["n"] == 2
|
||||
# визит больше не сбрасывает кэш: personal-поля дописываются поверх
|
||||
assert calls["n"] == 1
|
||||
|
||||
|
||||
def test_dashboard_is_admin_only(env):
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
"""P2.5a: «Мой день» — 5 карточек, деньги с бейджем, задача закрывается в 1–2 клика."""
|
||||
import functools
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import socketserver
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT)); sys.path.insert(0, str(ROOT / "tests"))
|
||||
pytest.importorskip("playwright.sync_api", reason="playwright не установлен")
|
||||
from test_admin_design_ui import browser # noqa: E402,F401
|
||||
|
||||
DASH = {"user": "boss@x", "generated_at": 1794000000, "last_visit": None,
|
||||
"work_24h": {"people": 3, "requests": 20, "failures": 1, "failure_share": 0.05,
|
||||
"limit_hits": 0, "latency_qa_ms": 200, "latency_qa_p95_ms": 500,
|
||||
"latency_agent_ms": 3000, "latency_agent_p95_ms": 9000},
|
||||
"money": {"revenue_rub": 1000, "flow_rub": 400, "accounts_total_rub": 2500,
|
||||
"topups_included": False, "unpriced": 0},
|
||||
"customers": {"total": 12, "active_24h": 3},
|
||||
"attention": {"failures": 1, "limit_hits": 0, "unpriced": 0}}
|
||||
ATT = {"items": [{"key": "failures:24h", "severity": "high", "title": "Сбои",
|
||||
"detail": "1 сбой", "action": "/admin/v2/work"},
|
||||
{"key": "unpriced", "severity": "medium", "title": "Без цены",
|
||||
"detail": "1 прогон", "action": "/admin/v2/money"}], "count": 2}
|
||||
|
||||
|
||||
class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
calls = []
|
||||
fail_done = False
|
||||
|
||||
def __init__(self, *a, **kw):
|
||||
super().__init__(*a, directory=str(ROOT), **kw)
|
||||
|
||||
def do_GET(self):
|
||||
if self.path.startswith("/api/admin/v2/dashboard"):
|
||||
return self._json(DASH)
|
||||
if self.path.startswith("/api/admin/v2/attention"):
|
||||
return self._json(ATT)
|
||||
if self.path == "/admin/v2" or self.path.startswith("/admin/v2/"):
|
||||
data = (ROOT / "static/admin2/index.html").read_bytes()
|
||||
self.send_response(200); self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(data))); self.end_headers()
|
||||
self.wfile.write(data); return
|
||||
return super().do_GET()
|
||||
|
||||
def do_POST(self):
|
||||
n = int(self.headers.get('Content-Length') or 0)
|
||||
body = self.rfile.read(n).decode() if n else ''
|
||||
Handler.calls.append({"path": self.path, "body": body})
|
||||
if Handler.fail_done and self.path.endswith('/done'):
|
||||
self.send_response(500); self.end_headers(); return
|
||||
self._json({"ok": True, "previous": 1793000000, "key": "failures:24h"})
|
||||
|
||||
def _json(self, obj):
|
||||
data = json.dumps(obj).encode()
|
||||
self.send_response(200); self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(data))); self.end_headers()
|
||||
self.wfile.write(data)
|
||||
|
||||
def log_message(self, *a):
|
||||
return
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def site():
|
||||
Handler.calls = []
|
||||
class Quiet(socketserver.ThreadingTCPServer):
|
||||
allow_reuse_address = True
|
||||
daemon_threads = True
|
||||
srv = Quiet(("127.0.0.1", 0), Handler)
|
||||
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
||||
yield f"http://127.0.0.1:{srv.server_address[1]}"
|
||||
srv.shutdown()
|
||||
|
||||
|
||||
def test_five_cards_money_badge_and_done(browser, site):
|
||||
page = browser.new_page()
|
||||
errors = []
|
||||
page.on("pageerror", lambda e: errors.append(str(e)))
|
||||
page.add_init_script("localStorage.setItem('token','t')")
|
||||
page.goto(site + "/admin/v2")
|
||||
page.wait_for_selector(".grid .card")
|
||||
assert page.locator(".grid .card").count() == 5
|
||||
assert "предварительно" in page.locator(".badge").first.inner_text()
|
||||
assert "1\u00a0000" in page.locator(".grid").inner_text()
|
||||
assert page.locator(".task").count() == 2
|
||||
assert "первый визит" not in page.locator(".grid").inner_text()
|
||||
page.locator(".task button", has_text="Готово").first.click()
|
||||
page.wait_for_timeout(400)
|
||||
assert page.locator(".task").count() == 1
|
||||
page.locator(".task button", has_text="1 ч").click()
|
||||
page.wait_for_timeout(400)
|
||||
assert page.locator(".task").count() == 0
|
||||
paths = [c["path"] for c in Handler.calls]
|
||||
assert any("/api/admin/v2/attention/failures%3A24h/done" in p for p in paths)
|
||||
assert any("/api/admin/v2/attention/unpriced/snooze" in p for p in paths)
|
||||
assert any('"minutes":60' in c["body"] for c in Handler.calls if "snooze" in c["path"])
|
||||
assert errors == []
|
||||
page.close()
|
||||
|
||||
|
||||
def test_task_failure_is_visible(browser, site):
|
||||
Handler.fail_done = True
|
||||
Handler.calls = []
|
||||
page = browser.new_page()
|
||||
page.add_init_script("localStorage.setItem('token','t')")
|
||||
page.goto(site + "/admin/v2")
|
||||
page.wait_for_selector(".task")
|
||||
page.locator(".task button", has_text="Готово").first.click()
|
||||
page.wait_for_timeout(400)
|
||||
assert "Ошибка 500" in page.locator(".queue .error").inner_text()
|
||||
page.close()
|
||||
Handler.fail_done = False
|
||||
Reference in New Issue
Block a user