mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-17 21:27:23 +08:00
@@ -100,6 +100,7 @@ def _load_file2document_module(monkeypatch):
|
||||
|
||||
services_pkg = ModuleType("api.db.services")
|
||||
services_pkg.__path__ = []
|
||||
services_pkg.duplicate_name = lambda _query_func, **kwargs: "file(1).txt" if kwargs.get("name") == "file.txt" and kwargs.get("kb_id") == "kb-dup" else kwargs.get("name")
|
||||
monkeypatch.setitem(sys.modules, "api.db.services", services_pkg)
|
||||
|
||||
common_pkg = ModuleType("api.common")
|
||||
@@ -184,6 +185,10 @@ def _load_file2document_module(monkeypatch):
|
||||
def remove_document(*_args, **_kwargs):
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def query(*_args, **_kwargs):
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def insert(_payload):
|
||||
return SimpleNamespace(id="doc-1")
|
||||
@@ -300,3 +305,21 @@ def test_convert_branch_matrix_unit(monkeypatch):
|
||||
res = _run(module.convert())
|
||||
assert res["code"] == 500
|
||||
assert "convert boom" in res["message"]
|
||||
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_convert_files_renames_duplicate_document_name_unit(monkeypatch):
|
||||
module = _load_file2document_module(monkeypatch)
|
||||
inserted_docs = []
|
||||
file = _DummyFile("f1", module.FileType.DOC.value, name="file.txt")
|
||||
kb = SimpleNamespace(id="kb-dup", parser_id="naive", pipeline_id="p1", parser_config={})
|
||||
|
||||
monkeypatch.setattr(module.FileService, "get_by_id", lambda _file_id: (True, file))
|
||||
monkeypatch.setattr(module.KnowledgebaseService, "get_by_id", lambda _kb_id: (True, kb))
|
||||
monkeypatch.setattr(module.DocumentService, "insert", lambda payload: inserted_docs.append(payload) or SimpleNamespace(id="doc-1"))
|
||||
|
||||
module._convert_files(["f1"], ["kb-dup"], "user-1", "add")
|
||||
|
||||
assert inserted_docs[0]["name"] == "file(1).txt"
|
||||
assert inserted_docs[0]["suffix"] == "txt"
|
||||
assert inserted_docs[0]["location"] == "loc"
|
||||
|
||||
Reference in New Issue
Block a user