- Pipeline: analyze(), redact(), analyze_image() methods - API: /analyze, /redact, /analyze/frame, /analyze/frame/base64 endpoints - Detectors: regex, NER, face (RKNN NPU) - Privacy frame route added for KVM-Privacy Hub integration
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
# tests/test_models.py
|
|
from info_privacy.models import TextBlock, Entity, DetectionReport, EntityType
|
|
|
|
def test_entity_type_enum():
|
|
assert EntityType.ID_CARD.value == "id_card"
|
|
assert EntityType.FACE.value == "face"
|
|
|
|
def test_text_block_creation():
|
|
block = TextBlock(
|
|
text="张三,身份证:110101199001011234",
|
|
bbox=[10, 20, 200, 40],
|
|
page=1,
|
|
layer="text",
|
|
)
|
|
assert block.layer == "text"
|
|
|
|
def test_entity_creation():
|
|
entity = Entity(
|
|
id="e1",
|
|
type=EntityType.ID_CARD,
|
|
value="110101199001011234",
|
|
page=1,
|
|
bbox=[10, 20, 200, 40],
|
|
layer="text",
|
|
security_level="high",
|
|
)
|
|
assert entity.type == EntityType.ID_CARD
|
|
|
|
def test_detection_report_summary():
|
|
from info_privacy.models import Classification
|
|
report = DetectionReport(
|
|
doc_id="test-uuid",
|
|
classification=Classification.NORMAL,
|
|
blocked=False,
|
|
block_reason=None,
|
|
warning=None,
|
|
doc_meta={"format": "pdf", "has_text_layer": True, "redact_strategy": "text_replace"},
|
|
entities=[
|
|
Entity(id="e1", type=EntityType.ID_CARD, value="x",
|
|
page=1, bbox=[0,0,1,1], layer="text", security_level="high"),
|
|
Entity(id="e2", type=EntityType.PHONE, value="y",
|
|
page=1, bbox=[0,0,1,1], layer="text", security_level="high"),
|
|
],
|
|
)
|
|
assert report.summary["id_card"] == 1
|
|
assert report.summary["phone"] == 1
|