feat: add admin dashboard, pipeline service, lightbox, and update dependencies

This commit is contained in:
2026-06-09 09:32:10 +08:00
parent 0d293422ac
commit 32978b3fc5
50 changed files with 4054 additions and 1618 deletions
+6 -11
View File
@@ -3,7 +3,6 @@
from __future__ import annotations
import logging
from datetime import date, datetime, timezone
from unittest.mock import AsyncMock, patch
import pytest
@@ -14,6 +13,7 @@ from app.models import (
CrawlLog,
TaskLock,
)
from app.utils import utc_now
# ═══════════════════════════════════════════════════════════════════════
@@ -24,11 +24,6 @@ from app.models import (
class TestAdminAuth:
"""管理接口鉴权测试。"""
def test_unauthenticated_redirects_to_login(self, auth_client):
"""未登录时请求管理接口应重定向到登录页。"""
# 用未登录的 clientauth_client 已登录,这里直接用 client)
pass # 见下方 test_no_session_returns_303
def test_no_session_returns_303(self, client, monkeypatch):
"""无 session 时请求管理接口应返回 303 重定向。"""
monkeypatch.setattr(settings, "ADMIN_PASSWORD", "some-password")
@@ -58,7 +53,7 @@ class TestAdminAuth:
follow_redirects=False,
)
assert resp.status_code == 303
assert "/admin/logs" in resp.headers.get("location", "")
assert "/admin/" in resp.headers.get("location", "")
def test_logout_clears_session(self, auth_client, monkeypatch):
"""退出登录后应清除 session。"""
@@ -265,7 +260,7 @@ class TestAdminLogs:
):
"""日志页面应包含日志数据。"""
# 先创建一条日志
now = datetime.now(timezone.utc)
now = utc_now()
db_session.add(
CrawlLog(
task="crawl",
@@ -345,7 +340,7 @@ class TestScheduler:
@pytest.mark.asyncio
async def test_daily_pipeline_lock_prevents_reentry(self, db_session):
"""pipeline 使用 task_locks 防重入。"""
now = datetime.now(timezone.utc)
now = utc_now()
lock = TaskLock(
task="scheduler",
lock_key="pipeline-2024-01-15",
@@ -380,7 +375,7 @@ class TestTaskLocks:
def test_unique_running_lock(self, db_session):
"""同一 task + lock_key 只能有一个 running 锁。"""
now = datetime.now(timezone.utc)
now = utc_now()
lock1 = TaskLock(
task="crawl",
lock_key="2024-01-15",
@@ -405,7 +400,7 @@ class TestTaskLocks:
def test_released_lock_allows_new(self, db_session):
"""已释放的锁允许新的 running 锁。"""
now = datetime.now(timezone.utc)
now = utc_now()
lock1 = TaskLock(
task="crawl",
lock_key="2024-01-16",