Files
gaokao-volunteer-system/admin/tests/test_notifications_admin.py
Hermes Agent a957b39cc0
Some checks failed
CI / pytest (Python 3.10) (push) Has been cancelled
CI / pytest (Python 3.11) (push) Has been cancelled
CI / pytest (Python 3.12) (push) Has been cancelled
feat(frontend): harden home CTA, Portal, public, and admin pages
- Landing: 主 CTA “先做快速审核” 升级为主按钮,移除多余的次按钮,添加 hero-note 与 hero-divider 让首屏节奏更稳
- Landing: hero-points 收口为 3 个差异化卖点,第 1 个加 lead 背景,右侧风险卡降饱和、避免压过主 CTA
- Landing: 删去旧“志愿方案审计更聚焦/先下单后补资料/站内可追踪交付”重复卡片
- Public: /privacy /service-terms /deletion-policy 接 portal-ui.css 并改成双段 panel + 列表结构
- Portal: /portal/{token}/notifications /portal/{token}/deletion-request 接 portal-ui.css 与新的工具条 / 表单字段化
- Admin: /admin/orders/new 接 portal-ui.css,添加“人工补录更直接/与后台订单主链一致/字段业务语义化”信任块
- Admin: /admin/notifications /admin/ops-alerts 接 portal-ui.css,添加 meta-grid 摘要并把 “payload / details” 改名为“通知内容摘要 / 详细上下文”
- Tests: 锁住 shared CSS、关键产品化文案、Portal 与 admin 页结构断言
2026-06-16 20:12:58 +08:00

84 lines
3.1 KiB
Python

from __future__ import annotations
from data.notifications.email_service import DeliveryNotificationService
from data.orders.dao import OrdersDAO
from data.orders.models import Order
def _seed_order(db_path: str, order_id: str = "GKO-20260615-ADMIN-NOTIFY") -> Order:
order = Order(
id=order_id,
source="web",
service_version="standard",
amount_cents=9900,
status="pending",
customer_name="张家长",
customer_phone="13800138000",
customer_email="parent@example.com",
candidate_name="张三",
candidate_province="湖南",
)
with OrdersDAO.connect(db_path) as dao:
created = dao.create(order, actor="test", reason="seed")
dao.transition_status(created.id, "paid", actor="test", reason="seed_pay")
dao.transition_status(created.id, "serving", actor="test", reason="seed_processing")
dao.transition_status(created.id, "delivered", actor="test", reason="seed_ready")
return dao.get(created.id)
def test_admin_notification_list_api_filters_by_status_and_channel(client, auth_headers, settings):
order = _seed_order(settings.orders_db_path)
service = DeliveryNotificationService.for_db(settings.orders_db_path)
try:
service.notify_event(
order.id,
event_type="report_ready",
channel="station",
payload_json='{"kind":"station"}',
)
service.mark_validated(order.id, event_type="report_ready", payload_json='{"kind":"station"}')
service.notify_event(
order.id,
event_type="report_ready_email",
channel="email",
payload_json='{"kind":"email"}',
)
service.mark_delivered(order.id, event_type="report_ready_email", payload_json='{"kind":"email"}')
finally:
service.close()
resp = client.get(
"/api/admin/notifications?status=delivered&channel=email",
headers=auth_headers,
)
assert resp.status_code == 200, resp.text
body = resp.json()
assert body["total"] == 1
assert len(body["items"]) == 1
assert body["items"][0]["channel"] == "email"
assert body["items"][0]["status"] == "delivered"
def test_admin_notification_audit_page_renders_table(client, auth_headers, settings):
order = _seed_order(settings.orders_db_path, order_id="GKO-20260615-ADMIN-NOTIFY-PAGE")
service = DeliveryNotificationService.for_db(settings.orders_db_path)
try:
service.notify_event(
order.id,
event_type="report_ready",
channel="station",
payload_json='{"kind":"station"}',
)
finally:
service.close()
resp = client.get(f"/admin/notifications?order_id={order.id}", headers=auth_headers)
assert resp.status_code == 200, resp.text
assert "后台通知审计" in resp.text
assert '/static/portal-ui.css' in resp.text
assert "通知内容摘要" in resp.text
assert "查看重点" in resp.text
assert order.id in resp.text
assert "station" in resp.text
assert "report_ready" in resp.text