feat: update audit platform workspace
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
"""首页统计接口测试。"""
|
||||
|
||||
import pytest
|
||||
|
||||
from fastapi_modules.fastapi_leaudit.services.impl.homeServiceImpl import HomeServiceImpl
|
||||
|
||||
|
||||
class _FakeDocument:
|
||||
def __init__(self, *, audit_status: int, failed_count: int = 0, updated_at: str = "2026-05-23T10:00:00") -> None:
|
||||
self.auditStatus = audit_status
|
||||
self.failedCount = failed_count
|
||||
self.updatedAt = updated_at
|
||||
|
||||
|
||||
class _FakePage:
|
||||
def __init__(self, *, documents, total_pages: int) -> None:
|
||||
self.documents = documents
|
||||
self.totalPages = total_pages
|
||||
|
||||
|
||||
class _FakeDocumentService:
|
||||
def __init__(self) -> None:
|
||||
self.calls = []
|
||||
|
||||
async def ListDocuments(self, **kwargs):
|
||||
self.calls.append(kwargs)
|
||||
page = kwargs["Page"]
|
||||
if page == 1:
|
||||
return _FakePage(
|
||||
documents=[
|
||||
_FakeDocument(audit_status=0, updated_at="2026-05-23T09:00:00"),
|
||||
_FakeDocument(audit_status=2, updated_at="2026-05-23T09:30:00"),
|
||||
_FakeDocument(audit_status=1, failed_count=0, updated_at="2026-05-03T10:00:00"),
|
||||
_FakeDocument(audit_status=1, failed_count=2, updated_at="2026-05-20T10:00:00"),
|
||||
],
|
||||
total_pages=2,
|
||||
)
|
||||
if page == 2:
|
||||
return _FakePage(
|
||||
documents=[
|
||||
_FakeDocument(audit_status=1, failed_count=1, updated_at="2026-05-22T10:00:00"),
|
||||
_FakeDocument(audit_status=1, failed_count=0, updated_at="2026-04-18T10:00:00"),
|
||||
_FakeDocument(audit_status=0, updated_at="2026-05-10T10:00:00"),
|
||||
],
|
||||
total_pages=2,
|
||||
)
|
||||
return _FakePage(documents=[], total_pages=2)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_home_dashboard_statistics_uses_entry_scope_and_all_pages():
|
||||
"""首页统计按入口模块与文档类型过滤,并拉取全量分页后计算。"""
|
||||
document_service = _FakeDocumentService()
|
||||
service = HomeServiceImpl(DocumentService=document_service)
|
||||
|
||||
result = await service.GetDashboardStatistics(
|
||||
UserId=7,
|
||||
Today="2026-05-23",
|
||||
TypeIds=[10, 11],
|
||||
EntryModuleId=3,
|
||||
)
|
||||
|
||||
assert result.todayPendingFiles == 2
|
||||
assert result.monthlyReviewedFiles == 3
|
||||
assert result.monthlyPassRate == 33
|
||||
assert result.issuesDetected == 3
|
||||
assert result.monthlyReviewGrowth.value == 200
|
||||
assert result.monthlyReviewGrowth.isUp is True
|
||||
assert {call["EntryModuleId"] for call in document_service.calls} == {3}
|
||||
assert {tuple(call["TypeIds"]) for call in document_service.calls} == {(10, 11)}
|
||||
assert [call["Page"] for call in document_service.calls] == [1, 2]
|
||||
assert all("DateFrom" not in call for call in document_service.calls)
|
||||
assert all("DateTo" not in call for call in document_service.calls)
|
||||
Reference in New Issue
Block a user