Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

test(sdk): audit dataset management tests (#21619)

Sbaaoui Idriss8f217778a39b
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/README.md b/test/testcases/test_sdk_api/test_dataset_mangement/README.md
new file mode 100644
index 0000000000..9d0e4a71d5
--- /dev/null
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/README.md
@@ -0,0 +1,68 @@
+<!--
+Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+# Dataset SDK tests
+
+Run from the repository root with Python 3.13 and the current SDK installed:
+
+```sh
+uv venv --python 3.13 /tmp/ragflow-sdk-tests
+uv pip install --python /tmp/ragflow-sdk-tests/bin/python -e sdk/python pytest
+/tmp/ragflow-sdk-tests/bin/python -m pytest test/testcases/test_sdk_api/test_dataset_mangement --collect-only
+/tmp/ragflow-sdk-tests/bin/python -m pytest test/testcases/test_sdk_api/test_dataset_mangement -m 'not integration'
+```
+
+The folder's `pytest.ini` keeps collection and mocked contracts independent of the
+legacy parent conftests, provider keys, backend setup, and priority filtering.
+For an explicit configuration path, use `-c test/testcases/test_sdk_api/test_dataset_mangement/pytest.ini`.
+Do not collect this folder together with unaudited SDK folders under the old parent configuration.
+
+Integration tests require a dedicated **Go** test deployment and an initially empty
+test tenant. Do not use a shared deployment or production credentials. Provision
+services and a default embedding model before running; the fixtures do not register
+users, configure providers, or change tenant defaults. Run serially, without xdist.
+
+Set these environment variables:
+
+- `RAGFLOW_SDK_ISOLATED=1`: confirms the deployment and tenant are dedicated to this run.
+- `RAGFLOW_SDK_BASE_URL`: the Go HTTP API base URL.
+- `RAGFLOW_SDK_API_KEY`: an owner API key for the empty test tenant.
+- `RAGFLOW_SDK_EMBEDDING_MODEL`: an accessible canonical `model@instance@provider` identifier for explicit model tests.
+- `RAGFLOW_SDK_PIPELINE_ID` and `RAGFLOW_SDK_PIPELINE_VERSION_ID`: an accessible ingestion pipeline and its published version for parser-mode update tests.
+- `RAGFLOW_SDK_DOC_ENGINE`: the configured document engine for pagerank capability tests.
+- `RAGFLOW_SDK_OTHER_API_KEY`: a valid key belonging to an unrelated test tenant for resource permission tests.
+
+```sh
+/tmp/ragflow-sdk-tests/bin/python -m pytest test/testcases/test_sdk_api/test_dataset_mangement -m 'integration and not p3'
+# Includes 1,000-dataset capacity and concurrent request scenarios:
+/tmp/ragflow-sdk-tests/bin/python -m pytest test/testcases/test_sdk_api/test_dataset_mangement -m integration
+```
+
+Missing environment requirements fail setup with a prerequisite message; they are
+not product-defect skips. Cleanup only deletes IDs returned by this test's creates,
+including successful creates before a later failure, and preserves unrelated IDs.
+No live test or fixture calls `delete_all=True`; its payload is checked with mocks.
+
+Four explicit skips preserve supported expectations blocked by confirmed source defects:
+
+- Create and update accept 128 BMP characters, but Go counts UTF-8 bytes in
+ `internal/service/dataset/crud.go` and `update.go`.
+- Pipeline creation is documented in the SDK, but `RAGFlow.create_dataset` cannot
+ send `pipeline_version_id`, which Go requires (`empty_version_test.go`).
+- Negative pagerank should report the lower bound; `update.go` reports the upper
+ bound for both range violations.
+
+The suite does not enable CI execution or change production implementations.
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/conftest.py b/test/testcases/test_sdk_api/test_dataset_mangement/conftest.py
index 998af94995..e66bd235dd 100644
--- a/test/testcases/test_sdk_api/test_dataset_mangement/conftest.py
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/conftest.py
@@ -1,5 +1,5 @@
#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,26 +14,89 @@
# limitations under the License.
#
+"""Dataset-only fixtures; never provision models or delete tenant-wide resources."""
+
+import os
+from uuid import uuid4
import pytest
-from common import batch_create_datasets, delete_all_datasets
+import requests
+from ragflow_sdk import RAGFlow
+
+
[email protected](autouse=True)
+def block_contract_network(request, monkeypatch):
+ if request.node.get_closest_marker("integration") is None:
+
+ def reject_request(*args, **kwargs):
+ pytest.fail("Service-free dataset tests must not open a network connection")
+
+ monkeypatch.setattr(requests.sessions.Session, "request", reject_request)
+
+
[email protected](scope="session")
+def integration_settings():
+ required = ("RAGFLOW_SDK_BASE_URL", "RAGFLOW_SDK_API_KEY")
+ if os.getenv("RAGFLOW_SDK_ISOLATED") != "1" or any(not os.getenv(key) for key in required):
+ pytest.fail(
+ "Integration environment required: set RAGFLOW_SDK_ISOLATED=1, "
+ "RAGFLOW_SDK_BASE_URL and RAGFLOW_SDK_API_KEY for a dedicated, empty Go test tenant. "
+ "Run service-free tests with -m 'not integration'."
+ )
+ settings = {
+ "base_url": os.environ["RAGFLOW_SDK_BASE_URL"],
+ "api_key": os.environ["RAGFLOW_SDK_API_KEY"],
+ "embedding_model": os.getenv("RAGFLOW_SDK_EMBEDDING_MODEL"),
+ "pipeline_id": os.getenv("RAGFLOW_SDK_PIPELINE_ID"),
+ "pipeline_version_id": os.getenv("RAGFLOW_SDK_PIPELINE_VERSION_ID"),
+ "doc_engine": os.getenv("RAGFLOW_SDK_DOC_ENGINE"),
+ "other_api_key": os.getenv("RAGFLOW_SDK_OTHER_API_KEY"),
+ }
+ probe = RAGFlow(settings["api_key"], settings["base_url"])
+ assert probe.list_datasets(page_size=1) == [], "Refusing integrations: test tenant is not empty"
+ return settings
+
+
+def client(integration_settings, monkeypatch):
+ rag = RAGFlow(integration_settings["api_key"], integration_settings["base_url"])
+ created = []
+ create = rag.create_dataset
+
+ def tracked_create(*args, **kwargs):
+ dataset = create(*args, **kwargs)
+ created.append(dataset.id)
+ return dataset
+
+ monkeypatch.setattr(rag, "create_dataset", tracked_create)
+ yield rag
+ # Tests may already have deleted some IDs; never fall back to delete_all.
+ for offset in range(0, len(created), 100):
+ ids = created[offset : offset + 100]
+ remaining = rag.list_datasets(ids=ids, page_size=100)
+ if remaining:
+ rag.delete_datasets(ids=[dataset.id for dataset in remaining])
+ assert rag.list_datasets(ids=ids, page_size=100) == [], "Test dataset cleanup failed"
+
+def dataset_factory(client):
+ def create(name=None, **kwargs):
+ return client.create_dataset(name=name if name is not None else f"sdk-dataset-{uuid4().hex}", **kwargs)
[email protected](scope="class")
-def add_datasets(client, request):
- def cleanup():
- delete_all_datasets(client)
+ return create
- request.addfinalizer(cleanup)
- return batch_create_datasets(client, 5)
+def add_dataset_func(dataset_factory):
+ return dataset_factory()
[email protected](scope="function")
-def add_datasets_func(client, request):
- def cleanup():
- delete_all_datasets(client)
+def add_datasets_func(dataset_factory):
+ return [dataset_factory() for _ in range(3)]
- request.addfinalizer(cleanup)
- return batch_create_datasets(client, 3)
+def add_datasets(dataset_factory):
+ return [dataset_factory() for _ in range(5)]
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/pytest.ini b/test/testcases/test_sdk_api/test_dataset_mangement/pytest.ini
new file mode 100644
index 0000000000..c545b1dc53
--- /dev/null
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/pytest.ini
@@ -0,0 +1,24 @@
+#
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+[pytest]
+pythonpath = ../../../../sdk/python
+addopts = --strict-markers
+markers =
+ integration: requires an explicitly isolated Go backend and dedicated empty tenant
+ p1: high priority
+ p2: medium priority
+ p3: low priority
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py
index 39de107137..1776174767 100644
--- a/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py
@@ -1,5 +1,5 @@
#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,690 +13,256 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-from concurrent.futures import ThreadPoolExecutor, as_completed
-from operator import attrgetter
+
+from concurrent.futures import ThreadPoolExecutor
+from uuid import uuid4
import pytest
-from configs import DATASET_NAME_LIMIT, DEFAULT_PARSER_CONFIG, HOST_ADDRESS, INVALID_API_TOKEN, IS_GO_PROXY, SDK_UNAUTHORIZED_ERROR_MESSAGE
-from hypothesis import example, given, settings
from ragflow_sdk import DataSet, RAGFlow
-from utils import encode_avatar
-from utils.file_utils import create_image_file
-from utils.hypothesis_utils import valid_names
-
-
[email protected]("clear_datasets")
-class TestAuthorization:
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "invalid_auth, expected_message",
- [
- (None, SDK_UNAUTHORIZED_ERROR_MESSAGE),
- (INVALID_API_TOKEN, SDK_UNAUTHORIZED_ERROR_MESSAGE),
- ],
- ids=["empty_auth", "invalid_api_token"],
- )
- def test_auth_invalid(self, invalid_auth, expected_message):
- client = RAGFlow(invalid_auth, HOST_ADDRESS)
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**{"name": "auth_test"})
- assert str(exception_info.value) == expected_message
-
-
[email protected]("clear_datasets")
-class TestCapability:
- @pytest.mark.p3
- def test_create_dataset_1k(self, client):
- count = 1_000
- for i in range(count):
- payload = {"name": f"dataset_{i}"}
- client.create_dataset(**payload)
- datasets = []
- for page in range(1, (count // 100) + 1):
- datasets.extend(client.list_datasets(page=page, page_size=100))
- assert len(datasets) == count
-
- @pytest.mark.p3
- def test_create_dataset_concurrent(self, client):
- count = 100
- with ThreadPoolExecutor(max_workers=5) as executor:
- futures = [executor.submit(client.create_dataset, **{"name": f"dataset_{i}"}) for i in range(100)]
- responses = list(as_completed(futures))
- assert len(responses) == count, responses
-
-
[email protected]("clear_datasets")
-class TestDatasetCreate:
- @pytest.mark.p1
- @given(name=valid_names())
- @example("a" * 128)
- @settings(max_examples=20)
- def test_name(self, client, name):
- dataset = client.create_dataset(**{"name": name})
- assert dataset.name == name, str(dataset)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, expected_message",
- [
- ("", "String should have at least 1 character"),
- (" ", "String should have at least 1 character"),
- ("a" * (DATASET_NAME_LIMIT + 1), "String should have at most 128 characters"),
- (0, "not instance of"),
- (None, "not instance of"),
- ],
- ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
- )
- def test_name_invalid(self, client, name, expected_message):
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**{"name": name})
- if IS_GO_PROXY:
- if name == "":
- expected_message = "failed on the 'required' tag"
- elif isinstance(name, str) and not name.strip():
- expected_message = "dataset name can't be empty"
- elif isinstance(name, str):
- expected_message = f"Dataset name length is {len(name)} which is large than {DATASET_NAME_LIMIT}"
- assert expected_message in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- def test_name_duplicated(self, client):
- name = "duplicated_name"
- payload = {"name": name}
- client.create_dataset(**payload)
-
- dataset = client.create_dataset(**payload)
- assert dataset.name == name + "(1)", str(dataset)
-
- @pytest.mark.p3
- def test_name_case_insensitive(self, client):
- name = "CaseInsensitive"
- payload = {"name": name.upper()}
- client.create_dataset(**payload)
-
- payload = {"name": name.lower()}
- dataset = client.create_dataset(**payload)
- assert dataset.name == name.lower() + "(1)", str(dataset)
-
- @pytest.mark.p2
- def test_avatar(self, client, tmp_path):
- fn = create_image_file(tmp_path / "ragflow_test.png")
- payload = {
- "name": "avatar",
- "avatar": f"data:image/png;base64,{encode_avatar(fn)}",
- }
- client.create_dataset(**payload)
-
- @pytest.mark.p3
- def test_avatar_exceeds_limit_length(self, client):
- payload = {"name": "avatar_exceeds_limit_length", "avatar": "a" * 65536}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- @pytest.mark.parametrize(
- "name, prefix, expected_message",
- [
- ("empty_prefix", "", "missing MIME prefix. Expected format: data:<mime>;base64,<data>"),
- ("missing_comma", "data:image/png;base64", "missing MIME prefix. Expected format: data:<mime>;base64,<data>"),
- ("unsupported_mine_type", "invalid_mine_prefix:image/png;base64,", "invalid MIME prefix format. Must start with 'data:'"),
- ("invalid_mine_type", "data:unsupported_mine_type;base64,", "Unsupported MIME type. Allowed: ['image/jpeg', 'image/png']"),
- ],
- ids=["empty_prefix", "missing_comma", "unsupported_mine_type", "invalid_mine_type"],
- )
- def test_avatar_invalid_prefix(self, client, tmp_path, name, prefix, expected_message):
- fn = create_image_file(tmp_path / "ragflow_test.png")
- payload = {
- "name": name,
- "avatar": f"{prefix}{encode_avatar(fn)}",
- }
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert expected_message in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- def test_avatar_unset(self, client):
- payload = {"name": "avatar_unset"}
- dataset = client.create_dataset(**payload)
- assert dataset.avatar is None, str(dataset)
-
- @pytest.mark.p2
- def test_description(self, client):
- payload = {"name": "description", "description": "description"}
- dataset = client.create_dataset(**payload)
- assert dataset.description == "description", str(dataset)
-
- @pytest.mark.p3
- def test_description_exceeds_limit_length(self, client):
- payload = {"name": "description_exceeds_limit_length", "description": "a" * 65536}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- def test_description_unset(self, client):
- payload = {"name": "description_unset"}
- dataset = client.create_dataset(**payload)
- assert dataset.description is None, str(dataset)
-
- @pytest.mark.p3
- def test_description_none(self, client):
- payload = {"name": "description_none", "description": None}
- dataset = client.create_dataset(**payload)
- assert dataset.description is None, str(dataset)
-
- @pytest.mark.p1
- @pytest.mark.parametrize(
- "name, embedding_model",
- [
- ("BAAI/bge-small-en-v1.5@Builtin", "BAAI/bge-small-en-v1.5@Builtin"),
- ("embedding-3@ZHIPU-AI", "embedding-3@CI@ZHIPU-AI"),
- ],
- ids=["builtin_baai", "tenant_zhipu"],
- )
- def test_embedding_model(self, client, name, embedding_model):
- payload = {"name": name, "embedding_model": embedding_model}
- dataset = client.create_dataset(**payload)
- assert dataset.embedding_model == embedding_model, str(dataset)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, embedding_model",
- [
- ("unknown_llm_name", "unknown@CI@ZHIPU-AI"),
- ("unknown_llm_factory", "embedding-3@unknown"),
- ("tenant_no_auth_default_tenant_llm", "text-embedding-v3@Tongyi-Qianwen"),
- ("tenant_no_auth", "text-embedding-3-small@OpenAI"),
- ],
- ids=["unknown_llm_name", "unknown_llm_factory", "tenant_no_auth_default_tenant_llm", "tenant_no_auth"],
- )
- def test_embedding_model_invalid(self, client, name, embedding_model):
- payload = {"name": name, "embedding_model": embedding_model}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert "not found" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, embedding_model",
- [
- ("empty", ""),
- ("space", " "),
- ("missing_at", "BAAI/bge-small-en-v1.5Builtin"),
- ("missing_model_name", "@Builtin"),
- ("missing_provider", "BAAI/bge-small-en-v1.5@"),
- ("whitespace_only_model_name", " @Builtin"),
- ("whitespace_only_provider", "BAAI/bge-small-en-v1.5@ "),
- ],
- ids=["empty", "space", "missing_at", "empty_model_name", "empty_provider", "whitespace_only_model_name", "whitespace_only_provider"],
- )
- def test_embedding_model_format(self, client, name, embedding_model):
- payload = {"name": name, "embedding_model": embedding_model}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- if name in ["empty", "space", "missing_at"]:
- assert "embedding model identifier must follow <model_name>@<provider> format" in str(exception_info.value), str(exception_info.value)
- else:
- assert "both model_name and provider must be non-empty strings" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- def test_embedding_model_unset(self, client):
- payload = {"name": "embedding_model_unset"}
- dataset = client.create_dataset(**payload)
- assert dataset.embedding_model.startswith("BAAI/bge-small-en-v1.5@Local@Builtin") if IS_GO_PROXY else dataset.embedding_model == "BAAI/bge-small-en-v1.5@Local@Builtin", str(dataset)
-
- @pytest.mark.p2
- def test_embedding_model_none(self, client):
- payload = {"name": "embedding_model_none", "embedding_model": None}
- dataset = client.create_dataset(**payload)
- assert dataset.embedding_model.startswith("BAAI/bge-small-en-v1.5@Local@Builtin") if IS_GO_PROXY else dataset.embedding_model == "BAAI/bge-small-en-v1.5@Local@Builtin", str(dataset)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, permission",
- [
- ("me", "me"),
- ("team", "team"),
- ],
- ids=["me", "team"],
- )
- def test_permission(self, client, name, permission):
- payload = {"name": name, "permission": permission}
- dataset = client.create_dataset(**payload)
- assert dataset.permission == permission.lower().strip(), str(dataset)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, permission",
- [
- ("empty", ""),
- ("unknown", "unknown"),
- ("me_upercase", "ME"),
- ("team_upercase", "TEAM"),
- ("whitespace", " ME "),
- ],
- ids=["empty", "unknown", "me_upercase", "team_upercase", "whitespace"],
- )
- def test_permission_invalid(self, client, name, permission):
- payload = {"name": name, "permission": permission}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert "Input should be 'me' or 'team'" in str(exception_info.value)
-
- @pytest.mark.p2
- def test_permission_unset(self, client):
- payload = {"name": "permission_unset"}
- dataset = client.create_dataset(**payload)
- assert dataset.permission == "me", str(dataset)
-
- @pytest.mark.p3
- def test_permission_none(self, client):
- payload = {"name": "permission_none", "permission": None}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert "not instance of" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p1
- @pytest.mark.parametrize(
- "name, chunk_method",
- [
- ("naive", "naive"),
- ("book", "book"),
- ("email", "email"),
- ("laws", "laws"),
- ("manual", "manual"),
- ("one", "one"),
- ("paper", "paper"),
- ("picture", "picture"),
- ("presentation", "presentation"),
- ("qa", "qa"),
- ("table", "table"),
- ("tag", "tag"),
- ("resume", "resume"),
- ],
- ids=["naive", "book", "email", "laws", "manual", "one", "paper", "picture", "presentation", "qa", "table", "tag", "resume"],
- )
- def test_chunk_method(self, client, name, chunk_method):
- payload = {"name": name, "chunk_method": chunk_method}
- dataset = client.create_dataset(**payload)
- assert dataset.chunk_method == chunk_method, str(dataset)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, chunk_method",
- [
- ("empty", ""),
- ("unknown", "unknown"),
- ],
- ids=["empty", "unknown"],
- )
- def test_chunk_method_invalid(self, client, name, chunk_method):
- payload = {"name": name, "chunk_method": chunk_method}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- error_message = str(exception_info.value)
- if IS_GO_PROXY:
- assert error_message.startswith("Input should be 'naive', 'book'") and error_message.endswith("or 'tag'"), error_message
- else:
- assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'" in error_message, error_message
-
- @pytest.mark.p2
- def test_chunk_method_unset(self, client):
- payload = {"name": "chunk_method_unset"}
- dataset = client.create_dataset(**payload)
- assert dataset.chunk_method == "naive", str(dataset)
-
- @pytest.mark.p3
- def test_chunk_method_none(self, client):
- payload = {"name": "chunk_method_none", "chunk_method": None}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert "not instance of" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p1
- @pytest.mark.parametrize(
- "name, parser_config",
- [
- ("auto_keywords_min", {"auto_keywords": 0}),
- ("auto_keywords_mid", {"auto_keywords": 16}),
- ("auto_keywords_max", {"auto_keywords": 32}),
- ("auto_questions_min", {"auto_questions": 0}),
- ("auto_questions_mid", {"auto_questions": 5}),
- ("auto_questions_max", {"auto_questions": 10}),
- ("chunk_token_num_min", {"chunk_token_num": 1}),
- ("chunk_token_num_mid", {"chunk_token_num": 1024}),
- ("chunk_token_num_max", {"chunk_token_num": 2048}),
- ("delimiter", {"delimiter": "\n"}),
- ("delimiter_space", {"delimiter": " "}),
- ("html4excel_true", {"html4excel": True}),
- ("html4excel_false", {"html4excel": False}),
- ("layout_recognize_DeepDOC", {"layout_recognize": "DeepDOC"}),
- ("layout_recognize_navie", {"layout_recognize": "Plain Text"}),
- ("tag_kb_ids", {"tag_kb_ids": ["1", "2"]}),
- ("topn_tags_min", {"topn_tags": 1}),
- ("topn_tags_mid", {"topn_tags": 5}),
- ("topn_tags_max", {"topn_tags": 10}),
- ("filename_embd_weight_min", {"filename_embd_weight": 0.1}),
- ("filename_embd_weight_mid", {"filename_embd_weight": 0.5}),
- ("filename_embd_weight_max", {"filename_embd_weight": 1.0}),
- ("task_page_size_min", {"task_page_size": 1}),
- ("task_page_size_None", {"task_page_size": None}),
- ("pages", {"pages": [[1, 100]]}),
- ("pages_none", {"pages": None}),
- ("graphrag_true", {"graphrag": {"use_graphrag": True}}),
- ("graphrag_false", {"graphrag": {"use_graphrag": False}}),
- ("graphrag_entity_types", {"graphrag": {"entity_types": ["age", "sex", "height", "weight"]}}),
- ("graphrag_method_general", {"graphrag": {"method": "general"}}),
- ("graphrag_method_light", {"graphrag": {"method": "light"}}),
- ("graphrag_community_true", {"graphrag": {"community": True}}),
- ("graphrag_community_false", {"graphrag": {"community": False}}),
- ("graphrag_resolution_true", {"graphrag": {"resolution": True}}),
- ("graphrag_resolution_false", {"graphrag": {"resolution": False}}),
- ("raptor_true", {"raptor": {"use_raptor": True}}),
- ("raptor_false", {"raptor": {"use_raptor": False}}),
- ("raptor_prompt", {"raptor": {"prompt": "Who are you?"}}),
- ("raptor_max_token_min", {"raptor": {"max_token": 512}}),
- ("raptor_max_token_mid", {"raptor": {"max_token": 1024}}),
- ("raptor_max_token_max", {"raptor": {"max_token": 2048}}),
- ("raptor_clustering_threshold_min", {"raptor": {"clustering_threshold": 0.0}}),
- ("raptor_clustering_threshold_mid", {"raptor": {"clustering_threshold": 0.5}}),
- ("raptor_clustering_threshold_max", {"raptor": {"clustering_threshold": 1.0}}),
- ("raptor_max_cluster_min", {"raptor": {"max_cluster": 1}}),
- ("raptor_max_cluster_mid", {"raptor": {"max_cluster": 512}}),
- ("raptor_max_cluster_max", {"raptor": {"max_cluster": 1024}}),
- ("raptor_random_seed_min", {"raptor": {"random_seed": 0}}),
- ],
- ids=[
- "auto_keywords_min",
- "auto_keywords_mid",
- "auto_keywords_max",
- "auto_questions_min",
- "auto_questions_mid",
- "auto_questions_max",
- "chunk_token_num_min",
- "chunk_token_num_mid",
- "chunk_token_num_max",
- "delimiter",
- "delimiter_space",
- "html4excel_true",
- "html4excel_false",
- "layout_recognize_DeepDOC",
- "layout_recognize_navie",
- "tag_kb_ids",
- "topn_tags_min",
- "topn_tags_mid",
- "topn_tags_max",
- "filename_embd_weight_min",
- "filename_embd_weight_mid",
- "filename_embd_weight_max",
- "task_page_size_min",
- "task_page_size_None",
- "pages",
- "pages_none",
- "graphrag_true",
- "graphrag_false",
- "graphrag_entity_types",
- "graphrag_method_general",
- "graphrag_method_light",
- "graphrag_community_true",
- "graphrag_community_false",
- "graphrag_resolution_true",
- "graphrag_resolution_false",
- "raptor_true",
- "raptor_false",
- "raptor_prompt",
- "raptor_max_token_min",
- "raptor_max_token_mid",
- "raptor_max_token_max",
- "raptor_clustering_threshold_min",
- "raptor_clustering_threshold_mid",
- "raptor_clustering_threshold_max",
- "raptor_max_cluster_min",
- "raptor_max_cluster_mid",
- "raptor_max_cluster_max",
- "raptor_random_seed_min",
- ],
- )
- def test_parser_config(self, client, name, parser_config):
- parser_config_o = DataSet.ParserConfig(client, parser_config)
- payload = {"name": name, "parser_config": parser_config_o}
- dataset = client.create_dataset(**payload)
- for k, v in parser_config.items():
- if k in {"graphrag", "raptor"}:
- assert not hasattr(dataset.parser_config, k), str(dataset)
- continue
- if isinstance(v, dict):
- for kk, vv in v.items():
- assert attrgetter(f"{k}.{kk}")(dataset.parser_config) == vv, str(dataset)
- else:
- assert attrgetter(k)(dataset.parser_config) == v, str(dataset)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, parser_config, expected_message",
- [
- ("auto_keywords_min_limit", {"auto_keywords": -1}, "Input should be greater than or equal to 0"),
- ("auto_keywords_max_limit", {"auto_keywords": 33}, "Input should be less than or equal to 32"),
- ("auto_keywords_float_not_allowed", {"auto_keywords": 3.14}, "Input should be a valid integer"),
- ("auto_keywords_type_invalid", {"auto_keywords": "string"}, "Input should be a valid integer"),
- ("auto_questions_min_limit", {"auto_questions": -1}, "Input should be greater than or equal to 0"),
- ("auto_questions_max_limit", {"auto_questions": 11}, "Input should be less than or equal to 10"),
- ("auto_questions_float_not_allowed", {"auto_questions": 3.14}, "Input should be a valid integer"),
- ("auto_questions_type_invalid", {"auto_questions": "string"}, "Input should be a valid integer"),
- ("chunk_token_num_min_limit", {"chunk_token_num": 0}, "Input should be greater than or equal to 1"),
- ("chunk_token_num_max_limit", {"chunk_token_num": 2049}, "Input should be less than or equal to 2048"),
- ("chunk_token_num_float_not_allowed", {"chunk_token_num": 3.14}, "Input should be a valid integer"),
- ("chunk_token_num_type_invalid", {"chunk_token_num": "string"}, "Input should be a valid integer"),
- ("delimiter_empty", {"delimiter": ""}, "String should have at least 1 character"),
- ("html4excel_type_invalid", {"html4excel": "string"}, "Input should be a valid boolean"),
- ("tag_kb_ids_not_list", {"tag_kb_ids": "1,2"}, "Input should be a valid list"),
- ("tag_kb_ids_int_in_list", {"tag_kb_ids": [1, 2]}, "Input should be a valid string"),
- ("topn_tags_min_limit", {"topn_tags": 0}, "Input should be greater than or equal to 1"),
- ("topn_tags_max_limit", {"topn_tags": 11}, "Input should be less than or equal to 10"),
- ("topn_tags_float_not_allowed", {"topn_tags": 3.14}, "Input should be a valid integer"),
- ("topn_tags_type_invalid", {"topn_tags": "string"}, "Input should be a valid integer"),
- ("filename_embd_weight_min_limit", {"filename_embd_weight": -1}, "Input should be greater than or equal to 0"),
- ("filename_embd_weight_max_limit", {"filename_embd_weight": 1.1}, "Input should be less than or equal to 1"),
- ("filename_embd_weight_type_invalid", {"filename_embd_weight": "string"}, "Input should be a valid number"),
- ("task_page_size_min_limit", {"task_page_size": 0}, "Input should be greater than or equal to 1"),
- ("task_page_size_float_not_allowed", {"task_page_size": 3.14}, "Input should be a valid integer"),
- ("task_page_size_type_invalid", {"task_page_size": "string"}, "Input should be a valid integer"),
- ("pages_not_list", {"pages": "1,2"}, "Input should be a valid list"),
- ("pages_not_list_in_list", {"pages": ["1,2"]}, "Input should be a valid list"),
- ("pages_not_int_list", {"pages": [["string1", "string2"]]}, "Input should be a valid integer"),
- ("graphrag_type_invalid", {"graphrag": {"use_graphrag": "string"}}, "Input should be a valid boolean"),
- ("graphrag_entity_types_not_list", {"graphrag": {"entity_types": "1,2"}}, "Input should be a valid list"),
- ("graphrag_entity_types_not_str_in_list", {"graphrag": {"entity_types": [1, 2]}}, "nput should be a valid string"),
- ("graphrag_method_unknown", {"graphrag": {"method": "unknown"}}, "Input should be 'light', 'general' or 'ner'"),
- ("graphrag_method_none", {"graphrag": {"method": None}}, "Input should be 'light', 'general' or 'ner'"),
- ("graphrag_community_type_invalid", {"graphrag": {"community": "string"}}, "Input should be a valid boolean"),
- ("graphrag_resolution_type_invalid", {"graphrag": {"resolution": "string"}}, "Input should be a valid boolean"),
- ("raptor_type_invalid", {"raptor": {"use_raptor": "string"}}, "Input should be a valid boolean"),
- ("raptor_prompt_empty", {"raptor": {"prompt": ""}}, "String should have at least 1 character"),
- ("raptor_prompt_space", {"raptor": {"prompt": " "}}, "String should have at least 1 character"),
- ("raptor_max_token_max_limit", {"raptor": {"max_token": 2049}}, "Input should be less than or equal to 2048"),
- ("raptor_max_token_type_invalid", {"raptor": {"max_token": "string"}}, "Input should be a valid integer"),
- ("raptor_clustering_threshold_min_limit", {"raptor": {"clustering_threshold": -0.1}}, "Input should be greater than or equal to 0"),
- ("raptor_clustering_threshold_max_limit", {"raptor": {"clustering_threshold": 1.1}}, "Input should be less than or equal to 1"),
- ("raptor_clustering_threshold_type_invalid", {"raptor": {"clustering_threshold": "string"}}, "Input should be a valid number"),
- ("raptor_max_cluster_min_limit", {"raptor": {"max_cluster": 0}}, "Input should be greater than or equal to 1"),
- ("raptor_max_cluster_max_limit", {"raptor": {"max_cluster": 1025}}, "Input should be less than or equal to 1024"),
- ("raptor_max_cluster_float_not_allowed", {"raptor": {"max_cluster": 3.14}}, "Input should be a valid integer"),
- ("raptor_max_cluster_type_invalid", {"raptor": {"max_cluster": "string"}}, "Input should be a valid integer"),
- ("raptor_random_seed_min_limit", {"raptor": {"random_seed": -1}}, "Input should be greater than or equal to 0"),
- ("raptor_random_seed_float_not_allowed", {"raptor": {"random_seed": 3.14}}, "Input should be a valid integer"),
- ("raptor_random_seed_type_invalid", {"raptor": {"random_seed": "string"}}, "Input should be a valid integer"),
- ("parser_config_type_invalid", {"delimiter": "a" * 65536}, "Parser config exceeds size limit (max 65,535 characters)"),
- ],
- ids=[
- "auto_keywords_min_limit",
- "auto_keywords_max_limit",
- "auto_keywords_float_not_allowed",
- "auto_keywords_type_invalid",
- "auto_questions_min_limit",
- "auto_questions_max_limit",
- "auto_questions_float_not_allowed",
- "auto_questions_type_invalid",
- "chunk_token_num_min_limit",
- "chunk_token_num_max_limit",
- "chunk_token_num_float_not_allowed",
- "chunk_token_num_type_invalid",
- "delimiter_empty",
- "html4excel_type_invalid",
- "tag_kb_ids_not_list",
- "tag_kb_ids_int_in_list",
- "topn_tags_min_limit",
- "topn_tags_max_limit",
- "topn_tags_float_not_allowed",
- "topn_tags_type_invalid",
- "filename_embd_weight_min_limit",
- "filename_embd_weight_max_limit",
- "filename_embd_weight_type_invalid",
- "task_page_size_min_limit",
- "task_page_size_float_not_allowed",
- "task_page_size_type_invalid",
- "pages_not_list",
- "pages_not_list_in_list",
- "pages_not_int_list",
- "graphrag_type_invalid",
- "graphrag_entity_types_not_list",
- "graphrag_entity_types_not_str_in_list",
- "graphrag_method_unknown",
- "graphrag_method_none",
- "graphrag_community_type_invalid",
- "graphrag_resolution_type_invalid",
- "raptor_type_invalid",
- "raptor_prompt_empty",
- "raptor_prompt_space",
- "raptor_max_token_max_limit",
- "raptor_max_token_type_invalid",
- "raptor_clustering_threshold_min_limit",
- "raptor_clustering_threshold_max_limit",
- "raptor_clustering_threshold_type_invalid",
- "raptor_max_cluster_min_limit",
- "raptor_max_cluster_max_limit",
- "raptor_max_cluster_float_not_allowed",
- "raptor_max_cluster_type_invalid",
- "raptor_random_seed_min_limit",
- "raptor_random_seed_float_not_allowed",
- "raptor_random_seed_type_invalid",
- "parser_config_type_invalid",
- ],
- )
- def test_parser_config_invalid(self, client, name, parser_config, expected_message):
- parser_config_o = DataSet.ParserConfig(client, parser_config)
- payload = {"name": name, "parser_config": parser_config_o}
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert expected_message in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- def test_parser_config_empty(self, client):
- excepted_value = DataSet.ParserConfig(
- client,
- DEFAULT_PARSER_CONFIG,
- )
- parser_config_o = DataSet.ParserConfig(client, {})
- payload = {"name": "parser_config_empty", "parser_config": parser_config_o}
- dataset = client.create_dataset(**payload)
- assert str(dataset.parser_config) == str(excepted_value), str(dataset)
-
- @pytest.mark.p2
- def test_parser_config_unset(self, client):
- excepted_value = DataSet.ParserConfig(
- client,
- DEFAULT_PARSER_CONFIG,
- )
- payload = {"name": "parser_config_unset"}
- dataset = client.create_dataset(**payload)
- assert str(dataset.parser_config) == str(excepted_value), str(dataset)
-
- @pytest.mark.p3
- def test_parser_config_none(self, client):
- excepted_value = DataSet.ParserConfig(
- client,
- DEFAULT_PARSER_CONFIG,
- )
- payload = {"name": "parser_config_empty", "parser_config": None}
- dataset = client.create_dataset(**payload)
- assert str(dataset.parser_config) == str(excepted_value), str(dataset)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "payload",
- [
- {"name": "id", "id": "id"},
- {"name": "tenant_id", "tenant_id": "e57c1966f99211efb41e9e45646e0111"},
- {"name": "created_by", "created_by": "created_by"},
- {"name": "create_date", "create_date": "Tue, 11 Mar 2025 13:37:23 GMT"},
- {"name": "create_time", "create_time": 1741671443322},
- {"name": "update_date", "update_date": "Tue, 11 Mar 2025 13:37:23 GMT"},
- {"name": "update_time", "update_time": 1741671443339},
- {"name": "document_count", "document_count": 1},
- {"name": "chunk_count", "chunk_count": 1},
- {"name": "token_num", "token_num": 1},
- {"name": "status", "status": "1"},
- {"name": "pagerank", "pagerank": 50},
- {"name": "unknown_field", "unknown_field": "unknown_field"},
- ],
- )
- def test_unsupported_field(self, client, payload):
- with pytest.raises(Exception) as exception_info:
- client.create_dataset(**payload)
- assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value)
-
-
[email protected]("clear_datasets")
-class TestParserConfigBugFix:
- @pytest.mark.p1
- def test_parser_config_missing_raptor_and_graphrag(self, client):
- parser_config = DataSet.ParserConfig(client, {"chunk_token_num": 1024})
- payload = {"name": "test_parser_config_missing_fields_sdk", "parser_config": parser_config}
- dataset = client.create_dataset(**payload)
-
- config = dataset.parser_config
- assert not hasattr(config, "raptor"), "raptor field should not be exposed"
- assert not hasattr(config, "graphrag"), "graphrag field should not be exposed"
- assert config.chunk_token_num == 1024, "User-provided chunk_token_num should be preserved"
-
- @pytest.mark.p1
- def test_parser_config_with_only_raptor(self, client):
- parser_config = DataSet.ParserConfig(client, {"chunk_token_num": 1024, "raptor": {"use_raptor": True}})
- payload = {"name": "test_parser_config_only_raptor_sdk", "parser_config": parser_config}
- dataset = client.create_dataset(**payload)
-
- config = dataset.parser_config
- assert not hasattr(config, "raptor"), "raptor field should not be exposed"
- assert not hasattr(config, "graphrag"), "graphrag field should not be exposed"
-
- @pytest.mark.p1
- def test_parser_config_with_only_graphrag(self, client):
- parser_config = DataSet.ParserConfig(client, {"chunk_token_num": 1024, "graphrag": {"use_graphrag": True}})
- payload = {"name": "test_parser_config_only_graphrag_sdk", "parser_config": parser_config}
- dataset = client.create_dataset(**payload)
-
- config = dataset.parser_config
- assert not hasattr(config, "raptor"), "raptor field should not be exposed"
- assert not hasattr(config, "graphrag"), "graphrag field should not be exposed"
-
- @pytest.mark.p1
- def test_parser_config_with_both_fields(self, client):
- parser_config = DataSet.ParserConfig(client, {"chunk_token_num": 1024, "raptor": {"use_raptor": True}, "graphrag": {"use_graphrag": True}})
- payload = {"name": "test_parser_config_both_fields_sdk", "parser_config": parser_config}
- dataset = client.create_dataset(**payload)
-
- config = dataset.parser_config
- assert not hasattr(config, "raptor"), "raptor field should not be exposed"
- assert not hasattr(config, "graphrag"), "graphrag field should not be exposed"
-
- @pytest.mark.p2
- @pytest.mark.parametrize("chunk_method", ["qa", "manual", "paper", "book", "laws", "presentation"])
- def test_parser_config_different_chunk_methods(self, client, chunk_method):
- parser_config = DataSet.ParserConfig(client, {"chunk_token_num": 512})
- payload = {"name": f"test_parser_config_{chunk_method}_sdk", "chunk_method": chunk_method, "parser_config": parser_config}
- dataset = client.create_dataset(**payload)
-
- config = dataset.parser_config
- assert not hasattr(config, "raptor"), f"raptor field should not be exposed for {chunk_method}"
- assert not hasattr(config, "graphrag"), f"graphrag field should not be exposed for {chunk_method}"
+
+pytestmark = pytest.mark.integration
+
+
[email protected]("api_key", [None, "not-a-valid-sdk-token"])
+def test_auth_invalid(integration_settings, api_key):
+ unauthorized = RAGFlow(api_key, integration_settings["base_url"])
+ with pytest.raises(Exception, match="Invalid access token"):
+ unauthorized.create_dataset(name="unauthorized-dataset")
+
+
[email protected]("name", ["a", "a" * 128, "dataset with spaces", "数据集", "name-with_符号"])
+def test_name(dataset_factory, client, name):
+ dataset = dataset_factory(name=name)
+ assert dataset.name == name
+ persisted = client.list_datasets(id=dataset.id)
+ assert len(persisted) == 1
+ assert persisted[0].name == name
+
+
[email protected](reason="internal/service/dataset/crud.go CreateDataset uses len(name) bytes despite the documented 128-character limit")
+def test_name_unicode_limit(dataset_factory):
+ name = "数" * 128
+ assert dataset_factory(name=name).name == name
+
+
+ "name,message",
+ [
+ ("", "required"),
+ (" ", "dataset name can't be empty"),
+ ("a" * 129, "large than 128"),
+ ],
+)
+def test_name_invalid(client, name, message):
+ with pytest.raises(Exception, match=message):
+ client.create_dataset(name=name)
+
+
[email protected]("case_sensitive", [True, False], ids=["duplicate", "case-insensitive"])
+def test_name_duplicated(dataset_factory, client, case_sensitive):
+ name = "SdkDuplicate" + uuid4().hex
+ first = dataset_factory(name=name)
+ requested = name if case_sensitive else name.lower()
+ second = dataset_factory(name=requested)
+ assert first.name == name
+ assert second.name == requested + "(1)"
+ assert first.id != second.id
+ assert client.list_datasets(id=second.id)[0].name == second.name
+
+
+def test_create_dataset_1k(dataset_factory, client):
+ created = {dataset_factory().id for _ in range(1000)}
+ found = set()
+ page = 1
+ while True:
+ datasets = client.list_datasets(page=page, page_size=100)
+ found.update(dataset.id for dataset in datasets)
+ if len(datasets) < 100:
+ break
+ page += 1
+ assert created <= found
+
+
+def test_create_dataset_concurrent(dataset_factory, client):
+ with ThreadPoolExecutor(max_workers=5) as executor:
+ futures = [executor.submit(dataset_factory) for _ in range(100)]
+ datasets = [future.result() for future in futures]
+ assert len({dataset.id for dataset in datasets}) == 100
+ for dataset in datasets:
+ assert client.list_datasets(id=dataset.id)[0].name == dataset.name
+
+
+def test_embedding_model(dataset_factory, integration_settings, client):
+ model = integration_settings.get("embedding_model")
+ if not model:
+ pytest.fail("RAGFLOW_SDK_EMBEDDING_MODEL must identify an accessible embedding model")
+ dataset = dataset_factory(embedding_model=model)
+ assert dataset.embedding_model == model
+ assert client.list_datasets(id=dataset.id)[0].embedding_model == model
+
+
[email protected]("embedding_model", ["missing-model@MissingProvider", "0123456789abcdef0123456789abcdef"])
+def test_embedding_model_invalid(client, embedding_model):
+ with pytest.raises(Exception, match="(?i)not found|does not exist|unavailable|not authorized|no permission"):
+ client.create_dataset(name="invalid-embedding", embedding_model=embedding_model)
+
+
+ "embedding_model,message",
+ [
+ ("", "must follow"),
+ (" ", "must follow"),
+ ("model-without-provider", "must follow"),
+ ("@Builtin", "must be non-empty"),
+ ("model@", "must be non-empty"),
+ (" @Builtin", "must be non-empty"),
+ ("model@ ", "must be non-empty"),
+ ],
+)
+def test_embedding_model_format(client, embedding_model, message):
+ with pytest.raises(Exception, match=message):
+ client.create_dataset(name="invalid-model-format", embedding_model=embedding_model)
+
+
[email protected]("kwargs", [{}, {"embedding_model": None}], ids=["unset", "none"])
+def test_embedding_model_default(dataset_factory, client, kwargs):
+ dataset = dataset_factory(**kwargs)
+ reference = dataset_factory()
+ assert dataset.embedding_model
+ assert dataset.embedding_model == reference.embedding_model
+ persisted = client.list_datasets(id=dataset.id)[0]
+ assert persisted.embedding_model == client.list_datasets(id=reference.id)[0].embedding_model
+
+
[email protected]("permission", ["me", "team"])
+def test_permission(dataset_factory, client, permission):
+ dataset = dataset_factory(permission=permission)
+ assert dataset.permission == permission
+ assert client.list_datasets(id=dataset.id)[0].permission == permission
+
+
[email protected]("permission", ["", "unknown", "ME", "TEAM"])
+def test_permission_invalid(client, permission):
+ with pytest.raises(Exception, match="Input should be 'me' or 'team'"):
+ client.create_dataset(name="invalid-permission", permission=permission)
+
+
+def test_permission_unset(dataset_factory):
+ assert dataset_factory().permission == "me"
+
+
[email protected]("permission", [" me ", " team "])
+def test_permission_normalized(dataset_factory, permission):
+ assert dataset_factory(permission=permission).permission == permission.strip()
+
+
[email protected]("language", ["English", " 中文 ", "a" * 32])
+def test_language(dataset_factory, client, language):
+ dataset = dataset_factory(language=language)
+ assert dataset.language == language.strip()
+ assert client.list_datasets(id=dataset.id)[0].language == language.strip()
+
+
[email protected]("language,message", [("", "at least 1"), (" ", "at least 1"), ("a" * 33, "at most 32")])
+def test_language_invalid(client, language, message):
+ with pytest.raises(Exception, match=message):
+ client.create_dataset(name="invalid-language", language=language)
+
+
[email protected]("parser_id", ["general", "book", "email", "laws", "manual", "one", "paper", "picture", "presentation", "qa", "table", "audio"])
+def test_builtin_parser(dataset_factory, client, parser_id):
+ dataset = dataset_factory(parse_type=1, parser_id=parser_id)
+ assert dataset.parser_id == parser_id
+ assert dataset.parse_type == 1
+ assert dataset.pipeline_id is None
+ persisted = client.list_datasets(id=dataset.id)[0]
+ assert persisted.parser_id == parser_id
+ assert persisted.pipeline_id is None
+
+
+def test_builtin_parser_invalid(client):
+ with pytest.raises(Exception, match="input should be"):
+ client.create_dataset(name="invalid-parser", parser_id="unknown")
+
+
+def test_builtin_parser_default(dataset_factory):
+ dataset = dataset_factory()
+ assert dataset.parser_id == "general"
+ assert dataset.parse_type == 1
+ assert dataset.pipeline_id is None
+
+
[email protected](reason="sdk/python/ragflow_sdk/ragflow.py create_dataset cannot send pipeline_version_id required by internal/service/dataset/crud.go CreateDataset (empty_version_test.go)")
+def test_pipeline_parser(dataset_factory, client, integration_settings):
+ pipeline_id = integration_settings.get("pipeline_id")
+ if not pipeline_id:
+ pytest.fail("RAGFLOW_SDK_PIPELINE_ID must identify an accessible versioned ingestion pipeline")
+ dataset = dataset_factory(parse_type=2, pipeline_id=pipeline_id)
+ assert dataset.pipeline_id == pipeline_id
+ assert dataset.parse_type == 2
+ persisted = client.list_datasets(id=dataset.id)[0]
+ assert persisted.pipeline_id == pipeline_id
+ assert persisted.parse_type == 2
+
+
[email protected]("chunk_token_size", [1, 256, 1024, 2048])
+def test_parser_config(dataset_factory, client, chunk_token_size):
+ config = {"GeneralChunker:SixApplesFall": {"chunk_token_size": chunk_token_size}}
+ dataset = dataset_factory(parser_config=DataSet.ParserConfig(client, config))
+ assert dataset.parser_config.to_json()["GeneralChunker:SixApplesFall"]["chunk_token_size"] == chunk_token_size
+ persisted = client.list_datasets(id=dataset.id)[0]
+ assert persisted.parser_config.to_json()["GeneralChunker:SixApplesFall"]["chunk_token_size"] == chunk_token_size
+
+
+def test_parser_config_parent_child(dataset_factory, client):
+ config = {"GeneralChunker:SixApplesFall": {"parent_child": {"use_parent_child": True, "children_delimiter": "|"}}}
+ dataset = dataset_factory(parser_config=DataSet.ParserConfig(client, config))
+ for result in (dataset, client.list_datasets(id=dataset.id)[0]):
+ chunker = result.parser_config.to_json()["GeneralChunker:SixApplesFall"]
+ assert chunker["parent_child"] == config["GeneralChunker:SixApplesFall"]["parent_child"]
+ assert chunker["children_delimiters"] == ["|"]
+
+
+def test_parser_config_size(client):
+ config = DataSet.ParserConfig(client, {"GeneralChunker:SixApplesFall": {"delimiter": "a" * 65536}})
+ with pytest.raises(Exception, match="Parser config exceeds size limit"):
+ client.create_dataset(name="oversized-config", parser_config=config)
+
+
[email protected]("config", [None, {}], ids=["none", "empty"])
+def test_parser_config_default(dataset_factory, client, config):
+ kwargs = {} if config is None else {"parser_config": DataSet.ParserConfig(client, config)}
+ dataset = dataset_factory(**kwargs)
+ parsed = dataset.parser_config.to_json()
+ assert parsed
+ assert all(":" in key for key in parsed)
+ assert parsed["GeneralChunker:SixApplesFall"]["chunk_token_size"] == 512
+ assert client.list_datasets(id=dataset.id)[0].parser_config.to_json() == parsed
+
+
+def test_parser_config_legacy_keys_ignored(dataset_factory, client):
+ config = DataSet.ParserConfig(client, {"chunk_token_num": 1024, "raptor": {"use_raptor": True}, "graphrag": {"use_graphrag": True}})
+ dataset = dataset_factory(parser_config=config)
+ parsed = dataset.parser_config.to_json()
+ assert "chunk_token_num" not in parsed
+ assert "raptor" not in parsed
+ assert "graphrag" not in parsed
+ assert parsed["GeneralChunker:SixApplesFall"]["chunk_token_size"] == 512
+
+
[email protected]("pages", [[[1, 100]], [[1, 10], [5, 20]]])
+def test_parser_config_pages(dataset_factory, client, pages):
+ config = {"Parser:HipSignsRhyme": {"pdf": {"pages": pages}}}
+ dataset = dataset_factory(parser_config=DataSet.ParserConfig(client, config))
+ expected = [[1, 100]] if len(pages) == 1 else [[1, 20]]
+ assert dataset.parser_config.to_json()["Parser:HipSignsRhyme"]["pdf"]["pages"] == expected
+ assert client.list_datasets(id=dataset.id)[0].parser_config.to_json()["Parser:HipSignsRhyme"]["pdf"]["pages"] == expected
+
+
[email protected]("pages", ["1,2", ["1,2"], [["bad", "range"]], [[3, 1]], [[0, 1]]])
+def test_parser_config_pages_invalid(client, pages):
+ config = DataSet.ParserConfig(client, {"Parser:HipSignsRhyme": {"pdf": {"pages": pages}}})
+ with pytest.raises(Exception, match="pages must|invalid page range"):
+ client.create_dataset(name="invalid-pages", parser_config=config)
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_dataset_permissions.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_dataset_permissions.py
new file mode 100644
index 0000000000..6e32f3021b
--- /dev/null
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_dataset_permissions.py
@@ -0,0 +1,51 @@
+#
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Check resource authorization with a valid credential from an unrelated tenant."""
+
+import pytest
+from ragflow_sdk import DataSet, RAGFlow
+
+pytestmark = pytest.mark.integration
+
+
+ "operation,message",
+ [
+ ("read", "Permission denied"),
+ ("update", "Resource not found"),
+ ("delete", "Permission denied"),
+ ],
+)
+def test_other_tenant_cannot_access_private_dataset(client, dataset_factory, integration_settings, operation, message):
+ key = integration_settings.get("other_api_key")
+ if not key or key == integration_settings["api_key"]:
+ pytest.fail("RAGFLOW_SDK_OTHER_API_KEY must belong to an unrelated test tenant")
+ dataset = dataset_factory(permission="me")
+ other = RAGFlow(key, integration_settings["base_url"])
+ # Prove the second credential is authenticated; invalid tokens do not test permissions.
+ assert dataset.id not in {item.id for item in other.list_datasets()}
+ operations = {
+ "read": lambda: other.list_datasets(id=dataset.id),
+ "update": lambda: DataSet(other, {"id": dataset.id}).update({"name": "forbidden-rename"}),
+ "delete": lambda: other.delete_datasets(ids=[dataset.id]),
+ }
+ with pytest.raises(Exception, match=f"^{message}$"):
+ operations[operation]()
+ persisted = client.list_datasets(id=dataset.id)
+ assert len(persisted) == 1
+ assert persisted[0].name == dataset.name
+ assert persisted[0].permission == "me"
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_dataset_sdk.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_dataset_sdk.py
index 58d61384a5..24f430de68 100644
--- a/test/testcases/test_sdk_api/test_dataset_mangement/test_dataset_sdk.py
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_dataset_sdk.py
@@ -1,5 +1,20 @@
-import pytest
+#
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import pytest
from ragflow_sdk import RAGFlow
from ragflow_sdk.modules.dataset import DataSet
@@ -238,3 +253,128 @@ def test_update_rejects_legacy_chunk_method():
dataset.update({"chunk_method": "manual"})
assert rag.calls == []
+
+
+ "field",
+ [
+ "avatar",
+ "description",
+ "chunk_method",
+ "id",
+ "tenant_id",
+ "created_by",
+ "create_date",
+ "create_time",
+ "update_date",
+ "update_time",
+ "document_count",
+ "chunk_count",
+ "token_num",
+ "status",
+ "pagerank",
+ "auto_metadata_config",
+ "unknown_field",
+ ],
+)
+def test_create_rejects_removed_and_server_owned_arguments(field):
+ rag = RecordingRAGFlow({})
+ with pytest.raises(TypeError, match="unexpected keyword argument"):
+ rag.create_dataset(name="kb", **{field: "unsupported"})
+ assert rag.calls == []
+
+
[email protected]("parser_config", [None, DataSet.ParserConfig(None, {})])
+def test_create_omits_absent_config_and_serializes_explicit_empty_config(parser_config):
+ rag = RecordingRAGFlow({"id": "ds-1", "name": "kb"})
+ rag.create_dataset(name="kb", parser_config=parser_config)
+ payload = rag.calls[0][2]
+ if parser_config is None:
+ assert "parser_config" not in payload
+ else:
+ assert payload["parser_config"] == {}
+ assert "embedding_model" not in payload
+ assert "language" not in payload
+
+
[email protected]("kwargs", [{"name": None}, {"name": 0}, {"name": "kb", "permission": None}])
+def test_create_rejects_invalid_types_before_transport(kwargs):
+ from beartype.roar import BeartypeCallHintParamViolation
+
+ rag = RecordingRAGFlow({})
+ with pytest.raises(BeartypeCallHintParamViolation, match="not instance of str"):
+ rag.create_dataset(**kwargs)
+ assert rag.calls == []
+
+
[email protected]("ids, delete_all", [(None, False), ([], False), (["ds-1"], False), (None, True), ([], True)])
+def test_delete_payload_requires_explicit_delete_all(monkeypatch, ids, delete_all):
+ rag = RecordingRAGFlow({})
+ calls = []
+
+ def delete(path, json):
+ calls.append((path, json))
+ return FakeResponse({"code": 0})
+
+ monkeypatch.setattr(rag, "delete", delete)
+ assert rag.delete_datasets(ids=ids, delete_all=delete_all) is None
+ assert calls == [("/datasets", {"ids": ids, "delete_all": delete_all})]
+
+
+def test_list_parses_dataset_response_without_losing_parser_config(monkeypatch):
+ rag = RecordingRAGFlow({})
+ data = {"id": "ds-1", "name": "kb", "parser_id": "general", "permission": "team", "parser_config": {"GeneralChunker:node": {"chunk_token_size": 512}}}
+ monkeypatch.setattr(rag, "get", lambda *args, **kwargs: FakeResponse({"code": 0, "data": [data]}))
+ datasets = rag.list_datasets(ids=["ds-1"])
+ assert len(datasets) == 1
+ assert isinstance(datasets[0], DataSet)
+ assert datasets[0].id == "ds-1"
+ assert datasets[0].permission == "team"
+ assert datasets[0].parse_type == 1
+ assert datasets[0].parser_config.to_json() == {"GeneralChunker:node": {"chunk_token_size": 512}}
+
+
[email protected]("operation", ["create", "list", "update", "delete"])
+def test_api_errors_are_propagated_without_mutating_dataset(monkeypatch, operation):
+ rag = RecordingRAGFlow({})
+ dataset = DataSet(rag, {"id": "ds-1", "name": "before", "pipeline_id": "p1"})
+ error = FakeResponse({"code": 403, "message": "Permission denied", "data": None})
+ for method in ("post", "get", "put", "delete"):
+ monkeypatch.setattr(rag, method, lambda *args, **kwargs: error)
+ operations = {
+ "create": lambda: rag.create_dataset(name="kb"),
+ "list": rag.list_datasets,
+ "update": lambda: dataset.update({"name": "after"}),
+ "delete": lambda: rag.delete_datasets(ids=["ds-1"]),
+ }
+ with pytest.raises(Exception, match="^Permission denied$"):
+ operations[operation]()
+ assert dataset.name == "before"
+ assert dataset.pipeline_id == "p1"
+
+
+ "method, path, payload",
+ [
+ ("post", "/datasets", {"name": "kb", "parse_type": 1, "parser_id": "general"}),
+ ("put", "/datasets/ds-1", {"name": "renamed"}),
+ ("delete", "/datasets", {"ids": ["ds-1"], "delete_all": False}),
+ ],
+)
+def test_write_transport_sends_bearer_token_and_json(monkeypatch, method, path, payload):
+ import requests
+
+ rag = RAGFlow("secret-test-key", "http://example.invalid:9380")
+ calls = []
+ response = FakeResponse({"code": 0})
+
+ def send(**kwargs):
+ calls.append(kwargs)
+ return response
+
+ monkeypatch.setattr(requests, method, send)
+ assert getattr(rag, method)(path, json=payload) is response
+ assert len(calls) == 1
+ assert calls[0]["url"] == "http://example.invalid:9380/api/v1" + path
+ assert calls[0]["headers"] == {"Authorization": "Bearer secret-test-key"}
+ assert calls[0]["json"] == payload
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py
index cf7488fa45..6031b37784 100644
--- a/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py
@@ -1,5 +1,5 @@
#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,167 +13,115 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
import uuid
from concurrent.futures import ThreadPoolExecutor, as_completed
import pytest
-from common import batch_create_datasets
-from configs import HOST_ADDRESS, INVALID_API_TOKEN, SDK_UNAUTHORIZED_ERROR_MESSAGE
from ragflow_sdk import RAGFlow
class TestAuthorization:
@pytest.mark.p2
- @pytest.mark.parametrize(
- "invalid_auth, expected_message",
- [
- (None, SDK_UNAUTHORIZED_ERROR_MESSAGE),
- (INVALID_API_TOKEN, SDK_UNAUTHORIZED_ERROR_MESSAGE),
- ],
- )
- def test_auth_invalid(self, invalid_auth, expected_message):
- client = RAGFlow(invalid_auth, HOST_ADDRESS)
- with pytest.raises(Exception) as exception_info:
+ @pytest.mark.parametrize("invalid_auth", [None, "invalid-api-key"])
+ def test_auth_invalid(self, integration_settings, invalid_auth):
+ client = RAGFlow(invalid_auth, integration_settings["base_url"])
+ with pytest.raises(Exception, match="^Invalid access token$"):
+ client.delete_datasets()
+
+ @pytest.mark.p2
+ def test_auth_missing(self, integration_settings):
+ client = RAGFlow("unused", integration_settings["base_url"])
+ client.authorization_header = {}
+ with pytest.raises(Exception, match="^Missing Authorization header$"):
client.delete_datasets()
- assert str(exception_info.value) == expected_message
class TestCapability:
@pytest.mark.p3
- def test_delete_dataset_1k(self, client):
- datasets = batch_create_datasets(client, 1_000)
- client.delete_datasets(**{"ids": [dataset.id for dataset in datasets]})
-
- datasets = client.list_datasets()
- assert len(datasets) == 0, datasets
+ def test_delete_dataset_1k(self, client, dataset_factory):
+ datasets = [dataset_factory() for _ in range(1_000)]
+ assert client.delete_datasets(ids=[dataset.id for dataset in datasets]) is None
+ assert client.list_datasets() == []
@pytest.mark.p3
- def test_concurrent_deletion(self, client):
- count = 1_000
- datasets = batch_create_datasets(client, count)
+ def test_concurrent_deletion(self, client, dataset_factory):
+ datasets = [dataset_factory() for _ in range(20)]
with ThreadPoolExecutor(max_workers=5) as executor:
- futures = [executor.submit(client.delete_datasets, **{"ids": [dataset.id for dataset in datasets][i : i + 1]}) for i in range(count)]
- responses = list(as_completed(futures))
- assert len(responses) == count, responses
-
- datasets = client.list_datasets()
- assert len(datasets) == 0, datasets
+ futures = [executor.submit(client.delete_datasets, ids=[dataset.id]) for dataset in datasets]
+ for future in as_completed(futures):
+ assert future.result() is None
+ assert client.list_datasets() == []
class TestDatasetsDelete:
@pytest.mark.p1
- @pytest.mark.parametrize(
- "func, remaining",
- [
- (lambda r: {"ids": r[:1]}, 2),
- (lambda r: {"ids": r}, 0),
- ],
- ids=["single_dataset", "multiple_datasets"],
- )
- def test_ids(self, client, add_datasets_func, func, remaining):
- payload = None
- if callable(func):
- payload = func([dataset.id for dataset in add_datasets_func])
- client.delete_datasets(**payload)
-
- datasets = client.list_datasets()
- assert len(datasets) == remaining, str(datasets)
+ @pytest.mark.parametrize("delete_count", [1, 3], ids=["single_dataset", "multiple_datasets"])
+ def test_ids(self, client, add_datasets_func, delete_count):
+ ids = [dataset.id for dataset in add_datasets_func]
+ assert client.delete_datasets(ids=ids[:delete_count]) is None
+ assert {dataset.id for dataset in client.list_datasets()} == set(ids[delete_count:])
@pytest.mark.p2
- @pytest.mark.usefixtures("add_dataset_func")
- def test_ids_empty(self, client):
- payload = {"ids": []}
- client.delete_datasets(**payload)
-
- datasets = client.list_datasets()
- assert len(datasets) == 1, str(datasets)
+ def test_ids_empty(self, client, add_dataset_func):
+ client.delete_datasets(ids=[])
+ assert [dataset.id for dataset in client.list_datasets()] == [add_dataset_func.id]
@pytest.mark.p3
- @pytest.mark.usefixtures("add_datasets_func")
- def test_ids_none(self, client):
- payload = {"ids": None}
- client.delete_datasets(**payload)
-
- datasets = client.list_datasets()
- assert len(datasets) == 3, str(datasets)
+ def test_ids_none(self, client, add_datasets_func):
+ client.delete_datasets(ids=None)
+ assert {dataset.id for dataset in client.list_datasets()} == {dataset.id for dataset in add_datasets_func}
@pytest.mark.p2
- @pytest.mark.usefixtures("add_dataset_func")
- def test_id_not_uuid(self, client):
- payload = {"ids": ["not_uuid"]}
- with pytest.raises(Exception) as exception_info:
- client.delete_datasets(**payload)
- assert "Invalid UUID format" in str(exception_info.value), str(exception_info.value)
-
- datasets = client.list_datasets()
- assert len(datasets) == 1, str(datasets)
-
- @pytest.mark.p3
- @pytest.mark.usefixtures("add_dataset_func")
- def test_id_not_uuid1(self, client):
- payload = {"ids": [uuid.uuid4().hex]}
- with pytest.raises(Exception) as exception_info:
- client.delete_datasets(**payload)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
+ def test_ids_omitted(self, client, add_dataset_func):
+ client.delete_datasets()
+ assert [dataset.id for dataset in client.list_datasets()] == [add_dataset_func.id]
@pytest.mark.p2
- @pytest.mark.usefixtures("add_dataset_func")
- def test_id_wrong_uuid(self, client):
- payload = {"ids": ["d94a8dc02c9711f0930f7fbc369eab6d"]}
- with pytest.raises(Exception) as exception_info:
- client.delete_datasets(**payload)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
+ def test_id_not_uuid(self, client, add_dataset_func):
+ with pytest.raises(Exception, match="^Invalid UUID format$"):
+ client.delete_datasets(ids=["not_uuid"])
+ assert [dataset.id for dataset in client.list_datasets()] == [add_dataset_func.id]
- datasets = client.list_datasets()
- assert len(datasets) == 1, str(datasets)
+ @pytest.mark.p2
+ @pytest.mark.parametrize("dataset_id", [uuid.uuid4().hex, "d94a8dc02c9711f0930f7fbc369eab6d"], ids=["uuid4", "missing_uuid1"])
+ def test_id_wrong_uuid(self, client, add_dataset_func, dataset_id):
+ with pytest.raises(Exception, match="^Permission denied$"):
+ client.delete_datasets(ids=[dataset_id])
+ assert [dataset.id for dataset in client.list_datasets()] == [add_dataset_func.id]
@pytest.mark.p2
- @pytest.mark.parametrize(
- "func",
- [
- lambda r: {"ids": ["d94a8dc02c9711f0930f7fbc369eab6d"] + r},
- lambda r: {"ids": r[:1] + ["d94a8dc02c9711f0930f7fbc369eab6d"] + r[1:3]},
- lambda r: {"ids": r + ["d94a8dc02c9711f0930f7fbc369eab6d"]},
- ],
- )
- def test_ids_partial_invalid(self, client, add_datasets_func, func):
- if callable(func):
- payload = func([dataset.id for dataset in add_datasets_func])
- with pytest.raises(Exception) as exception_info:
- client.delete_datasets(**payload)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
-
- datasets = client.list_datasets()
- assert len(datasets) == 3, str(datasets)
+ @pytest.mark.parametrize("invalid_index", [0, 1, 3], ids=["first", "middle", "last"])
+ def test_ids_partial_invalid(self, client, add_datasets_func, invalid_index):
+ ids = [dataset.id for dataset in add_datasets_func]
+ payload = ids.copy()
+ payload.insert(invalid_index, uuid.uuid4().hex)
+ with pytest.raises(Exception, match="^Permission denied$"):
+ client.delete_datasets(ids=payload)
+ assert {dataset.id for dataset in client.list_datasets()} == set(ids)
@pytest.mark.p2
def test_ids_duplicate(self, client, add_datasets_func):
- dataset_ids = [dataset.id for dataset in add_datasets_func]
- payload = {"ids": dataset_ids + dataset_ids}
- with pytest.raises(Exception) as exception_info:
- client.delete_datasets(**payload)
- assert "Duplicate ids:" in str(exception_info.value), str(exception_info.value)
-
- datasets = client.list_datasets()
- assert len(datasets) == 3, str(datasets)
+ ids = [dataset.id for dataset in add_datasets_func]
+ with pytest.raises(Exception, match="Duplicate ids:"):
+ client.delete_datasets(ids=ids + ids)
+ assert {dataset.id for dataset in client.list_datasets()} == set(ids)
@pytest.mark.p2
def test_repeated_delete(self, client, add_datasets_func):
- dataset_ids = [dataset.id for dataset in add_datasets_func]
- payload = {"ids": dataset_ids}
- client.delete_datasets(**payload)
+ ids = [dataset.id for dataset in add_datasets_func]
+ client.delete_datasets(ids=ids)
+ with pytest.raises(Exception, match="^Permission denied$"):
+ client.delete_datasets(ids=ids)
+ assert client.list_datasets() == []
- with pytest.raises(Exception) as exception_info:
- client.delete_datasets(**payload)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
+class TestDeleteDatasetsArgumentValidation:
@pytest.mark.p3
- @pytest.mark.usefixtures("add_dataset_func")
- def test_field_unsupported(self, client):
- payload = {"unknown_field": "unknown_field"}
- with pytest.raises(Exception) as exception_info:
- client.delete_datasets(**payload)
- assert "got an unexpected keyword argument 'unknown_field'" in str(exception_info.value), str(exception_info.value)
-
- datasets = client.list_datasets()
- assert len(datasets) == 1, str(datasets)
+ def test_field_unsupported(self):
+ client = RAGFlow("token", "http://sdk.invalid")
+ with pytest.raises(TypeError, match="unexpected keyword argument 'unknown_field'"):
+ client.delete_datasets(unknown_field="unknown_field")
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_infrastructure.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_infrastructure.py
new file mode 100644
index 0000000000..62e585d0f4
--- /dev/null
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_infrastructure.py
@@ -0,0 +1,82 @@
+#
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Service-free checks for the integration suite's resource boundaries."""
+
+from types import SimpleNamespace
+
+import conftest as fixtures
+import pytest
+
+
[email protected]("isolated", [None, "0", "1"])
+def test_integration_requires_explicit_environment_before_network(monkeypatch, isolated):
+ monkeypatch.delenv("RAGFLOW_SDK_BASE_URL", raising=False)
+ monkeypatch.delenv("RAGFLOW_SDK_API_KEY", raising=False)
+ if isolated is None:
+ monkeypatch.delenv("RAGFLOW_SDK_ISOLATED", raising=False)
+ else:
+ monkeypatch.setenv("RAGFLOW_SDK_ISOLATED", isolated)
+
+ def no_network(*args, **kwargs):
+ pytest.fail("Missing integration prerequisites must not open a connection")
+
+ monkeypatch.setattr(fixtures, "RAGFlow", no_network)
+ with pytest.raises(pytest.fail.Exception, match="Integration environment required"):
+ fixtures.integration_settings.__wrapped__()
+
+
+def test_integration_refuses_nonempty_tenant(monkeypatch):
+ monkeypatch.setenv("RAGFLOW_SDK_ISOLATED", "1")
+ monkeypatch.setenv("RAGFLOW_SDK_BASE_URL", "http://example.invalid")
+ monkeypatch.setenv("RAGFLOW_SDK_API_KEY", "test-only-key")
+ monkeypatch.setattr(fixtures, "RAGFlow", lambda *args: SimpleNamespace(list_datasets=lambda **kwargs: [object()]))
+ with pytest.raises(AssertionError, match="test tenant is not empty"):
+ fixtures.integration_settings.__wrapped__()
+
+
+def test_cleanup_only_deletes_created_survivors_after_failure(monkeypatch):
+ datasets = {"unrelated": SimpleNamespace(id="unrelated")}
+ deleted = []
+
+ class FakeClient:
+ def create_dataset(self, name):
+ if name == "failure":
+ raise RuntimeError("create failed")
+ datasets[name] = SimpleNamespace(id=name)
+ return datasets[name]
+
+ def list_datasets(self, *, ids, page_size):
+ assert page_size == 100
+ return [datasets[key] for key in ids if key in datasets]
+
+ def delete_datasets(self, *, ids):
+ deleted.extend(ids)
+ for key in ids:
+ del datasets[key]
+
+ monkeypatch.setattr(fixtures, "RAGFlow", lambda *args: FakeClient())
+ fixture = fixtures.client.__wrapped__({"api_key": "test", "base_url": "http://example.invalid"}, monkeypatch)
+ client = next(fixture)
+ client.create_dataset("survivor")
+ client.create_dataset("already-deleted")
+ del datasets["already-deleted"]
+ with pytest.raises(RuntimeError, match="create failed"):
+ client.create_dataset("failure")
+ with pytest.raises(StopIteration):
+ next(fixture)
+ assert deleted == ["survivor"]
+ assert set(datasets) == {"unrelated"}
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py
index 60e7e405d3..87587312de 100644
--- a/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py
@@ -1,5 +1,5 @@
#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,11 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
import uuid
from concurrent.futures import ThreadPoolExecutor, as_completed
import pytest
-from configs import HOST_ADDRESS, INVALID_API_TOKEN, SDK_UNAUTHORIZED_ERROR_MESSAGE
+from beartype.roar import BeartypeCallHintParamViolation
from ragflow_sdk import RAGFlow
@@ -27,17 +28,13 @@ class _ListDatasetsResponse:
class TestListDatasetsArgumentValidation:
- @pytest.fixture(autouse=True)
- def set_tenant_info(self):
- return None
-
@pytest.mark.p2
@pytest.mark.parametrize(
"params",
[{"id": "dataset-id", "ids": ["dataset-id"]}, {"id": "dataset-id", "ids": [""]}],
)
def test_rejects_conflicting_id_and_ids_before_get(self, monkeypatch, params):
- client = RAGFlow("token", HOST_ADDRESS)
+ client = RAGFlow("token", "http://sdk.invalid")
get_calls = []
monkeypatch.setattr(client, "get", lambda *_args, **_kwargs: get_calls.append((_args, _kwargs)))
@@ -52,7 +49,7 @@ class TestListDatasetsArgumentValidation:
[{"id": "dataset-id"}, {"ids": ["dataset-id"]}, {"id": None, "ids": None}, {"id": "dataset-id", "ids": []}, {"id": "", "ids": ["dataset-id"]}],
)
def test_preserves_nonconflicting_id_and_ids(self, monkeypatch, params):
- client = RAGFlow("token", HOST_ADDRESS)
+ client = RAGFlow("token", "http://sdk.invalid")
get_calls = []
def _get(path, params=None, json=None):
@@ -69,302 +66,204 @@ class TestListDatasetsArgumentValidation:
)
]
+ @pytest.mark.p2
+ def test_get_dataset_not_found_raises(self, monkeypatch):
+ client = RAGFlow("token", "http://sdk.invalid")
+ monkeypatch.setattr(client, "list_datasets", lambda **_: [])
+ with pytest.raises(Exception, match="^Dataset missing-name-for-coverage not found$"):
+ client.get_dataset(name="missing-name-for-coverage")
+
+ @pytest.mark.p3
+ def test_field_unsupported(self):
+ client = RAGFlow("token", "http://sdk.invalid")
+ with pytest.raises(TypeError, match="unexpected keyword argument 'unknown_field'"):
+ client.list_datasets(unknown_field="unknown_field")
-class TestAuthorization:
@pytest.mark.p2
@pytest.mark.parametrize(
- "invalid_auth, expected_message",
- [
- (None, SDK_UNAUTHORIZED_ERROR_MESSAGE),
- (INVALID_API_TOKEN, SDK_UNAUTHORIZED_ERROR_MESSAGE),
- ],
+ "params",
+ [{"page": "a"}, {"page": None}, {"page_size": "a"}, {"page_size": None}, {"orderby": None}, {"desc": 3.14}, {"desc": "unknown"}, {"desc": None}],
)
- def test_auth_invalid(self, invalid_auth, expected_message):
- client = RAGFlow(invalid_auth, HOST_ADDRESS)
- with pytest.raises(Exception) as exception_info:
+ def test_invalid_parameter_types_before_get(self, monkeypatch, params):
+ client = RAGFlow("token", "http://sdk.invalid")
+ get_calls = []
+ monkeypatch.setattr(client, "get", lambda *args, **kwargs: get_calls.append((args, kwargs)))
+ with pytest.raises(BeartypeCallHintParamViolation, match="not instance of"):
+ client.list_datasets(**params)
+ assert get_calls == []
+
+
+class TestAuthorization:
+ @pytest.mark.p2
+ @pytest.mark.parametrize("invalid_auth", [None, "invalid-api-key"])
+ def test_auth_invalid(self, integration_settings, invalid_auth):
+ client = RAGFlow(invalid_auth, integration_settings["base_url"])
+ with pytest.raises(Exception, match="^Invalid access token$"):
+ client.list_datasets()
+
+ @pytest.mark.p2
+ def test_auth_missing(self, integration_settings):
+ client = RAGFlow("unused", integration_settings["base_url"])
+ client.authorization_header = {}
+ with pytest.raises(Exception, match="^Missing Authorization header$"):
client.list_datasets()
- assert expected_message in str(exception_info.value)
class TestCapability:
@pytest.mark.p3
- def test_concurrent_list(self, client):
- count = 100
+ def test_concurrent_list(self, client, add_datasets):
+ expected_ids = {dataset.id for dataset in add_datasets}
with ThreadPoolExecutor(max_workers=5) as executor:
- futures = [
- executor.submit(
- client.list_datasets,
- )
- for _ in range(count)
- ]
- responses = list(as_completed(futures))
- assert len(responses) == count, responses
+ futures = [executor.submit(client.list_datasets) for _ in range(100)]
+ for future in as_completed(futures):
+ assert {dataset.id for dataset in future.result()} == expected_ids
@pytest.mark.usefixtures("add_datasets")
class TestDatasetsList:
@pytest.mark.p2
- def test_params_unset(self, client):
+ def test_params_unset(self, client, add_datasets):
datasets = client.list_datasets()
- assert len(datasets) == 5, str(datasets)
-
- @pytest.mark.p2
- def test_params_empty(self, client):
- datasets = client.list_datasets(**{})
- assert len(datasets) == 5, str(datasets)
+ assert {dataset.id for dataset in datasets} == {dataset.id for dataset in add_datasets}
+ assert len(datasets) == len(add_datasets)
@pytest.mark.p1
@pytest.mark.parametrize(
"params, expected_page_size",
- [
- ({"page": 2, "page_size": 2}, 2),
- ({"page": 3, "page_size": 2}, 1),
- ({"page": 4, "page_size": 2}, 0),
- ({"page": 1, "page_size": 10}, 5),
- ],
- ids=["normal_middle_page", "normal_last_partial_page", "beyond_max_page", "full_data_single_page"],
+ [({"page": 2, "page_size": 2}, 2), ({"page": 3, "page_size": 2}, 1), ({"page": 4, "page_size": 2}, 0), ({"page": 1, "page_size": 10}, 5)],
+ ids=["middle", "last_partial", "beyond_last", "single_page"],
)
- def test_page(self, client, params, expected_page_size):
+ def test_page(self, client, add_datasets, params, expected_page_size):
datasets = client.list_datasets(**params)
- assert len(datasets) == expected_page_size, str(datasets)
+ assert len(datasets) == expected_page_size
+ assert len({dataset.id for dataset in datasets}) == len(datasets)
+ assert {dataset.id for dataset in datasets} <= {dataset.id for dataset in add_datasets}
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "params, expected_message",
- [
- ({"page": 0}, "Input should be greater than or equal to 1"),
- ({"page": "a"}, "not instance of"),
- ],
- ids=["page_0", "page_a"],
- )
- def test_page_invalid(self, client, params, expected_message):
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert expected_message in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.p1
+ def test_pages_partition_results(self, client, add_datasets):
+ datasets = [dataset for page in range(1, 4) for dataset in client.list_datasets(page=page, page_size=2)]
+ assert len(datasets) == len(add_datasets)
+ assert {dataset.id for dataset in datasets} == {dataset.id for dataset in add_datasets}
@pytest.mark.p2
- def test_page_none(self, client):
- params = {"page": None}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "not instance of" in str(exception_info.value), str(exception_info.value)
+ def test_page_invalid(self, client):
+ with pytest.raises(Exception, match="greater than or equal to 1"):
+ client.list_datasets(page=0)
@pytest.mark.p1
- @pytest.mark.parametrize(
- "params, expected_page_size",
- [
- ({"page_size": 1}, 1),
- ({"page_size": 3}, 3),
- ({"page_size": 5}, 5),
- ({"page_size": 6}, 5),
- ],
- ids=["min_valid_page_size", "medium_page_size", "page_size_equals_total", "page_size_exceeds_total"],
- )
- def test_page_size(self, client, params, expected_page_size):
- datasets = client.list_datasets(**params)
- assert len(datasets) == expected_page_size, str(datasets)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "params, expected_message",
- [
- ({"page_size": 0}, "Input should be greater than or equal to 1"),
- ({"page_size": "a"}, "not instance of"),
- ],
- )
- def test_page_size_invalid(self, client, params, expected_message):
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert expected_message in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.parametrize("page_size, expected_size", [(1, 1), (3, 3), (5, 5), (6, 5)])
+ def test_page_size(self, client, add_datasets, page_size, expected_size):
+ datasets = client.list_datasets(page_size=page_size)
+ assert len(datasets) == expected_size
+ assert len({dataset.id for dataset in datasets}) == len(datasets)
+ assert {dataset.id for dataset in datasets} <= {dataset.id for dataset in add_datasets}
@pytest.mark.p2
- def test_page_size_none(self, client):
- params = {"page_size": None}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "not instance of" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- @pytest.mark.parametrize(
- "params",
- [
- {"orderby": "create_time"},
- {"orderby": "update_time"},
- ],
- ids=["orderby_create_time", "orderby_update_time"],
- )
- def test_orderby(self, client, params):
- client.list_datasets(**params)
-
- @pytest.mark.p3
- @pytest.mark.parametrize(
- "params",
- [
- {"orderby": ""},
- {"orderby": "unknown"},
- {"orderby": "CREATE_TIME"},
- {"orderby": "UPDATE_TIME"},
- {"orderby": " create_time "},
- ],
- ids=["empty", "unknown", "orderby_create_time_upper", "orderby_update_time_upper", "whitespace"],
- )
- def test_orderby_invalid(self, client, params):
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "Input should be 'create_time' or 'update_time'" in str(exception_info.value), str(exception_info.value)
+ def test_page_size_invalid(self, client):
+ with pytest.raises(Exception, match="greater than or equal to 1"):
+ client.list_datasets(page_size=0)
@pytest.mark.p3
- def test_orderby_none(self, client):
- params = {"orderby": None}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "not instance of" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- @pytest.mark.parametrize(
- "params",
- [
- {"desc": True},
- {"desc": False},
- ],
- ids=["desc=True", "desc=False"],
- )
- def test_desc(self, client, params):
- client.list_datasets(**params)
-
- @pytest.mark.p3
- @pytest.mark.parametrize(
- "params",
- [
- {"desc": 3.14},
- {"desc": "unknown"},
- ],
- ids=["float_value", "invalid_string"],
- )
- def test_desc_invalid(self, client, params):
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "not instance of" in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.parametrize("orderby", ["create_time", "update_time"])
+ @pytest.mark.parametrize("desc", [True, False])
+ def test_orderby(self, client, add_datasets, orderby, desc):
+ # DataSet omits timestamps, so read persisted values through the detail API.
+ times = {}
+ for dataset in add_datasets:
+ response = client.get(f"/datasets/{dataset.id}").json()
+ assert response["code"] == 0, response
+ times[dataset.id] = response["data"][orderby]
+ datasets = client.list_datasets(orderby=orderby, desc=desc)
+ assert {dataset.id for dataset in datasets} == set(times)
+ values = [times[dataset.id] for dataset in datasets]
+ assert values == sorted(values, reverse=desc)
@pytest.mark.p3
- def test_desc_none(self, client):
- params = {"desc": None}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "not instance of" in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.parametrize("orderby", ["", "unknown", "CREATE_TIME", "UPDATE_TIME", " create_time "])
+ def test_orderby_invalid(self, client, orderby):
+ with pytest.raises(Exception, match="Input should be 'create_time' or 'update_time'"):
+ client.list_datasets(orderby=orderby)
@pytest.mark.p1
- def test_name(self, client):
- params = {"name": "dataset_1"}
- datasets = client.list_datasets(**params)
- assert len(datasets) == 1, str(datasets)
- assert datasets[0].name == "dataset_1", str(datasets)
+ def test_name(self, client, add_datasets):
+ target = add_datasets[1]
+ datasets = client.list_datasets(name=target.name)
+ assert [(dataset.id, dataset.name) for dataset in datasets] == [(target.id, target.name)]
@pytest.mark.p2
def test_name_wrong(self, client):
- params = {"name": "wrong name"}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- def test_get_dataset_not_found_raises(self, client, monkeypatch):
- monkeypatch.setattr(client, "list_datasets", lambda **_: [])
- with pytest.raises(Exception) as exception_info:
- client.get_dataset(name="missing-name-for-coverage")
- assert "Dataset missing-name-for-coverage not found" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- def test_name_empty(self, client):
- params = {"name": ""}
- datasets = client.list_datasets(**params)
- assert len(datasets) == 5, str(datasets)
+ assert client.list_datasets(name=f"missing-{uuid.uuid4().hex}") == []
@pytest.mark.p2
- def test_name_none(self, client):
- params = {"name": None}
- datasets = client.list_datasets(**params)
- assert len(datasets) == 5, str(datasets)
+ @pytest.mark.parametrize("name", ["", None])
+ def test_name_empty(self, client, add_datasets, name):
+ assert {dataset.id for dataset in client.list_datasets(name=name)} == {dataset.id for dataset in add_datasets}
@pytest.mark.p1
def test_id(self, client, add_datasets):
- dataset_ids = [dataset.id for dataset in add_datasets]
- params = {"id": dataset_ids[0]}
- datasets = client.list_datasets(**params)
- assert len(datasets) == 1, str(datasets)
- assert datasets[0].id == dataset_ids[0], str(datasets)
+ datasets = client.list_datasets(id=add_datasets[0].id)
+ assert [dataset.id for dataset in datasets] == [add_datasets[0].id]
@pytest.mark.p2
def test_id_not_uuid(self, client):
- params = {"id": "not_uuid"}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "Invalid UUID format" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- def test_id_not_uuid1(self, client):
- params = {"id": uuid.uuid4().hex}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
+ with pytest.raises(Exception, match="^Invalid UUID format$"):
+ client.list_datasets(id="not_uuid")
@pytest.mark.p2
- def test_id_wrong_uuid(self, client):
- params = {"id": "d94a8dc02c9711f0930f7fbc369eab6d"}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.parametrize("dataset_id", [uuid.uuid4().hex, "d94a8dc02c9711f0930f7fbc369eab6d"], ids=["uuid4", "missing_uuid1"])
+ def test_id_wrong_uuid(self, client, dataset_id):
+ with pytest.raises(Exception, match="^Resource not found$"):
+ client.list_datasets(id=dataset_id)
@pytest.mark.p2
def test_id_empty(self, client):
- params = {"id": ""}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "Invalid UUID format" in str(exception_info.value), str(exception_info.value)
+ with pytest.raises(Exception, match="^Invalid UUID format$"):
+ client.list_datasets(id="")
@pytest.mark.p2
- def test_id_none(self, client):
- params = {"id": None}
- datasets = client.list_datasets(**params)
- assert len(datasets) == 5, str(datasets)
+ def test_id_none(self, client, add_datasets):
+ assert {dataset.id for dataset in client.list_datasets(id=None)} == {dataset.id for dataset in add_datasets}
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "func, name, expected_num",
- [
- (lambda r: r[0].id, "dataset_0", 1),
- (lambda r: r[0].id, "dataset_1", 0),
- ],
- ids=["name_and_id_match", "name_and_id_mismatch"],
- )
- def test_name_and_id(self, client, add_datasets, func, name, expected_num):
- params = None
- if callable(func):
- params = {"id": func(add_datasets), "name": name}
- datasets = client.list_datasets(**params)
- assert len(datasets) == expected_num, str(datasets)
+ @pytest.mark.p1
+ @pytest.mark.parametrize("matching_name", [True, False])
+ def test_name_and_id(self, client, add_datasets, matching_name):
+ target = add_datasets[0]
+ name = target.name if matching_name else add_datasets[1].name
+ datasets = client.list_datasets(id=target.id, name=name)
+ assert [dataset.id for dataset in datasets] == ([target.id] if matching_name else [])
@pytest.mark.p3
- @pytest.mark.parametrize(
- "dataset_id, name",
- [
- (lambda r: r[0].id, "wrong_name"),
- (uuid.uuid1().hex, "dataset_0"),
- ],
- ids=["name", "id"],
- )
- def test_name_and_id_wrong(self, client, add_datasets, dataset_id, name):
- if callable(dataset_id):
- params = {"id": dataset_id(add_datasets), "name": name}
+ @pytest.mark.parametrize("missing_id", [False, True])
+ def test_name_and_id_wrong(self, client, add_datasets, missing_id):
+ if missing_id:
+ with pytest.raises(Exception, match="^Resource not found$"):
+ client.list_datasets(id=uuid.uuid4().hex, name=add_datasets[0].name)
else:
- params = {"id": dataset_id, "name": name}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
+ assert client.list_datasets(id=add_datasets[0].id, name=f"missing-{uuid.uuid4().hex}") == []
- @pytest.mark.p3
- def test_field_unsupported(self, client):
- params = {"unknown_field": "unknown_field"}
- with pytest.raises(Exception) as exception_info:
- client.list_datasets(**params)
- assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.p1
+ def test_ids_filter(self, client, add_datasets):
+ expected = {dataset.id for dataset in add_datasets[:2]}
+ datasets = client.list_datasets(ids=list(expected))
+ assert len(datasets) == len(expected)
+ assert {dataset.id for dataset in datasets} == expected
+
+ @pytest.mark.p2
+ def test_ids_missing_are_filtered(self, client, add_datasets):
+ datasets = client.list_datasets(ids=[add_datasets[0].id, uuid.uuid4().hex])
+ assert [dataset.id for dataset in datasets] == [add_datasets[0].id]
+ assert client.list_datasets(ids=[uuid.uuid4().hex]) == []
+
+ @pytest.mark.p2
+ def test_ids_invalid(self, client):
+ with pytest.raises(Exception, match="^Invalid UUID format$"):
+ client.list_datasets(ids=["not_uuid"])
+
+ @pytest.mark.p2
+ def test_ids_duplicates(self, client, add_datasets):
+ dataset_id = add_datasets[0].id
+ with pytest.raises(Exception, match="Duplicate ids:"):
+ client.list_datasets(ids=[dataset_id, dataset_id])
diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py
index 543245e0dd..f967cde3d6 100644
--- a/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py
+++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py
@@ -1,5 +1,5 @@
#
-# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
+# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,290 +13,198 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-import os
-from concurrent.futures import ThreadPoolExecutor, as_completed
-from operator import attrgetter
+
+from concurrent.futures import ThreadPoolExecutor
+from uuid import uuid4
import pytest
-from configs import DATASET_NAME_LIMIT, IS_GO_PROXY
-from hypothesis import HealthCheck, example, given, settings
-from ragflow_sdk import DataSet
-from utils import encode_avatar
-from utils.file_utils import create_image_file
-from utils.hypothesis_utils import valid_names
-from configs import DEFAULT_PARSER_CONFIG
-from utils.engine_utils import get_doc_engine
-
-
-class TestRquest:
- @pytest.mark.p2
+from ragflow_sdk import DataSet, RAGFlow
+
+pytestmark = pytest.mark.integration
+
+
+class TestRequest:
def test_payload_empty(self, add_dataset_func):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({})
- assert "no properties were modified" in str(exception_info.value), str(exception_info.value)
+ with pytest.raises(Exception, match="no properties were modified"):
+ add_dataset_func.update({})
class TestCapability:
@pytest.mark.p3
- def test_update_dateset_concurrent(self, add_dataset_func):
+ def test_update_dataset_concurrent(self, client, add_dataset_func):
dataset = add_dataset_func
- count = 100
+ names = [f"sdk-concurrent-{uuid4().hex}" for _ in range(10)]
with ThreadPoolExecutor(max_workers=5) as executor:
- futures = [executor.submit(dataset.update, {"name": f"dataset_{i}"}) for i in range(count)]
- responses = list(as_completed(futures))
- assert len(responses) == count, responses
+ futures = [executor.submit(dataset.update, {"name": name}) for name in names]
+ for future in futures:
+ assert future.result().id == dataset.id
+ assert client.list_datasets(id=dataset.id)[0].name in names
class TestDatasetUpdate:
- @pytest.mark.p1
- @given(name=valid_names())
- @example("a" * 128)
- @settings(max_examples=20, suppress_health_check=[HealthCheck.function_scoped_fixture])
+ @pytest.mark.parametrize("name", ["a", "a" * 128, "with spaces", " trimmed ", "资料"], ids=["min", "max", "spaces", "trim", "bmp"])
def test_name(self, client, add_dataset_func, name):
dataset = add_dataset_func
- payload = {"name": name}
- dataset.update(payload)
- assert dataset.name == name, str(dataset)
+ dataset.update({"name": name})
+ assert dataset.name == name.strip()
+ assert client.list_datasets(id=dataset.id)[0].name == name.strip()
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.name == name, str(retrieved_dataset)
+ @pytest.mark.skip(reason="Go internal/service/dataset/update.go uses len(name) bytes, rejecting documented 128-character BMP names")
+ def test_name_unicode_character_limit(self, client, add_dataset_func):
+ name = "资" * 128
+ add_dataset_func.update({"name": name})
+ assert add_dataset_func.name == name
+ assert client.list_datasets(id=add_dataset_func.id)[0].name == name
- @pytest.mark.p2
@pytest.mark.parametrize(
- "name, expected_message",
+ "name,message",
[
- ("", "String should have at least 1 character"),
- (" ", "String should have at least 1 character"),
- ("a" * (DATASET_NAME_LIMIT + 1), "String should have at most 128 characters"),
- (0, "Input should be a valid string"),
- (None, "Input should be a valid string"),
+ ("", "at least 1 character"),
+ (" ", "at least 1 character"),
+ ("a" * 129, "at most 128 characters"),
+ (0, "cannot unmarshal"),
],
- ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
)
- def test_name_invalid(self, add_dataset_func, name, expected_message):
+ def test_name_invalid(self, client, add_dataset_func, name, message):
dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
+ original = dataset.name
+ with pytest.raises(Exception, match=message):
dataset.update({"name": name})
- error_message = str(exception_info.value)
- if IS_GO_PROXY:
- if name is None:
- pytest.skip("Go dataset update ignores an explicit null name")
- if not isinstance(name, str):
- assert "cannot unmarshal" in error_message and ".name" in error_message, error_message
- return
- assert expected_message in error_message, error_message
+ assert client.list_datasets(id=dataset.id)[0].name == original
- @pytest.mark.p3
- def test_name_duplicated(self, add_datasets_func):
- datasets = add_datasets_func
- name = "dataset_1"
- with pytest.raises(Exception) as exception_info:
- datasets[0].update({"name": name})
- assert f"Dataset name '{name}' already exists" in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.parametrize("uppercase", [False, True])
+ def test_name_duplicated(self, client, add_datasets_func, uppercase):
+ first, second = add_datasets_func[:2]
+ original = first.name
+ name = second.name.upper() if uppercase else second.name
+ with pytest.raises(Exception, match="already exists"):
+ first.update({"name": name})
+ assert client.list_datasets(id=first.id)[0].name == original
- @pytest.mark.p3
- def test_name_case_insensitive(self, add_datasets_func):
- dataset = add_datasets_func[0]
- name = "DATASET_1"
- with pytest.raises(Exception) as exception_info:
- dataset.update({"name": name})
- assert f"Dataset name '{name}' already exists" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- def test_avatar(self, client, add_dataset_func, tmp_path):
+ @pytest.mark.parametrize("avatar", ["data:image/png;base64,iVBORw0KGgo=", "data:image/jpeg;base64,/9j/4AAQ=="])
+ def test_avatar(self, client, add_dataset_func, avatar):
dataset = add_dataset_func
- fn = create_image_file(tmp_path / "ragflow_test.png")
- avatar_data = f"data:image/png;base64,{encode_avatar(fn)}"
- dataset.update({"avatar": avatar_data})
- assert dataset.avatar == avatar_data, str(dataset)
+ dataset.update({"avatar": avatar})
+ assert dataset.avatar == avatar
+ assert client.list_datasets(id=dataset.id)[0].avatar == avatar
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.avatar == avatar_data, str(retrieved_dataset)
-
- @pytest.mark.p3
def test_avatar_exceeds_limit_length(self, add_dataset_func):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"avatar": "a" * 65536})
- assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
+ with pytest.raises(Exception, match="at most 65535 characters"):
+ add_dataset_func.update({"avatar": "a" * 65536})
- @pytest.mark.p3
@pytest.mark.parametrize(
- "avatar_prefix, expected_message",
+ "avatar,message",
[
- ("", "missing MIME prefix. Expected format: data:<mime>;base64,<data>"),
- ("data:image/png;base64", "missing MIME prefix. Expected format: data:<mime>;base64,<data>"),
- ("invalid_mine_prefix:image/png;base64,", "invalid MIME prefix format. Must start with 'data:'"),
- ("data:unsupported_mine_type;base64,", "Unsupported MIME type. Allowed: ['image/jpeg', 'image/png']"),
+ ("iVBORw0KGgo=", "missing MIME prefix"),
+ ("data:image/png;base64iVBORw0KGgo=", "missing MIME prefix"),
+ ("invalid:image/png;base64,iVBORw0KGgo=", "invalid MIME prefix"),
+ ("data:image/gif;base64,R0lGODlh", "unsupported MIME type"),
],
- ids=["empty_prefix", "missing_comma", "unsupported_mine_type", "invalid_mine_type"],
)
- def test_avatar_invalid_prefix(self, add_dataset_func, tmp_path, avatar_prefix, expected_message):
- dataset = add_dataset_func
- fn = create_image_file(tmp_path / "ragflow_test.png")
- with pytest.raises(Exception) as exception_info:
- dataset.update({"avatar": f"{avatar_prefix}{encode_avatar(fn)}"})
- assert expected_message in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- def test_avatar_none(self, client, add_dataset_func):
- dataset = add_dataset_func
- dataset.update({"avatar": None})
- assert dataset.avatar is None, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.avatar is None, str(retrieved_dataset)
+ def test_avatar_invalid_prefix(self, add_dataset_func, avatar, message):
+ with pytest.raises(Exception, match=message):
+ add_dataset_func.update({"avatar": avatar})
- @pytest.mark.p2
- def test_description(self, client, add_dataset_func):
- dataset = add_dataset_func
- dataset.update({"description": "description"})
- assert dataset.description == "description", str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.description == "description", str(retrieved_dataset)
-
- @pytest.mark.p3
- def test_description_exceeds_limit_length(self, add_dataset_func):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"description": "a" * 65536})
- assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p3
- def test_description_none(self, client, add_dataset_func):
- dataset = add_dataset_func
- dataset.update({"description": None})
- assert dataset.description is None, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.description is None, str(retrieved_dataset)
-
- @pytest.mark.p1
- @pytest.mark.parametrize(
- "embedding_model",
- [
- "BAAI/bge-small-en-v1.5@Builtin",
- "embedding-3@CI@ZHIPU-AI",
- ],
- ids=["builtin_baai", "tenant_zhipu"],
- )
- def test_embedding_model(self, client, add_dataset_func, embedding_model):
- dataset = add_dataset_func
- dataset.update({"embedding_model": embedding_model})
- assert dataset.embedding_model == embedding_model, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.embedding_model == embedding_model, str(retrieved_dataset)
-
- @pytest.mark.p2
@pytest.mark.parametrize(
- "name, embedding_model",
+ "field,value",
[
- ("unknown_llm_name", "unknown@ZHIPU-AI"),
- ("unknown_llm_factory", "embedding-3@unknown"),
- ("tenant_no_auth_default_tenant_llm", "text-embedding-v3@Tongyi-Qianwen"),
- ("tenant_no_auth", "text-embedding-3-small@OpenAI"),
+ ("avatar", "data:image/png;base64,iVBORw0KGgo="),
+ ("description", "description"),
],
- ids=["unknown_llm_name", "unknown_llm_factory", "tenant_no_auth_default_tenant_llm", "tenant_no_auth"],
)
- def test_embedding_model_invalid(self, add_dataset_func, name, embedding_model):
+ def test_clear_optional_text(self, client, add_dataset_func, field, value):
dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"name": name, "embedding_model": embedding_model})
- error_msg = str(exception_info.value)
- assert "not found" in error_msg, error_msg
+ dataset.update({field: value})
+ dataset.update({field: ""})
+ assert getattr(dataset, field) == ""
+ assert getattr(client.list_datasets(id=dataset.id)[0], field) == ""
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "name, embedding_model",
- [
- ("empty", ""),
- ("space", " "),
- ("missing_at", "BAAI/bge-small-en-v1.5Builtin"),
- ("missing_model_name", "@Builtin"),
- ("missing_provider", "BAAI/bge-small-en-v1.5@"),
- ("whitespace_only_model_name", " @Builtin"),
- ("whitespace_only_provider", "BAAI/bge-small-en-v1.5@ "),
- ],
- ids=["empty", "space", "missing_at", "empty_model_name", "empty_provider", "whitespace_only_model_name", "whitespace_only_provider"],
- )
- def test_embedding_model_format(self, add_dataset_func, name, embedding_model):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"name": name, "embedding_model": embedding_model})
- error_msg = str(exception_info.value)
- if IS_GO_PROXY and name in ["empty", "space"]:
- assert "lookup failed: record not found" in error_msg, error_msg
- elif name in ["empty", "space", "missing_at"]:
- assert "embedding model identifier must follow <model_name>@<provider> format" in error_msg, error_msg
- else:
- assert "both model_name and provider must be non-empty strings" in error_msg, error_msg
-
- @pytest.mark.p2
- def test_embedding_model_none(self, client, add_dataset_func):
+ @pytest.mark.parametrize("description", ["description", "a" * 65535], ids=["text", "max-length"])
+ def test_description(self, client, add_dataset_func, description):
dataset = add_dataset_func
- if IS_GO_PROXY:
- pytest.skip("Go dataset update ignores an explicit null embedding_model")
- dataset.update({"embedding_model": None})
- assert dataset.embedding_model.split("@", 1)[0] == "BAAI/bge-small-en-v1.5", str(dataset)
+ dataset.update({"description": description})
+ assert dataset.description == description
+ assert client.list_datasets(id=dataset.id)[0].description == description
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.embedding_model.split("@", 1)[0] == "BAAI/bge-small-en-v1.5", str(retrieved_dataset)
+ def test_description_exceeds_limit_length(self, add_dataset_func):
+ with pytest.raises(Exception, match="at most 65535 characters"):
+ add_dataset_func.update({"description": "a" * 65536})
+
+ @pytest.mark.parametrize("language", ["English", " 中文 ", "a" * 32])
+ def test_language(self, client, add_dataset_func, language):
+ add_dataset_func.update({"language": language})
+ assert add_dataset_func.language == language.strip()
+ assert client.list_datasets(id=add_dataset_func.id)[0].language == language.strip()
+
+ @pytest.mark.parametrize("language,message", [("", "at least 1"), (" ", "at least 1"), ("a" * 33, "at most 32")])
+ def test_language_invalid(self, client, add_dataset_func, language, message):
+ before = add_dataset_func.language
+ with pytest.raises(Exception, match=message):
+ add_dataset_func.update({"language": language})
+ assert client.list_datasets(id=add_dataset_func.id)[0].language == before
+
+ def test_embedding_model(self, client, add_dataset_func, integration_settings):
+ model = integration_settings.get("embedding_model")
+ if not model:
+ pytest.fail("Set RAGFLOW_SDK_EMBEDDING_MODEL to an accessible canonical model@instance@provider identifier")
+ dataset = add_dataset_func
+ dataset.update({"embedding_model": model})
+ assert dataset.embedding_model == model
+ assert client.list_datasets(id=dataset.id)[0].embedding_model == model
+
+ def test_embedding_model_invalid(self, client, add_dataset_func):
+ dataset = add_dataset_func
+ original = dataset.embedding_model
+ with pytest.raises(Exception, match="not found"):
+ dataset.update({"embedding_model": f"sdk-missing-{uuid4().hex}@MissingProvider"})
+ assert client.list_datasets(id=dataset.id)[0].embedding_model == original
- @pytest.mark.p2
@pytest.mark.parametrize(
- "permission",
+ "model,message",
[
- "me",
- "team",
+ ("", "must follow"),
+ (" ", "must follow"),
+ ("modelWithoutProvider", "must follow"),
+ ("@Builtin", "non-empty"),
+ ("model@", "non-empty"),
+ (" @Builtin", "non-empty"),
+ ("model@ ", "non-empty"),
],
- ids=["me", "team"],
)
+ def test_embedding_model_format(self, add_dataset_func, model, message):
+ with pytest.raises(Exception, match=message):
+ add_dataset_func.update({"embedding_model": model})
+
+ @pytest.mark.parametrize("permission", ["me", "team", " me "])
def test_permission(self, client, add_dataset_func, permission):
dataset = add_dataset_func
dataset.update({"permission": permission})
- assert dataset.permission == permission.lower().strip(), str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.permission == permission.lower().strip(), str(retrieved_dataset)
+ assert dataset.permission == permission.strip()
+ assert client.list_datasets(id=dataset.id)[0].permission == permission.strip()
- @pytest.mark.p2
@pytest.mark.parametrize(
- "permission",
+ "permission,message",
[
- "",
- "unknown",
- list(),
- "ME",
- "TEAM",
- " ME ",
+ ("", "'me' or 'team'"),
+ ("unknown", "'me' or 'team'"),
+ ([], "cannot unmarshal"),
+ ("ME", "'me' or 'team'"),
+ ("TEAM", "'me' or 'team'"),
],
- ids=["empty", "unknown", "type_error", "me_upercase", "team_upercase", "whitespace"],
)
- def test_permission_invalid(self, add_dataset_func, permission):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"permission": permission})
- error_message = str(exception_info.value)
- if IS_GO_PROXY and not isinstance(permission, str):
- assert "cannot unmarshal" in error_message and ".permission" in error_message, error_message
- else:
- assert "Input should be 'me' or 'team'" in error_message, error_message
+ def test_permission_invalid(self, add_dataset_func, permission, message):
+ with pytest.raises(Exception, match=message):
+ add_dataset_func.update({"permission": permission})
- @pytest.mark.p3
- def test_permission_none(self, add_dataset_func):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"permission": None})
- assert "Input should be 'me' or 'team'" in str(exception_info.value), str(exception_info.value)
+ @pytest.mark.parametrize("field", ["name", "embedding_model", "permission", "pagerank"])
+ def test_null_scalar_is_not_an_update(self, add_dataset_func, field):
+ with pytest.raises(Exception, match="no properties were modified"):
+ add_dataset_func.update({field: None})
- @pytest.mark.p1
@pytest.mark.parametrize(
- "chunk_method",
+ "parser_id",
[
- "naive",
+ "general",
"book",
"email",
"laws",
@@ -307,471 +215,171 @@ class TestDatasetUpdate:
"presentation",
"qa",
"table",
- "tag",
],
- ids=["naive", "book", "email", "laws", "manual", "one", "paper", "picture", "presentation", "qa", "table", "tag"],
)
- def test_chunk_method(self, client, add_dataset_func, chunk_method):
+ def test_parser_selection(self, client, add_dataset_func, parser_id):
dataset = add_dataset_func
- dataset.update({"chunk_method": chunk_method})
- assert dataset.chunk_method == chunk_method, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.chunk_method == chunk_method, str(retrieved_dataset)
+ dataset.update({"parse_type": 1, "parser_id": parser_id})
+ assert dataset.parser_id == parser_id
+ assert dataset.parse_type == 1
+ assert dataset.pipeline_id is None
+ retrieved = client.list_datasets(id=dataset.id)[0]
+ assert retrieved.parser_id == parser_id
+ assert retrieved.parse_type == 1
+ assert retrieved.pipeline_id is None
- @pytest.mark.p2
@pytest.mark.parametrize(
- "chunk_method",
+ "payload,message",
[
- "",
- "unknown",
- list(),
+ ({"parser_id": "qa"}, "parse_type is required"),
+ ({"pipeline_id": "12345678901234567890123456789012"}, "parse_type is required"),
+ ({"parse_type": 1}, "parser_id is required"),
+ ({"parse_type": 2}, "pipeline_id is required"),
+ ({"parse_type": 3}, "invalid parse_type"),
+ ({"parse_type": 1, "parser_id": "qa", "pipeline_id": "pipeline"}, "pipeline_id must not be set"),
+ ({"parse_type": 2, "pipeline_id": "pipeline", "parser_id": "qa"}, "parser_id must not be set"),
+ ({"parse_type": 1, "parser_id": "unknown"}, "input should be"),
+ ({"parse_type": 1, "parser_id": []}, "cannot unmarshal"),
+ ({"parse_type": 1, "parser_id": ""}, "parser_id is required"),
+ ({"parse_type": 1, "parser_id": None}, "parser_id is required"),
],
- ids=["empty", "unknown", "type_error"],
)
- def test_chunk_method_invalid(self, add_dataset_func, chunk_method):
+ def test_parser_selection_invalid(self, client, add_dataset_func, payload, message):
dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"chunk_method": chunk_method})
- error_message = str(exception_info.value)
- if IS_GO_PROXY and not isinstance(chunk_method, str):
- assert "cannot unmarshal" in error_message and ".chunk_method" in error_message, error_message
- elif IS_GO_PROXY:
- assert error_message.startswith("Input should be 'naive', 'book'") and error_message.endswith("or 'tag'"), error_message
- else:
- assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'" in error_message, error_message
-
- @pytest.mark.p3
- def test_chunk_method_none(self, add_dataset_func):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"chunk_method": None})
- assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table', 'tag' or 'resume'" in str(exception_info.value), str(
- exception_info.value
- )
-
- @pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="#8208")
- @pytest.mark.p2
- @pytest.mark.parametrize("pagerank", [0, 50, 100], ids=["min", "mid", "max"])
- def test_pagerank(self, client, add_dataset_func, pagerank):
- if get_doc_engine(client) == "infinity":
- pytest.skip("#8208")
- dataset = add_dataset_func
- dataset.update({"pagerank": pagerank})
- assert dataset.pagerank == pagerank, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.pagerank == pagerank, str(retrieved_dataset)
-
- @pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="#8208")
- @pytest.mark.p2
- def test_pagerank_set_to_0(self, client, add_dataset_func):
- if get_doc_engine(client) == "infinity":
- pytest.skip("#8208")
- dataset = add_dataset_func
- dataset.update({"pagerank": 50})
- assert dataset.pagerank == 50, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.pagerank == 50, str(retrieved_dataset)
-
- dataset.update({"pagerank": 0})
- assert dataset.pagerank == 0, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert retrieved_dataset.pagerank == 0, str(retrieved_dataset)
-
- @pytest.mark.skipif(os.getenv("DOC_ENGINE") != "infinity", reason="#8208")
- @pytest.mark.p2
- def test_pagerank_infinity(self, client, add_dataset_func):
- if get_doc_engine(client) != "infinity":
- pytest.skip("#8208")
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"pagerank": 50})
- assert "'pagerank' can only be set when doc_engine is elasticsearch" in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- @pytest.mark.parametrize(
- "pagerank, expected_message",
- [
- (-1, "Input should be greater than or equal to 0"),
- (101, "Input should be less than or equal to 100"),
- ],
- ids=["min_limit", "max_limit"],
- )
- def test_pagerank_invalid(self, add_dataset_func, pagerank, expected_message):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"pagerank": pagerank})
- error_message = str(exception_info.value)
- if IS_GO_PROXY and pagerank == -1 and "less than or equal to 100" in error_message:
- pytest.skip("Go dataset update applies the wrong pagerank bound error for negative values")
- assert expected_message in error_message, error_message
-
- @pytest.mark.p3
- def test_pagerank_none(self, add_dataset_func):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"pagerank": None})
- assert "Input should be a valid integer" in str(exception_info.value), str(exception_info.value)
+ original = dataset.parser_id
+ with pytest.raises(Exception, match=message):
+ dataset.update(payload)
+ assert client.list_datasets(id=dataset.id)[0].parser_id == original
+
+ def test_pipeline_mode_and_switch_back(self, client, add_dataset_func, integration_settings):
+ pipeline_id = integration_settings.get("pipeline_id")
+ version_id = integration_settings.get("pipeline_version_id")
+ if not pipeline_id or not version_id:
+ pytest.fail("Set RAGFLOW_SDK_PIPELINE_ID and RAGFLOW_SDK_PIPELINE_VERSION_ID to an accessible versioned ingestion pipeline")
+ dataset = add_dataset_func
+ dataset.update({"parse_type": 2, "pipeline_id": pipeline_id, "pipeline_version_id": version_id})
+ assert dataset.parse_type == 2
+ assert dataset.pipeline_id == pipeline_id
+ assert client.list_datasets(id=dataset.id)[0].pipeline_id == pipeline_id
+ dataset.update({"parse_type": 1, "parser_id": "general"})
+ assert dataset.parse_type == 1
+ assert dataset.pipeline_id is None
+ retrieved = client.list_datasets(id=dataset.id)[0]
+ assert retrieved.parse_type == 1
+ assert retrieved.pipeline_id is None
+
+ def test_pagerank(self, client, add_dataset_func, integration_settings):
+ engine = integration_settings.get("doc_engine")
+ if not engine:
+ pytest.fail("Set RAGFLOW_SDK_DOC_ENGINE for pagerank capability coverage")
+ dataset = add_dataset_func
+ if engine == "infinity":
+ with pytest.raises(Exception, match="can only be set when doc_engine is elasticsearch"):
+ dataset.update({"pagerank": 50})
+ assert client.list_datasets(id=dataset.id)[0].pagerank == 0
+ return
+ if engine not in {"elasticsearch", "oceanbase", "seekdb", "vastbase", "serenedb"}:
+ pytest.fail(f"Unrecognized pagerank engine configuration: {engine}")
+ for value in [50, 100, 0]:
+ dataset.update({"pagerank": value})
+ assert dataset.pagerank == value
+ assert client.list_datasets(id=dataset.id)[0].pagerank == value
- @pytest.mark.p1
- @pytest.mark.parametrize(
- "parser_config",
- [
- {"auto_keywords": 0},
- {"auto_keywords": 16},
- {"auto_keywords": 32},
- {"auto_questions": 0},
- {"auto_questions": 5},
- {"auto_questions": 10},
- {"chunk_token_num": 1},
- {"chunk_token_num": 1024},
- {"chunk_token_num": 2048},
- {"delimiter": "\n"},
- {"delimiter": " "},
- {"html4excel": True},
- {"html4excel": False},
- {"layout_recognize": "DeepDOC"},
- {"layout_recognize": "Plain Text"},
- {"tag_kb_ids": ["1", "2"]},
- {"topn_tags": 1},
- {"topn_tags": 5},
- {"topn_tags": 10},
- {"filename_embd_weight": 0.1},
- {"filename_embd_weight": 0.5},
- {"filename_embd_weight": 1.0},
- {"task_page_size": 1},
- {"task_page_size": None},
- {"pages": [[1, 100]]},
- {"pages": None},
- {"graphrag": {"use_graphrag": True}},
- {"graphrag": {"use_graphrag": False}},
- {"graphrag": {"entity_types": ["age", "sex", "height", "weight"]}},
- {"graphrag": {"method": "general"}},
- {"graphrag": {"method": "light"}},
- {"graphrag": {"community": True}},
- {"graphrag": {"community": False}},
- {"graphrag": {"resolution": True}},
- {"graphrag": {"resolution": False}},
- {"raptor": {"use_raptor": True}},
- {"raptor": {"use_raptor": False}},
- {"raptor": {"prompt": "Who are you?"}},
- {"raptor": {"max_token": 512}},
- {"raptor": {"max_token": 1024}},
- {"raptor": {"max_token": 2048}},
- {"raptor": {"clustering_threshold": 0.0}},
- {"raptor": {"clustering_threshold": 0.5}},
- {"raptor": {"clustering_threshold": 1.0}},
- {"raptor": {"max_cluster": 1}},
- {"raptor": {"max_cluster": 512}},
- {"raptor": {"max_cluster": 1024}},
- {"raptor": {"random_seed": 0}},
- ],
- ids=[
- "auto_keywords_min",
- "auto_keywords_mid",
- "auto_keywords_max",
- "auto_questions_min",
- "auto_questions_mid",
- "auto_questions_max",
- "chunk_token_num_min",
- "chunk_token_num_mid",
- "chunk_token_num_max",
- "delimiter",
- "delimiter_space",
- "html4excel_true",
- "html4excel_false",
- "layout_recognize_DeepDOC",
- "layout_recognize_navie",
- "tag_kb_ids",
- "topn_tags_min",
- "topn_tags_mid",
- "topn_tags_max",
- "filename_embd_weight_min",
- "filename_embd_weight_mid",
- "filename_embd_weight_max",
- "task_page_size_min",
- "task_page_size_None",
- "pages",
- "pages_none",
- "graphrag_true",
- "graphrag_false",
- "graphrag_entity_types",
- "graphrag_method_general",
- "graphrag_method_light",
- "graphrag_community_true",
- "graphrag_community_false",
- "graphrag_resolution_true",
- "graphrag_resolution_false",
- "raptor_true",
- "raptor_false",
- "raptor_prompt",
- "raptor_max_token_min",
- "raptor_max_token_mid",
- "raptor_max_token_max",
- "raptor_clustering_threshold_min",
- "raptor_clustering_threshold_mid",
- "raptor_clustering_threshold_max",
- "raptor_max_cluster_min",
- "raptor_max_cluster_mid",
- "raptor_max_cluster_max",
- "raptor_random_seed_min",
- ],
- )
- def test_parser_config(self, client, add_dataset_func, parser_config):
- dataset = add_dataset_func
- dataset.update({"parser_config": parser_config})
- for k, v in parser_config.items():
- if k in {"graphrag", "raptor"}:
- assert not hasattr(dataset.parser_config, k), str(dataset)
- continue
- if isinstance(v, dict):
- for kk, vv in v.items():
- assert attrgetter(f"{k}.{kk}")(dataset.parser_config) == vv, str(dataset)
- else:
- assert attrgetter(k)(dataset.parser_config) == v, str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- for k, v in parser_config.items():
- if k in {"graphrag", "raptor"}:
- assert not hasattr(retrieved_dataset.parser_config, k), str(retrieved_dataset)
- continue
- if isinstance(v, dict):
- for kk, vv in v.items():
- assert attrgetter(f"{k}.{kk}")(retrieved_dataset.parser_config) == vv, str(retrieved_dataset)
- else:
- assert attrgetter(k)(retrieved_dataset.parser_config) == v, str(retrieved_dataset)
-
- @pytest.mark.p2
@pytest.mark.parametrize(
- "parser_config, expected_message",
+ "pagerank,message",
[
- ({"auto_keywords": -1}, "Input should be greater than or equal to 0"),
- ({"auto_keywords": 33}, "Input should be less than or equal to 32"),
- ({"auto_keywords": 3.14}, "Input should be a valid integer"),
- ({"auto_keywords": "string"}, "Input should be a valid integer"),
- ({"auto_questions": -1}, "Input should be greater than or equal to 0"),
- ({"auto_questions": 11}, "Input should be less than or equal to 10"),
- ({"auto_questions": 3.14}, "Input should be a valid integer"),
- ({"auto_questions": "string"}, "Input should be a valid integer"),
- ({"chunk_token_num": 0}, "Input should be greater than or equal to 1"),
- ({"chunk_token_num": 2049}, "Input should be less than or equal to 2048"),
- ({"chunk_token_num": 3.14}, "Input should be a valid integer"),
- ({"chunk_token_num": "string"}, "Input should be a valid integer"),
- ({"delimiter": ""}, "String should have at least 1 character"),
- ({"html4excel": "string"}, "Input should be a valid boolean"),
- ({"tag_kb_ids": "1,2"}, "Input should be a valid list"),
- ({"tag_kb_ids": [1, 2]}, "Input should be a valid string"),
- ({"topn_tags": 0}, "Input should be greater than or equal to 1"),
- ({"topn_tags": 11}, "Input should be less than or equal to 10"),
- ({"topn_tags": 3.14}, "Input should be a valid integer"),
- ({"topn_tags": "string"}, "Input should be a valid integer"),
- ({"filename_embd_weight": -1}, "Input should be greater than or equal to 0"),
- ({"filename_embd_weight": 1.1}, "Input should be less than or equal to 1"),
- ({"filename_embd_weight": "string"}, "Input should be a valid number"),
- ({"task_page_size": 0}, "Input should be greater than or equal to 1"),
- ({"task_page_size": 3.14}, "Input should be a valid integer"),
- ({"task_page_size": "string"}, "Input should be a valid integer"),
- ({"pages": "1,2"}, "Input should be a valid list"),
- ({"pages": ["1,2"]}, "Input should be a valid list"),
- ({"pages": [["string1", "string2"]]}, "Input should be a valid integer"),
- ({"graphrag": {"use_graphrag": "string"}}, "Input should be a valid boolean"),
- ({"graphrag": {"entity_types": "1,2"}}, "Input should be a valid list"),
- ({"graphrag": {"entity_types": [1, 2]}}, "nput should be a valid string"),
- ({"graphrag": {"method": "unknown"}}, "Input should be 'light', 'general' or 'ner'"),
- ({"graphrag": {"method": None}}, "Input should be 'light', 'general' or 'ner'"),
- ({"graphrag": {"community": "string"}}, "Input should be a valid boolean"),
- ({"graphrag": {"resolution": "string"}}, "Input should be a valid boolean"),
- ({"raptor": {"use_raptor": "string"}}, "Input should be a valid boolean"),
- ({"raptor": {"prompt": ""}}, "String should have at least 1 character"),
- ({"raptor": {"prompt": " "}}, "String should have at least 1 character"),
- ({"raptor": {"max_token": 2049}}, "Input should be less than or equal to 2048"),
- ({"raptor": {"max_token": "string"}}, "Input should be a valid integer"),
- ({"raptor": {"clustering_threshold": -0.1}}, "Input should be greater than or equal to 0"),
- ({"raptor": {"clustering_threshold": 1.1}}, "Input should be less than or equal to 1"),
- ({"raptor": {"clustering_threshold": "string"}}, "Input should be a valid number"),
- ({"raptor": {"max_cluster": 0}}, "Input should be greater than or equal to 1"),
- ({"raptor": {"max_cluster": 1025}}, "Input should be less than or equal to 1024"),
- ({"raptor": {"max_cluster": 3.14}}, "Input should be a valid integer"),
- ({"raptor": {"max_cluster": "string"}}, "Input should be a valid integer"),
- ({"raptor": {"random_seed": -1}}, "Input should be greater than or equal to 0"),
- ({"raptor": {"random_seed": 3.14}}, "Input should be a valid integer"),
- ({"raptor": {"random_seed": "string"}}, "Input should be a valid integer"),
- ({"delimiter": "a" * 65536}, "Parser config exceeds size limit (max 65,535 characters)"),
- ],
- ids=[
- "auto_keywords_min_limit",
- "auto_keywords_max_limit",
- "auto_keywords_float_not_allowed",
- "auto_keywords_type_invalid",
- "auto_questions_min_limit",
- "auto_questions_max_limit",
- "auto_questions_float_not_allowed",
- "auto_questions_type_invalid",
- "chunk_token_num_min_limit",
- "chunk_token_num_max_limit",
- "chunk_token_num_float_not_allowed",
- "chunk_token_num_type_invalid",
- "delimiter_empty",
- "html4excel_type_invalid",
- "tag_kb_ids_not_list",
- "tag_kb_ids_int_in_list",
- "topn_tags_min_limit",
- "topn_tags_max_limit",
- "topn_tags_float_not_allowed",
- "topn_tags_type_invalid",
- "filename_embd_weight_min_limit",
- "filename_embd_weight_max_limit",
- "filename_embd_weight_type_invalid",
- "task_page_size_min_limit",
- "task_page_size_float_not_allowed",
- "task_page_size_type_invalid",
- "pages_not_list",
- "pages_not_list_in_list",
- "pages_not_int_list",
- "graphrag_type_invalid",
- "graphrag_entity_types_not_list",
- "graphrag_entity_types_not_str_in_list",
- "graphrag_method_unknown",
- "graphrag_method_none",
- "graphrag_community_type_invalid",
- "graphrag_resolution_type_invalid",
- "raptor_type_invalid",
- "raptor_prompt_empty",
- "raptor_prompt_space",
- "raptor_max_token_max_limit",
- "raptor_max_token_type_invalid",
- "raptor_clustering_threshold_min_limit",
- "raptor_clustering_threshold_max_limit",
- "raptor_clustering_threshold_type_invalid",
- "raptor_max_cluster_min_limit",
- "raptor_max_cluster_max_limit",
- "raptor_max_cluster_float_not_allowed",
- "raptor_max_cluster_type_invalid",
- "raptor_random_seed_min_limit",
- "raptor_random_seed_float_not_allowed",
- "raptor_random_seed_type_invalid",
- "parser_config_type_invalid",
+ pytest.param(
+ -1,
+ "greater than or equal to 0",
+ marks=pytest.mark.skip(reason="internal/service/dataset/update.go reports the upper bound for negative pagerank; preserve the correct lower-bound diagnostic"),
+ ),
+ (101, "less than or equal to 100"),
+ (3.14, "cannot unmarshal"),
+ ("invalid", "cannot unmarshal"),
],
)
- def test_parser_config_invalid(self, add_dataset_func, parser_config, expected_message):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update({"parser_config": parser_config})
- assert expected_message in str(exception_info.value), str(exception_info.value)
-
- @pytest.mark.p2
- def test_parser_config_empty(self, client, add_dataset_func):
- dataset = add_dataset_func
- expected_config = DataSet.ParserConfig(
- client,
- DEFAULT_PARSER_CONFIG,
- )
- dataset.update({"parser_config": {}})
- assert str(dataset.parser_config) == str(expected_config), str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert str(retrieved_dataset.parser_config) == str(expected_config), str(retrieved_dataset)
-
- @pytest.mark.p3
- def test_parser_config_none(self, client, add_dataset_func):
- dataset = add_dataset_func
- expected_config = DataSet.ParserConfig(
- client,
- DEFAULT_PARSER_CONFIG,
- )
- dataset.update({"parser_config": None})
- assert str(dataset.parser_config) == str(expected_config), str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert str(retrieved_dataset.parser_config) == str(expected_config), str(retrieved_dataset)
-
- @pytest.mark.p3
- def test_parser_config_empty_with_chunk_method_change(self, client, add_dataset_func):
- dataset = add_dataset_func
- expected_config = DataSet.ParserConfig(
- client,
- {
- "image_context_size": 0,
- "table_context_size": 0,
- },
- )
- dataset.update({"chunk_method": "qa", "parser_config": {}})
- assert str(dataset.parser_config) == str(expected_config), str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert str(retrieved_dataset.parser_config) == str(expected_config), str(retrieved_dataset)
-
- @pytest.mark.p3
- def test_parser_config_unset_with_chunk_method_change(self, client, add_dataset_func):
- dataset = add_dataset_func
- expected_config = DataSet.ParserConfig(
- client,
- {
- "image_context_size": 0,
- "table_context_size": 0,
- },
- )
- dataset.update({"chunk_method": "qa"})
- assert str(dataset.parser_config) == str(expected_config), str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert str(retrieved_dataset.parser_config) == str(expected_config), str(retrieved_dataset)
+ def test_pagerank_invalid(self, add_dataset_func, pagerank, message):
+ with pytest.raises(Exception, match=message):
+ add_dataset_func.update({"pagerank": pagerank})
+
+ @pytest.mark.parametrize("size", [128, 1024])
+ def test_component_parser_config(self, client, add_dataset_func, size):
+ dataset = add_dataset_func
+ key = "GeneralChunker:SixApplesFall"
+ dataset.update({"parser_config": {key: {"chunk_token_size": size}}})
+ assert dataset.parser_config.to_json()[key]["chunk_token_size"] == size
+ assert client.list_datasets(id=dataset.id)[0].parser_config.to_json()[key]["chunk_token_size"] == size
+
+ @pytest.mark.parametrize("config", [{}, None, {"chunk_token_num": 64, "graphrag": {"use_graphrag": True}}])
+ def test_parser_config_empty_or_unscoped(self, client, add_dataset_func, config):
+ dataset = add_dataset_func
+ original = dataset.parser_config.to_json()
+ dataset.update({"parser_config": config})
+ assert dataset.parser_config.to_json() == original
+ assert client.list_datasets(id=dataset.id)[0].parser_config.to_json() == original
+
+ @pytest.mark.parametrize("config", [[], "invalid", 1])
+ def test_parser_config_invalid(self, add_dataset_func, config):
+ with pytest.raises(Exception, match="cannot unmarshal"):
+ add_dataset_func.update({"parser_config": config})
+
+ def test_parser_config_size_limit(self, add_dataset_func):
+ with pytest.raises(Exception, match="exceeds size limit"):
+ add_dataset_func.update({"parser_config": {"GeneralChunker:SixApplesFall": {"delimiters": ["a" * 65536]}}})
+
+ @pytest.mark.parametrize("config", [{}, None, "omit"])
+ def test_parser_config_with_parser_change(self, client, add_dataset_func, config):
+ dataset = add_dataset_func
+ dataset.update({"parser_config": {"GeneralChunker:SixApplesFall": {"chunk_token_size": 1024}}})
+ payload = {"parse_type": 1, "parser_id": "qa"}
+ if config != "omit":
+ payload["parser_config"] = config
+ dataset.update(payload)
+ assert dataset.parser_id == "qa"
+ assert "GeneralChunker:SixApplesFall" not in dataset.parser_config.to_json()
+ retrieved = client.list_datasets(id=dataset.id)[0]
+ assert retrieved.parser_id == "qa"
+ assert retrieved.parser_config.to_json() == dataset.parser_config.to_json()
- @pytest.mark.p3
- def test_parser_config_none_with_chunk_method_change(self, client, add_dataset_func):
- dataset = add_dataset_func
- expected_config = DataSet.ParserConfig(
- client,
- {
- "image_context_size": 0,
- "table_context_size": 0,
- },
- )
- dataset.update({"chunk_method": "qa", "parser_config": None})
- assert str(dataset.parser_config) == str(expected_config), str(dataset)
-
- retrieved_dataset = client.get_dataset(name=dataset.name)
- assert str(retrieved_dataset.parser_config) == str(expected_config), str(retrieved_dataset)
-
- @pytest.mark.p2
@pytest.mark.parametrize(
- "payload",
+ "field",
[
- {"id": "id"},
- {"tenant_id": "e57c1966f99211efb41e9e45646e0111"},
- {"created_by": "created_by"},
- {"create_date": "Tue, 11 Mar 2025 13:37:23 GMT"},
- {"create_time": 1741671443322},
- {"update_date": "Tue, 11 Mar 2025 13:37:23 GMT"},
- {"update_time": 1741671443339},
- {"document_count": 1},
- {"chunk_count": 1},
- {"token_num": 1},
- {"status": "1"},
- {"unknown_field": "unknown_field"},
+ "id",
+ "tenant_id",
+ "created_by",
+ "create_date",
+ "create_time",
+ "update_date",
+ "update_time",
+ "document_count",
+ "chunk_count",
+ "token_num",
+ "status",
+ "unknown_field",
],
)
- def test_field_unsupported(self, add_dataset_func, payload):
- dataset = add_dataset_func
- with pytest.raises(Exception) as exception_info:
- dataset.update(payload)
- assert "Extra inputs are not permitted" in str(exception_info.value), str(exception_info.value)
+ def test_field_unsupported(self, add_dataset_func, field):
+ with pytest.raises(Exception, match=f"Extra inputs are not permitted: {field}"):
+ add_dataset_func.update({field: "unsupported"})
- @pytest.mark.p2
def test_field_unset(self, client, add_dataset_func):
dataset = add_dataset_func
- original_dataset = client.get_dataset(name=dataset.name)
-
- dataset.update({"name": "default_unset"})
-
- updated_dataset = client.get_dataset(name="default_unset")
- assert updated_dataset.avatar == original_dataset.avatar, str(updated_dataset)
- assert updated_dataset.description == original_dataset.description, str(updated_dataset)
- assert updated_dataset.embedding_model == original_dataset.embedding_model, str(updated_dataset)
- assert updated_dataset.permission == original_dataset.permission, str(updated_dataset)
- assert updated_dataset.chunk_method == original_dataset.chunk_method, str(updated_dataset)
- assert updated_dataset.pagerank == original_dataset.pagerank, str(updated_dataset)
- assert str(updated_dataset.parser_config) == str(original_dataset.parser_config), str(updated_dataset)
+ fields = ["avatar", "description", "embedding_model", "permission", "parser_id", "pipeline_id", "pagerank", "language"]
+ original = client.list_datasets(id=dataset.id)[0]
+ config = original.parser_config.to_json()
+ name = f"sdk-renamed-{uuid4().hex}"
+ dataset.update({"name": name})
+ updated = client.list_datasets(id=dataset.id)[0]
+ assert updated.name == name
+ for field in fields:
+ assert getattr(updated, field) == getattr(original, field), field
+ assert updated.parser_config.to_json() == config
+
+ def test_update_requires_authentication(self, client, add_dataset_func, integration_settings):
+ dataset = add_dataset_func
+ original = dataset.name
+ unauthorized = RAGFlow(api_key="invalid-sdk-test-token", base_url=integration_settings["base_url"])
+ untrusted_dataset = DataSet(unauthorized, {"id": dataset.id})
+ with pytest.raises(Exception, match="(?i)(unauthorized|authorization|api.?key|token|authentication)"):
+ untrusted_dataset.update({"name": f"sdk-denied-{uuid4().hex}"})
+ assert client.list_datasets(id=dataset.id)[0].name == original