62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import pytest
|
|
|
|
from app.core.knowledge_contracts import KnowledgeHit, KnowledgeQuery
|
|
from app.service.knowledge_authority import KnowledgeMysqlAuthority
|
|
|
|
|
|
class FakeRow:
|
|
id = 101
|
|
title = "申购规则"
|
|
content_text = '{"answer":"工作日确认"}'
|
|
version = "v2"
|
|
milvus_collection = "fin_policy_collection"
|
|
|
|
|
|
class FakeSession:
|
|
statement = None
|
|
|
|
async def scalars(self, statement):
|
|
self.statement = statement
|
|
return [FakeRow()]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_authority_filters_to_published_active_effective_knowledge() -> None:
|
|
session = FakeSession()
|
|
authority = KnowledgeMysqlAuthority(session)
|
|
|
|
hits = await authority.filter_published((
|
|
KnowledgeHit(
|
|
knowledge_id="101", collection="fin_policy_collection", snippet="摘要", score=0.91,
|
|
),
|
|
))
|
|
|
|
statement = str(session.statement)
|
|
assert "review_status" in statement
|
|
assert "status" in statement
|
|
assert "effective_date" in statement
|
|
assert "expire_date" in statement
|
|
assert hits[0].answer == "工作日确认"
|
|
assert hits[0].version == "v2"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_authority_keyword_fallback_only_returns_effective_public_knowledge() -> None:
|
|
session = FakeSession()
|
|
authority = KnowledgeMysqlAuthority(session)
|
|
|
|
hits = await authority.search_keyword(
|
|
KnowledgeQuery(query="基金 申购确认", intents=("policy_explain",)),
|
|
("fin_policy_collection",),
|
|
5,
|
|
)
|
|
|
|
statement = str(session.statement)
|
|
assert "milvus_collection" in statement
|
|
assert "content_text" in statement
|
|
assert "review_status" in statement
|
|
assert "effective_date" in statement
|
|
assert hits[0].knowledge_id == "101"
|
|
assert hits[0].collection == "fin_policy_collection"
|
|
assert hits[0].answer == "工作日确认"
|