- Added new modules for advisor compliance, KYC sessions, and script templates, enhancing the advisor agent's capabilities. - Implemented a comprehensive API structure under the `/api/advisor-agent` prefix, ensuring clear organization and access to new features. - Established database models and repositories for compliance rules and KYC sessions, facilitating robust data management. - Integrated exception handling and response models to improve error management and user feedback. - Updated settings to include new configurations for compliance and KYC features, ensuring flexibility and adaptability. This update significantly expands the advisor agent's functionality, providing essential tools for compliance and customer interaction while maintaining a structured API design.
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
from pathlib import Path
|
|
|
|
import app.advisor_db as advisor_db
|
|
from app.model.entities_advisor import ComplianceRule
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DATASET = ROOT / "docs" / "开发文档" / "20-Sprint1首批合规规则数据集.md"
|
|
|
|
def test_markdown_rule_dataset_loads_at_least_50_test_rules():
|
|
from scripts.seed.import_compliance_rules import load_rules_from_markdown
|
|
|
|
rules = load_rules_from_markdown(DATASET)
|
|
|
|
assert len(rules) >= 50
|
|
assert rules[0].rule_code == "CR-TEST-001"
|
|
assert rules[0].rule_type == "keyword"
|
|
assert rules[0].pattern == "保本保收益"
|
|
assert rules[0].severity == "block"
|
|
assert rules[0].category == "return_promise"
|
|
assert rules[0].is_active is True
|
|
assert rules[0].priority == 10
|
|
assert all(rule.review_status in {"test_data", "pending"} for rule in rules)
|
|
|
|
def test_import_markdown_rules_upserts_without_duplicate_rows():
|
|
from scripts.seed.import_compliance_rules import import_rules_from_markdown
|
|
|
|
first_result = import_rules_from_markdown(DATASET, actor_id="seed:test_data")
|
|
second_result = import_rules_from_markdown(DATASET, actor_id="seed:test_data")
|
|
|
|
assert first_result.total >= 50
|
|
assert first_result.created + first_result.updated == first_result.total
|
|
assert second_result.total == first_result.total
|
|
assert second_result.created == 0
|
|
assert second_result.updated == second_result.total
|
|
|
|
with advisor_db.AgentSessionLocal() as session:
|
|
imported_count = (
|
|
session.query(ComplianceRule)
|
|
.filter(
|
|
ComplianceRule.rule_code.like("CR-TEST-%"),
|
|
ComplianceRule.created_by == "seed:test_data",
|
|
)
|
|
.count()
|
|
)
|
|
first_rule = session.query(ComplianceRule).filter(ComplianceRule.rule_code == "CR-TEST-001").one()
|
|
|
|
assert imported_count >= 50
|
|
assert first_rule.pattern == "保本保收益"
|
|
assert first_rule.is_active is True
|
|
|
|
def test_import_script_entrypoint_imports_fifty_rules():
|
|
from scripts.seed import import_compliance_rules as mod
|
|
|
|
result = mod.import_rules_from_markdown(DATASET, actor_id="seed:test_data")
|
|
assert result.total == 50
|
|
assert result.created + result.updated == result.total
|