Files
huihuiSquare/digital-avatar-app/backend/tests/test_knowledge_storage.py
T

24 lines
833 B
Python

from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
from routers.knowledge import _doc_payload
def test_doc_payload_reports_whether_the_persisted_file_exists(tmp_path: Path):
avatar_id = "avatar-1"
stored_name = "knowledge.md"
doc = SimpleNamespace(
avatar_id=avatar_id,
file_url=f"/api/files/{avatar_id}/{stored_name}",
to_dict=lambda: {"id": "doc-1", "fileUrl": f"/api/files/{avatar_id}/{stored_name}"},
)
stored_dir = tmp_path / avatar_id
stored_dir.mkdir()
stored_file = stored_dir / stored_name
with patch("routers.knowledge.UPLOAD_DIR", str(tmp_path)):
assert _doc_payload(doc)["filePresent"] is False
stored_file.write_text("knowledge", encoding="utf-8")
assert _doc_payload(doc)["filePresent"] is True