54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
"""自动化 API 在独立后台进程模式下不能因为空注册表返回空白页。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from web.backend.models import AutomationRun, User
|
|
from web.backend.routers import automation as automation_router
|
|
from web.backend.services.automation import reset_registry
|
|
|
|
|
|
def _admin(db) -> User:
|
|
user = User(
|
|
username="automation-registry-admin",
|
|
password_hash="h",
|
|
role="super_admin",
|
|
is_active=True,
|
|
)
|
|
db.add(user)
|
|
db.commit()
|
|
return user
|
|
|
|
|
|
def test_list_jobs_registers_default_jobs_when_api_process_registry_is_empty(db):
|
|
reset_registry()
|
|
admin = _admin(db)
|
|
|
|
result = automation_router.list_jobs(db=db, current=admin)
|
|
|
|
jobs = {job["key"]: job for job in result["jobs"]}
|
|
keys = set(jobs)
|
|
assert "account_sync_queue" in keys
|
|
assert "account_supply_replenishment" in keys
|
|
assert jobs["account_sync_queue"]["batch_size"] == 40
|
|
assert result["scheduler"]["enabled"] is not None
|
|
|
|
|
|
def test_list_runs_registers_default_jobs_when_api_process_registry_is_empty(db):
|
|
reset_registry()
|
|
admin = _admin(db)
|
|
db.add(
|
|
AutomationRun(
|
|
job_key="account_sync_queue",
|
|
status="success",
|
|
message="test",
|
|
started_at=datetime.now(UTC),
|
|
)
|
|
)
|
|
db.commit()
|
|
|
|
result = automation_router.list_runs(job_key=None, limit=10, db=db, current=admin)
|
|
|
|
assert any(item["job_key"] == "account_sync_queue" for item in result["items"])
|