mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-03-30 02:40:00 +08:00
Revert "Refactor: dataset / kb API to RESTFul style" (#13646)
Reverts infiniflow/ragflow#13619
This commit is contained in:
@ -27,7 +27,6 @@ from utils.file_utils import create_txt_file
|
||||
HEADERS = {"Content-Type": "application/json"}
|
||||
|
||||
KB_APP_URL = f"/{VERSION}/kb"
|
||||
DATASETS_URL = f"/api/{VERSION}/datasets"
|
||||
DOCUMENT_APP_URL = f"/{VERSION}/document"
|
||||
CHUNK_API_URL = f"/{VERSION}/chunk"
|
||||
DIALOG_APP_URL = f"/{VERSION}/dialog"
|
||||
@ -169,28 +168,25 @@ def search_rm(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
|
||||
|
||||
# KB APP
|
||||
def create_dataset(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{DATASETS_URL}", headers=headers, auth=auth, json=payload, data=data)
|
||||
def create_kb(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/create", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def list_datasets(auth, params=None, *, headers=HEADERS):
|
||||
res = requests.get(url=f"{HOST_ADDRESS}{DATASETS_URL}", headers=headers, auth=auth, params=params)
|
||||
def list_kbs(auth, params=None, payload=None, *, headers=HEADERS, data=None):
|
||||
if payload is None:
|
||||
payload = {}
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/list", headers=headers, auth=auth, params=params, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def update_dataset(auth, dataset_id, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.put(url=f"{HOST_ADDRESS}{DATASETS_URL}/{dataset_id}", headers=headers, auth=auth, json=payload, data=data)
|
||||
def update_kb(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/update", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def delete_datasets(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
"""
|
||||
Delete datasets.
|
||||
The endpoint is DELETE /api/{VERSION}/datasets with payload {"ids": [...]}
|
||||
This is the standard SDK REST API endpoint for dataset deletion.
|
||||
"""
|
||||
res = requests.delete(url=f"{HOST_ADDRESS}{DATASETS_URL}", headers=headers, auth=auth, json=payload, data=data)
|
||||
def rm_kb(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/rm", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
@ -240,43 +236,23 @@ def kb_pipeline_log_detail(auth, params=None, *, headers=HEADERS):
|
||||
return res.json()
|
||||
|
||||
|
||||
# DATASET GRAPH AND TASKS
|
||||
def knowledge_graph(auth, dataset_id, params=None):
|
||||
url = f"{HOST_ADDRESS}{DATASETS_URL}/{dataset_id}/knowledge_graph"
|
||||
res = requests.get(url=url, headers=HEADERS, auth=auth, params=params)
|
||||
def kb_run_graphrag(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/run_graphrag", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def delete_knowledge_graph(auth, dataset_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{DATASETS_URL}/{dataset_id}/knowledge_graph"
|
||||
if payload is None:
|
||||
res = requests.delete(url=url, headers=HEADERS, auth=auth)
|
||||
else:
|
||||
res = requests.delete(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
def kb_trace_graphrag(auth, params=None, *, headers=HEADERS):
|
||||
res = requests.get(url=f"{HOST_ADDRESS}{KB_APP_URL}/trace_graphrag", headers=headers, auth=auth, params=params)
|
||||
return res.json()
|
||||
|
||||
|
||||
def run_graphrag(auth, dataset_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{DATASETS_URL}/{dataset_id}/run_graphrag"
|
||||
res = requests.post(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
def kb_run_raptor(auth, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.post(url=f"{HOST_ADDRESS}{KB_APP_URL}/run_raptor", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def trace_graphrag(auth, dataset_id, params=None):
|
||||
url = f"{HOST_ADDRESS}{DATASETS_URL}/{dataset_id}/trace_graphrag"
|
||||
res = requests.get(url=url, headers=HEADERS, auth=auth, params=params)
|
||||
return res.json()
|
||||
|
||||
|
||||
def run_raptor(auth, dataset_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{DATASETS_URL}/{dataset_id}/run_raptor"
|
||||
res = requests.post(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
def trace_raptor(auth, dataset_id, params=None):
|
||||
url = f"{HOST_ADDRESS}{DATASETS_URL}/{dataset_id}/trace_raptor"
|
||||
res = requests.get(url=url, headers=HEADERS, auth=auth, params=params)
|
||||
def kb_trace_raptor(auth, params=None, *, headers=HEADERS):
|
||||
res = requests.get(url=f"{HOST_ADDRESS}{KB_APP_URL}/trace_raptor", headers=headers, auth=auth, params=params)
|
||||
return res.json()
|
||||
|
||||
|
||||
@ -310,11 +286,21 @@ def rename_tags(auth, dataset_id, payload=None, *, headers=HEADERS, data=None):
|
||||
return res.json()
|
||||
|
||||
|
||||
def knowledge_graph(auth, dataset_id, params=None, *, headers=HEADERS):
|
||||
res = requests.get(url=f"{HOST_ADDRESS}{KB_APP_URL}/{dataset_id}/knowledge_graph", headers=headers, auth=auth, params=params)
|
||||
return res.json()
|
||||
|
||||
|
||||
def delete_knowledge_graph(auth, dataset_id, payload=None, *, headers=HEADERS, data=None):
|
||||
res = requests.delete(url=f"{HOST_ADDRESS}{KB_APP_URL}/{dataset_id}/knowledge_graph", headers=headers, auth=auth, json=payload, data=data)
|
||||
return res.json()
|
||||
|
||||
|
||||
def batch_create_datasets(auth, num):
|
||||
ids = []
|
||||
for i in range(num):
|
||||
res = create_dataset(auth, {"name": f"kb_{i}"})
|
||||
ids.append(res["data"]["id"])
|
||||
res = create_kb(auth, {"name": f"kb_{i}"})
|
||||
ids.append(res["data"]["kb_id"])
|
||||
return ids
|
||||
|
||||
|
||||
|
||||
@ -26,9 +26,9 @@ from common import (
|
||||
delete_dialogs,
|
||||
list_chunks,
|
||||
list_documents,
|
||||
list_datasets,
|
||||
list_kbs,
|
||||
parse_documents,
|
||||
delete_datasets,
|
||||
rm_kb,
|
||||
)
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
from pytest import FixtureRequest
|
||||
@ -104,9 +104,9 @@ def require_env_flag():
|
||||
@pytest.fixture(scope="function")
|
||||
def clear_datasets(request: FixtureRequest, WebApiAuth: RAGFlowWebApiAuth):
|
||||
def cleanup():
|
||||
res = list_datasets(WebApiAuth, params={"page_size": 1000})
|
||||
kb_ids = [kb["id"] for kb in res["data"]]
|
||||
delete_datasets(WebApiAuth, {"ids": kb_ids})
|
||||
res = list_kbs(WebApiAuth, params={"page_size": 1000})
|
||||
for kb in res["data"]["kbs"]:
|
||||
rm_kb(WebApiAuth, {"kb_id": kb["id"]})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
|
||||
@ -122,9 +122,9 @@ def clear_dialogs(request, WebApiAuth):
|
||||
@pytest.fixture(scope="class")
|
||||
def add_dataset(request: FixtureRequest, WebApiAuth: RAGFlowWebApiAuth) -> str:
|
||||
def cleanup():
|
||||
res = list_datasets(WebApiAuth, params={"page_size": 1000})
|
||||
kb_ids = [kb["id"] for kb in res["data"]]
|
||||
delete_datasets(WebApiAuth, {"ids": kb_ids})
|
||||
res = list_kbs(WebApiAuth, params={"page_size": 1000})
|
||||
for kb in res["data"]["kbs"]:
|
||||
rm_kb(WebApiAuth, {"kb_id": kb["id"]})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return batch_create_datasets(WebApiAuth, 1)[0]
|
||||
@ -133,9 +133,9 @@ def add_dataset(request: FixtureRequest, WebApiAuth: RAGFlowWebApiAuth) -> str:
|
||||
@pytest.fixture(scope="function")
|
||||
def add_dataset_func(request: FixtureRequest, WebApiAuth: RAGFlowWebApiAuth) -> str:
|
||||
def cleanup():
|
||||
res = list_datasets(WebApiAuth, params={"page_size": 1000})
|
||||
kb_ids = [kb["id"] for kb in res["data"]]
|
||||
delete_datasets(WebApiAuth, {"ids": kb_ids})
|
||||
res = list_kbs(WebApiAuth, params={"page_size": 1000})
|
||||
for kb in res["data"]["kbs"]:
|
||||
rm_kb(WebApiAuth, {"kb_id": kb["id"]})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return batch_create_datasets(WebApiAuth, 1)[0]
|
||||
|
||||
@ -409,7 +409,7 @@ def _load_dataset_module(monkeypatch):
|
||||
rag_nlp_pkg.search = search_mod
|
||||
|
||||
module_name = "test_dataset_sdk_routes_unit_module"
|
||||
module_path = repo_root / "api" / "apps" / "restful_apis" / "dataset_api.py"
|
||||
module_path = repo_root / "api" / "apps" / "sdk" / "dataset.py"
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
module.manager = _DummyManager()
|
||||
@ -418,7 +418,7 @@ def _load_dataset_module(monkeypatch):
|
||||
return module
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_create_route_error_matrix_unit(monkeypatch):
|
||||
module = _load_dataset_module(monkeypatch)
|
||||
req_state = {"name": "kb"}
|
||||
@ -448,7 +448,7 @@ def test_create_route_error_matrix_unit(monkeypatch):
|
||||
assert res["message"] == "Database operation failed", res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_delete_route_error_summary_matrix_unit(monkeypatch):
|
||||
module = _load_dataset_module(monkeypatch)
|
||||
req_state = {"ids": ["kb-1"]}
|
||||
@ -476,7 +476,7 @@ def test_delete_route_error_summary_matrix_unit(monkeypatch):
|
||||
assert res["code"] == module.RetCode.SUCCESS, res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_update_route_branch_matrix_unit(monkeypatch):
|
||||
module = _load_dataset_module(monkeypatch)
|
||||
req_state = {"name": "new"}
|
||||
@ -556,7 +556,7 @@ def test_update_route_branch_matrix_unit(monkeypatch):
|
||||
assert res["message"] == "Database operation failed", res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_list_knowledge_graph_delete_kg_matrix_unit(monkeypatch):
|
||||
module = _load_dataset_module(monkeypatch)
|
||||
|
||||
@ -629,7 +629,7 @@ def test_list_knowledge_graph_delete_kg_matrix_unit(monkeypatch):
|
||||
assert res["code"] == module.RetCode.AUTHENTICATION_ERROR, res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_run_trace_graphrag_matrix_unit(monkeypatch):
|
||||
module = _load_dataset_module(monkeypatch)
|
||||
|
||||
@ -705,7 +705,7 @@ def test_run_trace_graphrag_matrix_unit(monkeypatch):
|
||||
assert res["data"]["id"] == "task-1", res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_run_trace_raptor_matrix_unit(monkeypatch):
|
||||
module = _load_dataset_module(monkeypatch)
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ from types import SimpleNamespace
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from test_web_api.common import create_document, list_datasets
|
||||
from common import create_document, list_kbs
|
||||
from configs import DOCUMENT_NAME_LIMIT, INVALID_API_TOKEN
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
from utils.file_utils import create_txt_file
|
||||
@ -91,8 +91,8 @@ class TestDocumentCreate:
|
||||
assert len(responses) == count, responses
|
||||
assert all(future.result()["code"] == 0 for future in futures), responses
|
||||
|
||||
res = list_datasets(WebApiAuth, {"id": kb_id})
|
||||
assert res["data"][0]["document_count"] == count, res
|
||||
res = list_kbs(WebApiAuth, {"id": kb_id})
|
||||
assert res["data"]["kbs"][0]["doc_num"] == count, res
|
||||
|
||||
|
||||
def _run(coro):
|
||||
|
||||
@ -20,7 +20,7 @@ from types import ModuleType, SimpleNamespace
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from common import list_datasets, upload_documents
|
||||
from common import list_kbs, upload_documents
|
||||
from configs import DOCUMENT_NAME_LIMIT, INVALID_API_TOKEN
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
from utils.file_utils import create_txt_file
|
||||
@ -172,8 +172,8 @@ class TestDocumentsUpload:
|
||||
res = upload_documents(WebApiAuth, {"kb_id": kb_id}, fps)
|
||||
assert res["code"] == 0, res
|
||||
|
||||
res = list_datasets(WebApiAuth)
|
||||
assert res["data"][0]["document_count"] == expected_document_count, res
|
||||
res = list_kbs(WebApiAuth)
|
||||
assert res["data"]["kbs"][0]["doc_num"] == expected_document_count, res
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_concurrent_upload(self, WebApiAuth, add_dataset_func, tmp_path):
|
||||
@ -191,8 +191,8 @@ class TestDocumentsUpload:
|
||||
assert len(responses) == count, responses
|
||||
assert all(future.result()["code"] == 0 for future in futures), responses
|
||||
|
||||
res = list_datasets(WebApiAuth)
|
||||
assert res["data"][0]["document_count"] == count, res
|
||||
res = list_kbs(WebApiAuth)
|
||||
assert res["data"]["kbs"][0]["doc_num"] == count, res
|
||||
|
||||
|
||||
class _AwaitableValue:
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
import pytest
|
||||
from common import batch_create_datasets, list_datasets, delete_datasets
|
||||
from common import batch_create_datasets, list_kbs, rm_kb
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
from pytest import FixtureRequest
|
||||
from ragflow_sdk import RAGFlow
|
||||
@ -26,10 +26,11 @@ def add_datasets(request: FixtureRequest, client: RAGFlow, WebApiAuth: RAGFlowWe
|
||||
|
||||
def cleanup():
|
||||
# Web KB cleanup cannot call SDK dataset bulk delete with empty ids; deletion must stay explicit.
|
||||
res = list_datasets(WebApiAuth, params={"page_size": 1000})
|
||||
existing_ids = {kb["id"] for kb in res["data"]}
|
||||
ids_to_delete = list({dataset_id for dataset_id in dataset_ids if dataset_id in existing_ids})
|
||||
delete_datasets(WebApiAuth, {"ids": ids_to_delete})
|
||||
res = list_kbs(WebApiAuth, params={"page_size": 1000})
|
||||
existing_ids = {kb["id"] for kb in res["data"]["kbs"]}
|
||||
for dataset_id in dataset_ids:
|
||||
if dataset_id in existing_ids:
|
||||
rm_kb(WebApiAuth, {"kb_id": dataset_id})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return dataset_ids
|
||||
@ -41,10 +42,11 @@ def add_datasets_func(request: FixtureRequest, client: RAGFlow, WebApiAuth: RAGF
|
||||
|
||||
def cleanup():
|
||||
# Web KB cleanup cannot call SDK dataset bulk delete with empty ids; deletion must stay explicit.
|
||||
res = list_datasets(WebApiAuth, params={"page_size": 1000})
|
||||
existing_ids = {kb["id"] for kb in res["data"]}
|
||||
ids_to_delete = list({dataset_id for dataset_id in dataset_ids if dataset_id in existing_ids})
|
||||
delete_datasets(WebApiAuth, {"ids": ids_to_delete})
|
||||
res = list_kbs(WebApiAuth, params={"page_size": 1000})
|
||||
existing_ids = {kb["id"] for kb in res["data"]["kbs"]}
|
||||
for dataset_id in dataset_ids:
|
||||
if dataset_id in existing_ids:
|
||||
rm_kb(WebApiAuth, {"kb_id": dataset_id})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return dataset_ids
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from common import create_dataset
|
||||
from common import create_kb
|
||||
from configs import DATASET_NAME_LIMIT, INVALID_API_TOKEN
|
||||
from hypothesis import example, given, settings
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
@ -35,7 +35,7 @@ class TestAuthorization:
|
||||
ids=["empty_auth", "invalid_api_token"],
|
||||
)
|
||||
def test_auth_invalid(self, invalid_auth, expected_code, expected_message):
|
||||
res = create_dataset(invalid_auth, {"name": "auth_test"})
|
||||
res = create_kb(invalid_auth, {"name": "auth_test"})
|
||||
assert res["code"] == expected_code, res
|
||||
assert res["message"] == expected_message, res
|
||||
|
||||
@ -46,14 +46,14 @@ class TestCapability:
|
||||
def test_create_kb_1k(self, WebApiAuth):
|
||||
for i in range(1_000):
|
||||
payload = {"name": f"dataset_{i}"}
|
||||
res = create_dataset(WebApiAuth, payload)
|
||||
res = create_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, f"Failed to create dataset {i}"
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_create_kb_concurrent(self, WebApiAuth):
|
||||
count = 100
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [executor.submit(create_dataset, WebApiAuth, {"name": f"dataset_{i}"}) for i in range(count)]
|
||||
futures = [executor.submit(create_kb, WebApiAuth, {"name": f"dataset_{i}"}) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(future.result()["code"] == 0 for future in futures)
|
||||
@ -66,44 +66,44 @@ class TestDatasetCreate:
|
||||
@example("a" * 128)
|
||||
@settings(max_examples=20)
|
||||
def test_name(self, WebApiAuth, name):
|
||||
res = create_dataset(WebApiAuth, {"name": name})
|
||||
res = create_kb(WebApiAuth, {"name": name})
|
||||
assert res["code"] == 0, res
|
||||
|
||||
@pytest.mark.p2
|
||||
@pytest.mark.parametrize(
|
||||
"name, expected_message",
|
||||
[
|
||||
("", "Field: <name> - Message: <String should have at least 1 character>"),
|
||||
(" ", "Field: <name> - Message: <String should have at least 1 character>"),
|
||||
("a" * (DATASET_NAME_LIMIT + 1), "Field: <name> - Message: <String should have at most 128 characters>"),
|
||||
(0, "Field: <name> - Message: <Input should be a valid string>"),
|
||||
(None, "Field: <name> - Message: <Input should be a valid string>"),
|
||||
("", "Dataset name can't be empty."),
|
||||
(" ", "Dataset name can't be empty."),
|
||||
("a" * (DATASET_NAME_LIMIT + 1), "Dataset name length is 129 which is large than 128"),
|
||||
(0, "Dataset name must be string."),
|
||||
(None, "Dataset name must be string."),
|
||||
],
|
||||
ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
|
||||
)
|
||||
def test_name_invalid(self, WebApiAuth, name, expected_message):
|
||||
payload = {"name": name}
|
||||
res = create_dataset(WebApiAuth, payload)
|
||||
assert res["code"] == 101, res
|
||||
res = create_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 102, res
|
||||
assert expected_message in res["message"], res
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_name_duplicated(self, WebApiAuth):
|
||||
name = "duplicated_name"
|
||||
payload = {"name": name}
|
||||
res = create_dataset(WebApiAuth, payload)
|
||||
res = create_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
|
||||
res = create_dataset(WebApiAuth, payload)
|
||||
res = create_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_name_case_insensitive(self, WebApiAuth):
|
||||
name = "CaseInsensitive"
|
||||
payload = {"name": name.upper()}
|
||||
res = create_dataset(WebApiAuth, payload)
|
||||
res = create_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
|
||||
payload = {"name": name.lower()}
|
||||
res = create_dataset(WebApiAuth, payload)
|
||||
res = create_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
|
||||
@ -14,17 +14,17 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
import pytest
|
||||
from test_web_api.common import (
|
||||
from common import (
|
||||
kb_delete_pipeline_logs,
|
||||
kb_list_pipeline_dataset_logs,
|
||||
kb_list_pipeline_logs,
|
||||
kb_pipeline_log_detail,
|
||||
run_graphrag,
|
||||
trace_graphrag,
|
||||
run_raptor,
|
||||
trace_raptor,
|
||||
kb_run_graphrag,
|
||||
kb_run_mindmap,
|
||||
kb_run_raptor,
|
||||
kb_trace_graphrag,
|
||||
kb_trace_mindmap,
|
||||
kb_trace_raptor,
|
||||
list_documents,
|
||||
parse_documents,
|
||||
)
|
||||
@ -101,13 +101,13 @@ class TestKbPipelineTasks:
|
||||
@pytest.mark.p3
|
||||
def test_graphrag_run_and_trace(self, WebApiAuth, add_chunks):
|
||||
kb_id, _, _ = add_chunks
|
||||
run_res = run_graphrag(WebApiAuth, kb_id)
|
||||
run_res = kb_run_graphrag(WebApiAuth, {"kb_id": kb_id})
|
||||
assert run_res["code"] == 0, run_res
|
||||
task_id = run_res["data"]["graphrag_task_id"]
|
||||
assert task_id, run_res
|
||||
|
||||
_wait_for_task(trace_graphrag, WebApiAuth, kb_id, task_id)
|
||||
trace_res = trace_graphrag(WebApiAuth, kb_id)
|
||||
_wait_for_task(kb_trace_graphrag, WebApiAuth, kb_id, task_id)
|
||||
trace_res = kb_trace_graphrag(WebApiAuth, {"kb_id": kb_id})
|
||||
assert trace_res["code"] == 0, trace_res
|
||||
task = _find_task(trace_res["data"], task_id)
|
||||
assert task, trace_res
|
||||
@ -118,13 +118,13 @@ class TestKbPipelineTasks:
|
||||
@pytest.mark.p3
|
||||
def test_raptor_run_and_trace(self, WebApiAuth, add_chunks):
|
||||
kb_id, _, _ = add_chunks
|
||||
run_res = run_raptor(WebApiAuth, kb_id)
|
||||
run_res = kb_run_raptor(WebApiAuth, {"kb_id": kb_id})
|
||||
assert run_res["code"] == 0, run_res
|
||||
task_id = run_res["data"]["raptor_task_id"]
|
||||
assert task_id, run_res
|
||||
|
||||
_wait_for_task(trace_raptor, WebApiAuth, kb_id, task_id)
|
||||
trace_res = trace_raptor(WebApiAuth, kb_id)
|
||||
_wait_for_task(kb_trace_raptor, WebApiAuth, kb_id, task_id)
|
||||
trace_res = kb_trace_raptor(WebApiAuth, {"kb_id": kb_id})
|
||||
assert trace_res["code"] == 0, trace_res
|
||||
task = _find_task(trace_res["data"], task_id)
|
||||
assert task, trace_res
|
||||
|
||||
@ -181,7 +181,7 @@ def set_tenant_info():
|
||||
return None
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_create_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -211,7 +211,7 @@ def test_create_branches(monkeypatch):
|
||||
assert "save boom" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_update_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
update_route = _unwrap_route(module.update)
|
||||
@ -326,7 +326,7 @@ def test_update_branches(monkeypatch):
|
||||
assert "update boom" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_update_metadata_setting_not_found(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
_set_request_json(monkeypatch, module, {"kb_id": "missing-kb", "metadata": {}})
|
||||
@ -336,7 +336,7 @@ def test_update_metadata_setting_not_found(monkeypatch):
|
||||
assert "Database error" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_detail_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -380,7 +380,7 @@ def test_detail_branches(monkeypatch):
|
||||
assert "detail boom" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_list_kbs_owner_ids_and_desc(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -414,7 +414,7 @@ def test_list_kbs_owner_ids_and_desc(monkeypatch):
|
||||
assert "list boom" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_rm_and_rm_sync_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -491,7 +491,7 @@ def test_rm_and_rm_sync_branches(monkeypatch):
|
||||
assert "rm boom" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_tags_and_meta_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -560,7 +560,7 @@ def test_tags_and_meta_branches(monkeypatch):
|
||||
assert res["data"]["finished"] == 1, res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_knowledge_graph_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -636,7 +636,7 @@ def test_knowledge_graph_branches(monkeypatch):
|
||||
assert res["data"] is True, res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_list_pipeline_logs_validation_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -681,7 +681,7 @@ def test_list_pipeline_logs_validation_branches(monkeypatch):
|
||||
assert "Create data filter is abnormal." in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_list_pipeline_logs_filter_and_exception_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -718,7 +718,7 @@ def test_list_pipeline_logs_filter_and_exception_branches(monkeypatch):
|
||||
assert "logs boom" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_list_pipeline_dataset_logs_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -792,7 +792,7 @@ def test_list_pipeline_dataset_logs_branches(monkeypatch):
|
||||
assert "dataset logs boom" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_pipeline_log_detail_and_delete_routes_branches(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
|
||||
@ -841,7 +841,7 @@ def test_pipeline_log_detail_and_delete_routes_branches(monkeypatch):
|
||||
assert res["data"]["id"] == "log-1", res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
@pytest.mark.parametrize(
|
||||
"route_name,task_attr,response_key,task_type",
|
||||
[
|
||||
@ -914,7 +914,7 @@ def test_run_pipeline_task_routes_branch_matrix(monkeypatch, route_name, task_at
|
||||
assert queue_calls["doc_ids"] == ["doc-1", "doc-2"], queue_calls
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
@pytest.mark.parametrize(
|
||||
"route_name,task_attr,empty_on_missing_task,error_text",
|
||||
[
|
||||
@ -970,7 +970,7 @@ def test_trace_pipeline_task_routes_branch_matrix(monkeypatch, route_name, task_
|
||||
assert res["data"]["id"] == "task-1", res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_unbind_task_branch_matrix(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
route = inspect.unwrap(module.delete_kb_task)
|
||||
@ -1060,7 +1060,7 @@ def test_unbind_task_branch_matrix(monkeypatch):
|
||||
assert "cannot delete task" in res["message"], res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_check_embedding_similarity_threshold_matrix_unit(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
route = inspect.unwrap(module.check_embedding)
|
||||
@ -1229,7 +1229,7 @@ def test_check_embedding_similarity_threshold_matrix_unit(monkeypatch):
|
||||
assert res["data"]["summary"]["avg_cos_sim"] > 0.9, res
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.p2
|
||||
def test_check_embedding_error_and_empty_sample_paths_unit(monkeypatch):
|
||||
module = _load_kb_module(monkeypatch)
|
||||
route = inspect.unwrap(module.check_embedding)
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from test_web_api.common import (
|
||||
from common import (
|
||||
delete_knowledge_graph,
|
||||
kb_basic_info,
|
||||
kb_get_meta,
|
||||
|
||||
@ -13,11 +13,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
import json
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from common import list_datasets
|
||||
from common import list_kbs
|
||||
from configs import INVALID_API_TOKEN
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
from utils import is_sorted
|
||||
@ -33,7 +32,7 @@ class TestAuthorization:
|
||||
],
|
||||
)
|
||||
def test_auth_invalid(self, invalid_auth, expected_code, expected_message):
|
||||
res = list_datasets(invalid_auth)
|
||||
res = list_kbs(invalid_auth)
|
||||
assert res["code"] == expected_code, res
|
||||
assert res["message"] == expected_message, res
|
||||
|
||||
@ -43,7 +42,7 @@ class TestCapability:
|
||||
def test_concurrent_list(self, WebApiAuth):
|
||||
count = 100
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [executor.submit(list_datasets, WebApiAuth) for i in range(count)]
|
||||
futures = [executor.submit(list_kbs, WebApiAuth) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(future.result()["code"] == 0 for future in futures)
|
||||
@ -53,15 +52,15 @@ class TestCapability:
|
||||
class TestDatasetsList:
|
||||
@pytest.mark.p2
|
||||
def test_params_unset(self, WebApiAuth):
|
||||
res = list_datasets(WebApiAuth, None)
|
||||
res = list_kbs(WebApiAuth, None)
|
||||
assert res["code"] == 0, res
|
||||
assert len(res["data"]) == 5, res
|
||||
assert len(res["data"]["kbs"]) == 5, res
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_params_empty(self, WebApiAuth):
|
||||
res = list_datasets(WebApiAuth, {})
|
||||
res = list_kbs(WebApiAuth, {})
|
||||
assert res["code"] == 0, res
|
||||
assert len(res["data"]) == 5, res
|
||||
assert len(res["data"]["kbs"]) == 5, res
|
||||
|
||||
@pytest.mark.p1
|
||||
@pytest.mark.parametrize(
|
||||
@ -76,9 +75,9 @@ class TestDatasetsList:
|
||||
ids=["normal_middle_page", "normal_last_partial_page", "beyond_max_page", "string_page_number", "full_data_single_page"],
|
||||
)
|
||||
def test_page(self, WebApiAuth, params, expected_page_size):
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
assert res["code"] == 0, res
|
||||
assert len(res["data"]) == expected_page_size, res
|
||||
assert len(res["data"]["kbs"]) == expected_page_size, res
|
||||
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.p2
|
||||
@ -91,16 +90,16 @@ class TestDatasetsList:
|
||||
ids=["page_0", "page_a"],
|
||||
)
|
||||
def test_page_invalid(self, WebApiAuth, params, expected_code, expected_message):
|
||||
res = list_datasets(WebApiAuth, params=params)
|
||||
res = list_kbs(WebApiAuth, params=params)
|
||||
assert res["code"] == expected_code, res
|
||||
assert expected_message in res["message"], res
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_page_none(self, WebApiAuth):
|
||||
params = {"page": None}
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
assert res["code"] == 0, res
|
||||
assert len(res["data"]) == 5, res
|
||||
assert len(res["data"]["kbs"]) == 5, res
|
||||
|
||||
@pytest.mark.p1
|
||||
@pytest.mark.parametrize(
|
||||
@ -115,9 +114,9 @@ class TestDatasetsList:
|
||||
ids=["min_valid_page_size", "medium_page_size", "page_size_equals_total", "page_size_exceeds_total", "string_type_page_size"],
|
||||
)
|
||||
def test_page_size(self, WebApiAuth, params, expected_page_size):
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
assert res["code"] == 0, res
|
||||
assert len(res["data"]) == expected_page_size, res
|
||||
assert len(res["data"]["kbs"]) == expected_page_size, res
|
||||
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.p2
|
||||
@ -129,27 +128,27 @@ class TestDatasetsList:
|
||||
],
|
||||
)
|
||||
def test_page_size_invalid(self, WebApiAuth, params, expected_code, expected_message):
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
assert res["code"] == expected_code, res
|
||||
assert expected_message in res["message"], res
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_page_size_none(self, WebApiAuth):
|
||||
params = {"page_size": None}
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
assert res["code"] == 0, res
|
||||
assert len(res["data"]) == 5, res
|
||||
assert len(res["data"]["kbs"]) == 5, res
|
||||
|
||||
@pytest.mark.p3
|
||||
@pytest.mark.parametrize(
|
||||
"params, assertions",
|
||||
[
|
||||
({"orderby": "update_time"}, lambda r: (is_sorted(r["data"], "update_time", True))),
|
||||
({"orderby": "update_time"}, lambda r: (is_sorted(r["data"]["kbs"], "update_time", True))),
|
||||
],
|
||||
ids=["orderby_update_time"],
|
||||
)
|
||||
def test_orderby(self, WebApiAuth, params, assertions):
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
assert res["code"] == 0, res
|
||||
if callable(assertions):
|
||||
assert assertions(res), res
|
||||
@ -158,13 +157,13 @@ class TestDatasetsList:
|
||||
@pytest.mark.parametrize(
|
||||
"params, assertions",
|
||||
[
|
||||
({"desc": "True"}, lambda r: (is_sorted(r["data"], "update_time", True))),
|
||||
({"desc": "False"}, lambda r: (is_sorted(r["data"], "update_time", False))),
|
||||
({"desc": "True"}, lambda r: (is_sorted(r["data"]["kbs"], "update_time", True))),
|
||||
({"desc": "False"}, lambda r: (is_sorted(r["data"]["kbs"], "update_time", False))),
|
||||
],
|
||||
ids=["desc=True", "desc=False"],
|
||||
)
|
||||
def test_desc(self, WebApiAuth, params, assertions):
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
|
||||
assert res["code"] == 0, res
|
||||
if callable(assertions):
|
||||
@ -174,28 +173,29 @@ class TestDatasetsList:
|
||||
@pytest.mark.parametrize(
|
||||
"params, expected_page_size",
|
||||
[
|
||||
({"ext": json.dumps({"parser_id": "naive"})}, 5),
|
||||
({"ext": json.dumps({"parser_id": "qa"})}, 0),
|
||||
({"parser_id": "naive"}, 5),
|
||||
({"parser_id": "qa"}, 0),
|
||||
],
|
||||
ids=["naive", "dqa"],
|
||||
)
|
||||
def test_parser_id(self, WebApiAuth, params, expected_page_size):
|
||||
res = list_datasets(WebApiAuth, params)
|
||||
res = list_kbs(WebApiAuth, params)
|
||||
assert res["code"] == 0, res
|
||||
assert len(res["data"]) == expected_page_size, res
|
||||
assert len(res["data"]["kbs"]) == expected_page_size, res
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_owner_ids_payload_mode(self, WebApiAuth):
|
||||
base_res = list_datasets(WebApiAuth, {"page_size": 10})
|
||||
base_res = list_kbs(WebApiAuth, {"page_size": 10})
|
||||
assert base_res["code"] == 0, base_res
|
||||
assert base_res["data"], base_res
|
||||
owner_id = base_res["data"][0]["tenant_id"]
|
||||
assert base_res["data"]["kbs"], base_res
|
||||
owner_id = base_res["data"]["kbs"][0]["tenant_id"]
|
||||
|
||||
res = list_datasets(
|
||||
res = list_kbs(
|
||||
WebApiAuth,
|
||||
params={"page": 1, "page_size": 2, "desc": "false", "ext": json.dumps({"owner_ids": [owner_id]})},
|
||||
params={"page": 1, "page_size": 2, "desc": "false"},
|
||||
payload={"owner_ids": [owner_id]},
|
||||
)
|
||||
assert res["code"] == 0, res
|
||||
assert res["total_datasets"] >= len(res["data"]), res
|
||||
assert len(res["data"]) <= 2, res
|
||||
assert all(kb["tenant_id"] == owner_id for kb in res["data"]), res
|
||||
assert res["data"]["total"] >= len(res["data"]["kbs"]), res
|
||||
assert len(res["data"]["kbs"]) <= 2, res
|
||||
assert all(kb["tenant_id"] == owner_id for kb in res["data"]["kbs"]), res
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
|
||||
import pytest
|
||||
from common import (
|
||||
list_datasets,
|
||||
delete_datasets,
|
||||
list_kbs,
|
||||
rm_kb,
|
||||
)
|
||||
from configs import INVALID_API_TOKEN
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
@ -33,7 +33,7 @@ class TestAuthorization:
|
||||
],
|
||||
)
|
||||
def test_auth_invalid(self, invalid_auth, expected_code, expected_message):
|
||||
res = delete_datasets(invalid_auth)
|
||||
res = rm_kb(invalid_auth)
|
||||
assert res["code"] == expected_code, res
|
||||
assert res["message"] == expected_message, res
|
||||
|
||||
@ -42,20 +42,20 @@ class TestDatasetsDelete:
|
||||
@pytest.mark.p1
|
||||
def test_kb_id(self, WebApiAuth, add_datasets_func):
|
||||
kb_ids = add_datasets_func
|
||||
payload = {"ids": [kb_ids[0]]}
|
||||
res = delete_datasets(WebApiAuth, payload)
|
||||
payload = {"kb_id": kb_ids[0]}
|
||||
res = rm_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
|
||||
res = list_datasets(WebApiAuth)
|
||||
assert len(res["data"]) == 2, res
|
||||
res = list_kbs(WebApiAuth)
|
||||
assert len(res["data"]["kbs"]) == 2, res
|
||||
|
||||
@pytest.mark.p2
|
||||
@pytest.mark.usefixtures("add_dataset_func")
|
||||
def test_id_wrong_uuid(self, WebApiAuth):
|
||||
payload = {"ids": ["d94a8dc02c9711f0930f7fbc369eab6d"]}
|
||||
res = delete_datasets(WebApiAuth, payload)
|
||||
assert res["code"] == 102, res
|
||||
assert "lacks permission" in res["message"], res
|
||||
payload = {"kb_id": "d94a8dc02c9711f0930f7fbc369eab6d"}
|
||||
res = rm_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 109, res
|
||||
assert "No authorization." in res["message"], res
|
||||
|
||||
res = list_datasets(WebApiAuth)
|
||||
assert len(res["data"]) == 1, res
|
||||
res = list_kbs(WebApiAuth)
|
||||
assert len(res["data"]["kbs"]) == 1, res
|
||||
|
||||
@ -17,7 +17,7 @@ import os
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from test_web_api.common import update_dataset
|
||||
from common import update_kb
|
||||
from configs import DATASET_NAME_LIMIT, INVALID_API_TOKEN
|
||||
from hypothesis import HealthCheck, example, given, settings
|
||||
from libs.auth import RAGFlowWebApiAuth
|
||||
@ -37,7 +37,7 @@ class TestAuthorization:
|
||||
ids=["empty_auth", "invalid_api_token"],
|
||||
)
|
||||
def test_auth_invalid(self, invalid_auth, expected_code, expected_message):
|
||||
res = update_dataset(invalid_auth, "dataset_id")
|
||||
res = update_kb(invalid_auth, "dataset_id")
|
||||
assert res["code"] == expected_code, res
|
||||
assert res["message"] == expected_message, res
|
||||
|
||||
@ -50,13 +50,13 @@ class TestCapability:
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [
|
||||
executor.submit(
|
||||
update_dataset,
|
||||
update_kb,
|
||||
WebApiAuth,
|
||||
dataset_id,
|
||||
{
|
||||
"kb_id": dataset_id,
|
||||
"name": f"dataset_{i}",
|
||||
"description": "",
|
||||
"chunk_method": "naive",
|
||||
"parser_id": "naive",
|
||||
},
|
||||
)
|
||||
for i in range(count)
|
||||
@ -69,8 +69,8 @@ class TestCapability:
|
||||
class TestDatasetUpdate:
|
||||
@pytest.mark.p3
|
||||
def test_dataset_id_not_uuid(self, WebApiAuth):
|
||||
payload = {"name": "not uuid", "description": "", "chunk_method": "naive"}
|
||||
res = update_dataset(WebApiAuth, "not_uuid", payload)
|
||||
payload = {"name": "not uuid", "description": "", "parser_id": "naive", "kb_id": "not_uuid"}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 109, res
|
||||
assert "No authorization." in res["message"], res
|
||||
|
||||
@ -81,8 +81,8 @@ class TestDatasetUpdate:
|
||||
@settings(max_examples=20, suppress_health_check=[HealthCheck.function_scoped_fixture], deadline=None)
|
||||
def test_name(self, WebApiAuth, add_dataset_func, name):
|
||||
dataset_id = add_dataset_func
|
||||
payload = {"name": name, "description": "", "chunk_method": "naive"}
|
||||
res = update_dataset(WebApiAuth, dataset_id, payload)
|
||||
payload = {"name": name, "description": "", "parser_id": "naive", "kb_id": dataset_id}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["name"] == name, res
|
||||
|
||||
@ -90,27 +90,27 @@ class TestDatasetUpdate:
|
||||
@pytest.mark.parametrize(
|
||||
"name, expected_message",
|
||||
[
|
||||
("", "Field: <name> - Message: <String should have at least 1 character>"),
|
||||
(" ", "Field: <name> - Message: <String should have at least 1 character>"),
|
||||
("a" * (DATASET_NAME_LIMIT + 1), "Field: <name> - Message: <String should have at most 128 characters>"),
|
||||
(0, "Field: <name> - Message: <Input should be a valid string>"),
|
||||
(None, "Field: <name> - Message: <Input should be a valid string>"),
|
||||
("", "Dataset name can't be empty."),
|
||||
(" ", "Dataset name can't be empty."),
|
||||
("a" * (DATASET_NAME_LIMIT + 1), "Dataset name length is 129 which is large than 128"),
|
||||
(0, "Dataset name must be string."),
|
||||
(None, "Dataset name must be string."),
|
||||
],
|
||||
ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
|
||||
)
|
||||
def test_name_invalid(self, WebApiAuth, add_dataset_func, name, expected_message):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": name, "description": "", "chunk_method": "naive"}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
assert res["code"] == 101, res
|
||||
payload = {"name": name, "description": "", "parser_id": "naive", "kb_id": kb_id}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 102, res
|
||||
assert expected_message in res["message"], res
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_name_duplicated(self, WebApiAuth, add_datasets_func):
|
||||
kb_id = add_datasets_func[0]
|
||||
name = "kb_1"
|
||||
payload = {"name": name, "description": "", "chunk_method": "naive"}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": name, "description": "", "parser_id": "naive", "kb_id": kb_id}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 102, res
|
||||
assert res["message"] == "Duplicated dataset name.", res
|
||||
|
||||
@ -118,8 +118,8 @@ class TestDatasetUpdate:
|
||||
def test_name_case_insensitive(self, WebApiAuth, add_datasets_func):
|
||||
kb_id = add_datasets_func[0]
|
||||
name = "KB_1"
|
||||
payload = {"name": name, "description": "", "chunk_method": "naive"}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": name, "description": "", "parser_id": "naive", "kb_id": kb_id}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 102, res
|
||||
assert res["message"] == "Duplicated dataset name.", res
|
||||
|
||||
@ -130,18 +130,19 @@ class TestDatasetUpdate:
|
||||
payload = {
|
||||
"name": "avatar",
|
||||
"description": "",
|
||||
"chunk_method": "naive",
|
||||
"parser_id": "naive",
|
||||
"kb_id": kb_id,
|
||||
"avatar": f"data:image/png;base64,{encode_avatar(fn)}",
|
||||
}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["avatar"] == f"data:image/png;base64,{encode_avatar(fn)}", res
|
||||
|
||||
@pytest.mark.p2
|
||||
def test_description(self, WebApiAuth, add_dataset_func):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "description", "description": "description", "chunk_method": "naive"}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "description", "description": "description", "parser_id": "naive", "kb_id": kb_id}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["description"] == "description", res
|
||||
|
||||
@ -156,10 +157,10 @@ class TestDatasetUpdate:
|
||||
)
|
||||
def test_embedding_model(self, WebApiAuth, add_dataset_func, embedding_model):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "embedding_model", "description": "", "chunk_method": "naive", "embedding_model": embedding_model}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "embedding_model", "description": "", "parser_id": "naive", "kb_id": kb_id, "embd_id": embedding_model}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["embedding_model"] == embedding_model, res
|
||||
assert res["data"]["embd_id"] == embedding_model, res
|
||||
|
||||
@pytest.mark.p2
|
||||
@pytest.mark.parametrize(
|
||||
@ -172,8 +173,8 @@ class TestDatasetUpdate:
|
||||
)
|
||||
def test_permission(self, WebApiAuth, add_dataset_func, permission):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "permission", "description": "", "chunk_method": "naive", "permission": permission}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "permission", "description": "", "parser_id": "naive", "kb_id": kb_id, "permission": permission}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["permission"] == permission.lower().strip(), res
|
||||
|
||||
@ -198,17 +199,17 @@ class TestDatasetUpdate:
|
||||
)
|
||||
def test_chunk_method(self, WebApiAuth, add_dataset_func, chunk_method):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "chunk_method", "description": "", "chunk_method": chunk_method}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "chunk_method", "description": "", "parser_id": chunk_method, "kb_id": kb_id}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["chunk_method"] == chunk_method, res
|
||||
assert res["data"]["parser_id"] == chunk_method, res
|
||||
|
||||
@pytest.mark.p1
|
||||
@pytest.mark.skipif(os.getenv("DOC_ENGINE") != "infinity", reason="Infinity does not support parser_id=tag")
|
||||
def test_chunk_method_tag_with_infinity(self, WebApiAuth, add_dataset_func):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "chunk_method", "description": "", "chunk_method": "tag"}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "chunk_method", "description": "", "parser_id": "tag", "kb_id": kb_id}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 103, res
|
||||
assert res["message"] == "The chunking method Tag has not been supported by Infinity yet.", res
|
||||
|
||||
@ -217,8 +218,8 @@ class TestDatasetUpdate:
|
||||
@pytest.mark.parametrize("pagerank", [0, 50, 100], ids=["min", "mid", "max"])
|
||||
def test_pagerank(self, WebApiAuth, add_dataset_func, pagerank):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "pagerank", "description": "", "chunk_method": "naive", "pagerank": pagerank}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "pagerank", "description": "", "parser_id": "naive", "kb_id": kb_id, "pagerank": pagerank}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["pagerank"] == pagerank, res
|
||||
|
||||
@ -226,13 +227,13 @@ class TestDatasetUpdate:
|
||||
@pytest.mark.p2
|
||||
def test_pagerank_set_to_0(self, WebApiAuth, add_dataset_func):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "pagerank", "description": "", "chunk_method": "naive", "pagerank": 50}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "pagerank", "description": "", "parser_id": "naive", "kb_id": kb_id, "pagerank": 50}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["pagerank"] == 50, res
|
||||
|
||||
payload = {"name": "pagerank", "description": "", "chunk_method": "naive", "pagerank": 0}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "pagerank", "description": "", "parser_id": "naive", "kb_id": kb_id, "pagerank": 0}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
assert res["data"]["pagerank"] == 0, res
|
||||
|
||||
@ -240,8 +241,8 @@ class TestDatasetUpdate:
|
||||
@pytest.mark.p2
|
||||
def test_pagerank_infinity(self, WebApiAuth, add_dataset_func):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "pagerank", "description": "", "chunk_method": "naive", "pagerank": 50}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "pagerank", "description": "", "parser_id": "naive", "kb_id": kb_id, "pagerank": 50}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 102, res
|
||||
assert res["message"] == "'pagerank' can only be set when doc_engine is elasticsearch", res
|
||||
|
||||
@ -351,15 +352,10 @@ class TestDatasetUpdate:
|
||||
)
|
||||
def test_parser_config(self, WebApiAuth, add_dataset_func, parser_config):
|
||||
kb_id = add_dataset_func
|
||||
payload = {"name": "parser_config", "description": "", "chunk_method": "naive", "parser_config": parser_config}
|
||||
res = update_dataset(WebApiAuth, kb_id, payload)
|
||||
payload = {"name": "parser_config", "description": "", "parser_id": "naive", "kb_id": kb_id, "parser_config": parser_config}
|
||||
res = update_kb(WebApiAuth, payload)
|
||||
assert res["code"] == 0, res
|
||||
for key, value in parser_config.items():
|
||||
if not isinstance(value, dict):
|
||||
assert res["data"]["parser_config"].get(key) == value, res
|
||||
else:
|
||||
for sub_key, sub_value in value.items():
|
||||
assert res["data"]["parser_config"].get(key, {}).get(sub_key) == sub_value, res
|
||||
assert res["data"]["parser_config"] == parser_config, res
|
||||
|
||||
@pytest.mark.p2
|
||||
@pytest.mark.parametrize(
|
||||
@ -376,7 +372,7 @@ class TestDatasetUpdate:
|
||||
)
|
||||
def test_field_unsupported(self, WebApiAuth, add_dataset_func, payload):
|
||||
kb_id = add_dataset_func
|
||||
full_payload = {"name": "field_unsupported", "description": "", "chunk_method": "naive", **payload}
|
||||
res = update_dataset(WebApiAuth, kb_id, full_payload)
|
||||
full_payload = {"name": "field_unsupported", "description": "", "parser_id": "naive", "kb_id": kb_id, **payload}
|
||||
res = update_kb(WebApiAuth, full_payload)
|
||||
assert res["code"] == 101, res
|
||||
assert "are not permitted" in res["message"], res
|
||||
assert "isn't allowed" in res["message"], res
|
||||
|
||||
Reference in New Issue
Block a user