Phase 2 features: 1. Contract Risk Analysis - AI-powered risk detection with suggestions 2. Case Prediction Engine - Win probability and outcome prediction 3. Legal Knowledge Graph - Entity and relation management 4. Multi-language Translation - Legal document translation 5. Lawyer Matching - Intelligent lawyer recommendation All 63 unit tests passing. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
135 lines
4.0 KiB
Python
135 lines
4.0 KiB
Python
"""Unit tests for Phase 2 features."""
|
|
import pytest
|
|
from datetime import datetime
|
|
|
|
from app.models.phase2 import (
|
|
ContractRisk, RiskLevel, RiskType,
|
|
CasePrediction,
|
|
LegalEntity, LegalRelation, EntityType, RelationType,
|
|
TranslationRecord,
|
|
Lawyer, LawyerRecommendation,
|
|
)
|
|
|
|
|
|
class TestContractRiskModel:
|
|
"""Test cases for ContractRisk model."""
|
|
|
|
def test_risk_creation(self):
|
|
"""Test creating a risk instance."""
|
|
risk = ContractRisk(
|
|
contract_id=1,
|
|
clause_text="本条款内容模糊",
|
|
risk_type=RiskType.VAGUE,
|
|
risk_level=RiskLevel.HIGH,
|
|
description="条款缺乏明确定义",
|
|
suggestion="建议增加具体定义",
|
|
)
|
|
|
|
assert risk.contract_id == 1
|
|
assert risk.risk_type == RiskType.VAGUE
|
|
assert risk.risk_level == RiskLevel.HIGH
|
|
|
|
def test_risk_type_enum(self):
|
|
"""Test risk type enum values."""
|
|
assert RiskType.VAGUE.value == "vague"
|
|
assert RiskType.UNFAIR.value == "unfair"
|
|
assert RiskType.ILLEGAL.value == "illegal"
|
|
|
|
def test_risk_level_enum(self):
|
|
"""Test risk level enum values."""
|
|
assert RiskLevel.HIGH.value == "high"
|
|
assert RiskLevel.MEDIUM.value == "medium"
|
|
assert RiskLevel.LOW.value == "low"
|
|
|
|
|
|
class TestCasePredictionModel:
|
|
"""Test cases for CasePrediction model."""
|
|
|
|
def test_prediction_creation(self):
|
|
"""Test creating a prediction instance."""
|
|
prediction = CasePrediction(
|
|
user_id=1,
|
|
case_description="合同纠纷案件",
|
|
predicted_outcome="部分胜诉",
|
|
win_probability=0.65,
|
|
confidence=0.75,
|
|
key_factors=["证据充分", "法律依据明确"],
|
|
)
|
|
|
|
assert prediction.user_id == 1
|
|
assert prediction.win_probability == 0.65
|
|
assert len(prediction.key_factors) == 2
|
|
|
|
|
|
class TestKnowledgeGraphModels:
|
|
"""Test cases for Knowledge Graph models."""
|
|
|
|
def test_entity_creation(self):
|
|
"""Test creating a legal entity."""
|
|
entity = LegalEntity(
|
|
name="民法典",
|
|
entity_type=EntityType.LAW,
|
|
properties={"effective_date": "2021-01-01"},
|
|
)
|
|
|
|
assert entity.name == "民法典"
|
|
assert entity.entity_type == EntityType.LAW
|
|
|
|
def test_relation_creation(self):
|
|
"""Test creating a legal relation."""
|
|
relation = LegalRelation(
|
|
source_id=1,
|
|
target_id=2,
|
|
relation_type=RelationType.REFERENCES,
|
|
weight=0.9,
|
|
)
|
|
|
|
assert relation.source_id == 1
|
|
assert relation.relation_type == RelationType.REFERENCES
|
|
|
|
|
|
class TestTranslationModel:
|
|
"""Test cases for Translation model."""
|
|
|
|
def test_translation_creation(self):
|
|
"""Test creating a translation record."""
|
|
record = TranslationRecord(
|
|
source_text="合同条款",
|
|
source_lang="zh",
|
|
target_lang="en",
|
|
)
|
|
|
|
assert record.source_text == "合同条款"
|
|
assert record.source_lang == "zh"
|
|
assert record.target_lang == "en"
|
|
assert record.status == "pending"
|
|
|
|
|
|
class TestLawyerModels:
|
|
"""Test cases for Lawyer models."""
|
|
|
|
def test_lawyer_creation(self):
|
|
"""Test creating a lawyer instance."""
|
|
lawyer = Lawyer(
|
|
name="张律师",
|
|
specialties=["合同法", "公司法"],
|
|
experience_years=10,
|
|
)
|
|
|
|
assert lawyer.name == "张律师"
|
|
assert len(lawyer.specialties) == 2
|
|
assert lawyer.experience_years == 10
|
|
|
|
def test_recommendation_creation(self):
|
|
"""Test creating a recommendation instance."""
|
|
rec = LawyerRecommendation(
|
|
case_description="合同纠纷",
|
|
lawyer_id=1,
|
|
match_score=0.85,
|
|
match_reasons=["专业领域匹配", "经验丰富"],
|
|
)
|
|
|
|
assert rec.lawyer_id == 1
|
|
assert rec.match_score == 0.85
|
|
assert len(rec.match_reasons) == 2
|