e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from deeptutor.services.rag.file_routing import FileTypeRouter
|
|
from deeptutor.utils.document_validator import DocumentValidator
|
|
|
|
|
|
def test_validate_upload_safety_preserves_unicode_and_lowercases_extension() -> None:
|
|
safe_name = DocumentValidator.validate_upload_safety(
|
|
"中文资料/数学 讲义#1(最终版).PDF",
|
|
1024,
|
|
allowed_extensions=FileTypeRouter.get_supported_extensions(),
|
|
)
|
|
|
|
assert safe_name == "数学 讲义#1(最终版).pdf"
|
|
|
|
|
|
def test_validate_upload_safety_strips_windows_path_components() -> None:
|
|
safe_name = DocumentValidator.validate_upload_safety(
|
|
r"C:\Users\frank\资料\报告.MD",
|
|
128,
|
|
allowed_extensions=FileTypeRouter.get_supported_extensions(),
|
|
)
|
|
|
|
assert safe_name == "报告.md"
|
|
|
|
|
|
def test_validate_upload_safety_accepts_chat_office_formats_for_kb_policy() -> None:
|
|
safe_name = DocumentValidator.validate_upload_safety(
|
|
"Lecture Notes.DOCX",
|
|
1024,
|
|
allowed_extensions=FileTypeRouter.get_supported_extensions(),
|
|
)
|
|
|
|
assert safe_name == "Lecture Notes.docx"
|
|
|
|
|
|
def test_validate_upload_safety_custom_policy_allows_supported_code_mimes() -> None:
|
|
safe_name = DocumentValidator.validate_upload_safety(
|
|
"solver.PY",
|
|
1024,
|
|
allowed_extensions=FileTypeRouter.get_supported_extensions(),
|
|
)
|
|
|
|
assert safe_name == "solver.py"
|
|
|
|
|
|
def test_validate_upload_safety_custom_policy_allows_images() -> None:
|
|
safe_name = DocumentValidator.validate_upload_safety(
|
|
"diagram.PNG",
|
|
1024,
|
|
allowed_extensions=FileTypeRouter.get_supported_extensions(),
|
|
)
|
|
|
|
assert safe_name == "diagram.png"
|