71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
|
|
import sys
|
|
import re
|
|
sys.path.append(r"c:\Users\WIN10\Desktop\work\11th-week\法律风险提示-new\市监局-lawRisk-backend")
|
|
|
|
from lawrisk.services.licensing_repo import _normalize_import_row
|
|
|
|
def test_normalization():
|
|
print("Testing _normalize_import_row...")
|
|
|
|
# Mock a raw row that mimics what _parse_import_workbook produces
|
|
raw_row = {
|
|
"row_index": 10,
|
|
"permit_name": None, # Should come from defaults if missing
|
|
"risk_content": "Test Risk",
|
|
"legal_basis": "Law 101",
|
|
"document_no": "No.1",
|
|
"summary": "Summary",
|
|
"permit_status": "Active",
|
|
"filler_name": "John Doe",
|
|
"unit_name": "Test Unit",
|
|
"source_update_date": "2023-12-19",
|
|
"responsible_contact": "Contact Info",
|
|
"jurisdiction_scope": "City Level",
|
|
"subitem_text": "Subitem A、Subitem B",
|
|
"theme_names": "Theme X", # Should be ignored/cleared if not in new template, but if passed in raw_row...
|
|
"scope_text": "Scope Y",
|
|
}
|
|
|
|
sheet_defaults = {
|
|
"permit_name": "Test Permit",
|
|
"filler_name": "Default Filler", # Should use raw_row if present
|
|
"unit_name": "Default Unit",
|
|
"source_update_date": "2023-01-01",
|
|
}
|
|
|
|
normalized = _normalize_import_row(raw_row, "Sheet1", sheet_defaults)
|
|
|
|
if not normalized:
|
|
print("FAILED: Returned None")
|
|
return
|
|
|
|
# Check new fields
|
|
print(f"Filler Name: {normalized.get('filler_name')} (Expected: John Doe)")
|
|
print(f"Unit Name: {normalized.get('unit_name')} (Expected: Test Unit)")
|
|
print(f"Update Date: {normalized.get('source_update_date')} (Expected: 2023-12-19)")
|
|
|
|
# Check Permit Name (fallback)
|
|
print(f"Permit Name: {normalized.get('permit_name')} (Expected: Test Permit)")
|
|
|
|
# Check removed fields are gone or handled
|
|
if "subitem_summary" in normalized:
|
|
print("WARNING: subitem_summary still present")
|
|
if "theme_names" in normalized:
|
|
# It might be present but empty list if we removed extraction logic?
|
|
# Wait, I removed theme_names extraction from _normalize_import_row.
|
|
# So it should NOT be in the output dict unless I left it.
|
|
# Let's check.
|
|
pass
|
|
|
|
# Validation
|
|
assert normalized['filler_name'] == "John Doe"
|
|
assert normalized['unit_name'] == "Test Unit"
|
|
assert normalized['source_update_date'] == "2023-12-19"
|
|
assert normalized['permit_name'] == "Test Permit"
|
|
|
|
print("SUCCESS: Normalization logic verified.")
|
|
|
|
if __name__ == "__main__":
|
|
test_normalization()
|