147 lines
4.9 KiB
Python
147 lines
4.9 KiB
Python
import pytest
|
|
from django.urls import reverse
|
|
|
|
from review_agent.models import (
|
|
ApplicationFormFillBatch,
|
|
Conversation,
|
|
FileAttachment,
|
|
FileSummaryBatch,
|
|
KnowledgeBaseDocument,
|
|
RegulatoryReviewBatch,
|
|
)
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
def test_home_dashboard_renders_current_user_metrics(client, django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
other = django_user_model.objects.create_user(username="other", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="注册资料会话")
|
|
other_conversation = Conversation.objects.create(user=other, title="其他用户会话")
|
|
FileAttachment.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
original_name="active.docx",
|
|
storage_path="x/active.docx",
|
|
file_size=128,
|
|
is_active=True,
|
|
)
|
|
FileAttachment.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
original_name="deleted.docx",
|
|
storage_path="x/deleted.docx",
|
|
file_size=128,
|
|
is_active=False,
|
|
upload_status=FileAttachment.UploadStatus.DELETED,
|
|
)
|
|
FileAttachment.objects.create(
|
|
conversation=other_conversation,
|
|
user=other,
|
|
original_name="other.docx",
|
|
storage_path="x/other.docx",
|
|
file_size=128,
|
|
)
|
|
KnowledgeBaseDocument.objects.create(
|
|
user=user,
|
|
display_name="法规资料",
|
|
original_name="rule.md",
|
|
storage_path="kb/rule.md",
|
|
file_size=64,
|
|
is_active=True,
|
|
indexed_chunk_count=3,
|
|
)
|
|
KnowledgeBaseDocument.objects.create(
|
|
user=user,
|
|
display_name="删除资料",
|
|
original_name="deleted.md",
|
|
storage_path="kb/deleted.md",
|
|
file_size=64,
|
|
status=KnowledgeBaseDocument.Status.DELETED,
|
|
is_active=False,
|
|
indexed_chunk_count=5,
|
|
)
|
|
KnowledgeBaseDocument.objects.create(
|
|
user=other,
|
|
display_name="其他资料",
|
|
original_name="other.md",
|
|
storage_path="kb/other.md",
|
|
file_size=64,
|
|
indexed_chunk_count=9,
|
|
)
|
|
summary = FileSummaryBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
batch_no="FS-RUN",
|
|
status=FileSummaryBatch.Status.RUNNING,
|
|
)
|
|
RegulatoryReviewBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
source_summary_batch=summary,
|
|
batch_no="RR-WAIT",
|
|
status=RegulatoryReviewBatch.Status.WAITING_USER,
|
|
risk_summary={"high": 2},
|
|
)
|
|
ApplicationFormFillBatch.objects.create(
|
|
conversation=conversation,
|
|
user=user,
|
|
source_summary_batch=summary,
|
|
batch_no="AFF-OK",
|
|
status=ApplicationFormFillBatch.Status.SUCCESS,
|
|
)
|
|
FileSummaryBatch.objects.create(
|
|
conversation=other_conversation,
|
|
user=other,
|
|
batch_no="FS-OTHER",
|
|
status=FileSummaryBatch.Status.FAILED,
|
|
)
|
|
client.force_login(user)
|
|
|
|
response = client.get(reverse("home"))
|
|
|
|
assert response.status_code == 200
|
|
content = response.content.decode("utf-8")
|
|
assert "注册资料审核工作台" in content
|
|
assert "当前账号资料、知识库、附件与审核处理数据总览" in content
|
|
assert "工作流流程" not in content
|
|
assert "对话总数" in content
|
|
assert "附件总数" in content
|
|
assert "知识库材料" in content
|
|
assert "内置材料" in content
|
|
assert f"管理 {1} · 内置" in content
|
|
assert "向量片段" in content
|
|
assert "FS-RUN" in content
|
|
assert "RR-WAIT" in content
|
|
assert "AFF-OK" in content
|
|
assert "FS-OTHER" not in content
|
|
assert "其他用户会话" not in content
|
|
assert f'href="{reverse("chat")}?conversation={conversation.pk}"' in content
|
|
|
|
|
|
def test_chat_route_renders_review_agent_workspace(client, django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="审核会话")
|
|
client.force_login(user)
|
|
|
|
response = client.get(f"{reverse('chat')}?conversation={conversation.pk}")
|
|
|
|
assert response.status_code == 200
|
|
content = response.content.decode("utf-8")
|
|
assert "审核智能体" in content
|
|
assert 'id="summaryPanel"' in content
|
|
assert f'action="{reverse("chat")}"' in content
|
|
assert f'href="{reverse("chat")}?conversation={conversation.pk}"' in content
|
|
|
|
|
|
def test_legacy_home_conversation_redirects_to_chat(client, django_user_model):
|
|
user = django_user_model.objects.create_user(username="owner", password="pass")
|
|
conversation = Conversation.objects.create(user=user, title="旧入口会话")
|
|
client.force_login(user)
|
|
|
|
response = client.get(f"{reverse('home')}?conversation={conversation.pk}")
|
|
|
|
assert response.status_code == 302
|
|
assert response["Location"] == f"{reverse('chat')}?conversation={conversation.pk}"
|