Files
FunMD_Convert/docling/app/tests/test_api_convert.py

30 lines
930 B
Python
Raw Permalink Normal View History

2026-01-07 17:18:26 +08:00
import unittest
from fastapi.testclient import TestClient
from pathlib import Path
import io
from app.server import app
class ApiConvertTest(unittest.TestCase):
def setUp(self):
self.client = TestClient(app)
def test_api_convert_markdown_file(self):
tmpdir = Path("./scratch_unittest")
tmpdir.mkdir(exist_ok=True)
p = tmpdir / "sample.md"
p.write_text("# Title\n\n::: note\nBody\n:::\n", "utf-8")
with open(p, "rb") as f:
files = {"file": (p.name, io.BytesIO(f.read()), "text/markdown")}
r = self.client.post("/api/convert", files=files, data={"export": "markdown"})
self.assertEqual(r.status_code, 200)
j = r.json()
self.assertEqual(j.get("code"), 0)
self.assertIsInstance(j.get("data", {}).get("content"), str)
self.assertIn("!!! note", j["data"]["content"])
if __name__ == "__main__":
unittest.main()