Import project files
This commit is contained in:
80
docling/app/tests/run_batch_upload_debug.py
Normal file
80
docling/app/tests/run_batch_upload_debug.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import io
|
||||
import os
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from fastapi.testclient import TestClient
|
||||
import sys
|
||||
from pathlib import Path as _Path
|
||||
base = _Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(base))
|
||||
sys.path.insert(0, str(base / "docling"))
|
||||
import app.server as server
|
||||
|
||||
|
||||
class FakeMinio:
|
||||
def __init__(self):
|
||||
self.objs = {}
|
||||
|
||||
def put_object(self, bucket_name: str, object_name: str, data: io.BytesIO, length: int, content_type: str):
|
||||
self.objs[(bucket_name, object_name)] = data.read(length)
|
||||
|
||||
def get_presigned_url(self, method: str, bucket: str, obj: str, expires: int):
|
||||
return f"http://minio.test/presigned/{bucket}/{obj}"
|
||||
|
||||
def presigned_get_object(self, bucket: str, obj: str, expires: int):
|
||||
return f"http://minio.test/presigned/{bucket}/{obj}"
|
||||
|
||||
|
||||
def setup():
|
||||
server.RUNTIME_CONFIG["minio"].update({
|
||||
"endpoint": "127.0.0.1:9000",
|
||||
"public": "http://127.0.0.1:9000",
|
||||
"access": "ak",
|
||||
"secret": "sk",
|
||||
"bucket": "test",
|
||||
"secure": "false",
|
||||
"prefix": "assets",
|
||||
"store_final": "true",
|
||||
"public_read": "true",
|
||||
})
|
||||
fake = FakeMinio()
|
||||
def _cur():
|
||||
return fake, "test", "http://127.0.0.1:9000", "assets"
|
||||
server._minio_current = _cur # type: ignore
|
||||
|
||||
|
||||
def main():
|
||||
setup()
|
||||
app = server.app
|
||||
c = TestClient(app)
|
||||
tmp = Path("/tmp/run_batch_upload_debug")
|
||||
tmp.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
zpath = tmp / "pkg.zip"
|
||||
md_dir = tmp / "docs"
|
||||
img_dir = md_dir / "images"
|
||||
img_dir.mkdir(parents=True, exist_ok=True)
|
||||
(img_dir / "p.png").write_bytes(b"PNG")
|
||||
(md_dir / "a.md").write_text("", "utf-8")
|
||||
|
||||
with zipfile.ZipFile(str(zpath), "w") as zf:
|
||||
zf.write(str(md_dir / "a.md"), arcname="a.md")
|
||||
zf.write(str(img_dir / "p.png"), arcname="images/p.png")
|
||||
|
||||
with open(zpath, "rb") as fp:
|
||||
files = {"file": ("pkg.zip", fp.read())}
|
||||
r1 = c.post("/api/archive/stage", files=files)
|
||||
print("stage status:", r1.status_code, r1.json())
|
||||
sid = r1.json()["data"]["id"]
|
||||
|
||||
r2 = c.post("/api/archive/process", data={"id": sid, "prefix": "assets", "versionId": "1001"})
|
||||
print("process status:", r2.status_code, r2.json())
|
||||
|
||||
list_text = str(md_dir / "a.md")
|
||||
lf = io.BytesIO(list_text.encode("utf-8"))
|
||||
r3 = c.post("/api/upload-list", files={"list_file": ("list.txt", lf.getvalue())}, data={"prefix": "assets", "versionId": "1002"})
|
||||
print("upload-list status:", r3.status_code, r3.json())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user