Files
ai-contract-platform/backend/tests/test_contract_content_normalizer.py
T

50 lines
1.9 KiB
Python

import unittest
from app.services.contract_content_normalizer import normalize_contract_content
from app.services.contract_generation_service import ContractGenerationService
class ContractContentNormalizerTestCase(unittest.TestCase):
def test_normalize_contract_content_removes_markdown_headings(self):
raw_content = """# 劳动合同
### 一、合同期限与试用期
双方确认合同期限为三年。
### 六、保密、服务期与竞业限制
**乙方**应履行保密义务。
"""
normalized = normalize_contract_content(raw_content)
self.assertEqual(
normalized,
"劳动合同\n\n一、合同期限与试用期\n双方确认合同期限为三年。\n\n六、保密、服务期与竞业限制\n乙方应履行保密义务。",
)
self.assertNotIn("###", normalized)
self.assertNotIn("**", normalized)
def test_normalize_contract_content_removes_markdown_inside_html_payload(self):
raw_content = "<article><h1># 劳动合同</h1><p>### 一、合同期限与试用期</p></article>"
normalized = normalize_contract_content(raw_content)
self.assertEqual(normalized, "劳动合同\n一、合同期限与试用期")
self.assertNotIn("#", normalized)
def test_generated_contract_html_renders_clean_contract_headings(self):
html = ContractGenerationService._build_generated_contract_html(
"### 一、合同期限与试用期\n双方确认合同期限为三年。\n### 六、保密、服务期与竞业限制",
missing_fields=[],
related_legal_articles=[],
ai_hints=[],
)
self.assertIn("<h2>一、合同期限与试用期</h2>", html)
self.assertIn("<h2>六、保密、服务期与竞业限制</h2>", html)
self.assertNotIn("###", html)
if __name__ == "__main__":
unittest.main()