mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Refa: http API create dataset and test cases (#7393)
### What problem does this PR solve? This PR introduces Pydantic-based validation for the create dataset HTTP API, improving code clarity and robustness. Key changes include: 1. Pydantic Validation 2. Error Handling 3. Test Updates 4. Documentation ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] Documentation Update - [x] Refactoring
This commit is contained in:
@ -14,10 +14,11 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
from ragflow_sdk import RAGFlow
|
||||
import random
|
||||
|
||||
import pytest
|
||||
from common import HOST_ADDRESS
|
||||
from ragflow_sdk import RAGFlow
|
||||
|
||||
|
||||
def test_create_dataset_with_name(get_api_key_fixture):
|
||||
@ -32,7 +33,7 @@ def test_create_dataset_with_duplicated_name(get_api_key_fixture):
|
||||
rag.create_dataset("test_create_dataset_with_duplicated_name")
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
rag.create_dataset("test_create_dataset_with_duplicated_name")
|
||||
assert str(exc_info.value) == "Duplicated dataset name in creating dataset."
|
||||
assert str(exc_info.value) == "Dataset name 'test_create_dataset_with_duplicated_name' already exists"
|
||||
|
||||
|
||||
def test_create_dataset_with_random_chunk_method(get_api_key_fixture):
|
||||
@ -46,11 +47,13 @@ def test_create_dataset_with_random_chunk_method(get_api_key_fixture):
|
||||
def test_create_dataset_with_invalid_parameter(get_api_key_fixture):
|
||||
API_KEY = get_api_key_fixture
|
||||
rag = RAGFlow(API_KEY, HOST_ADDRESS)
|
||||
valid_chunk_methods = ["naive", "manual", "qa", "table", "paper", "book", "laws", "presentation", "picture", "one", "email", "tag"]
|
||||
chunk_method = "invalid_chunk_method"
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
rag.create_dataset("test_create_dataset_with_invalid_chunk_method", chunk_method=chunk_method)
|
||||
assert str(exc_info.value) == f"'{chunk_method}' is not in {valid_chunk_methods}"
|
||||
assert (
|
||||
str(exc_info.value)
|
||||
== f"Field: <chunk_method> - Message: <Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'> - Value: <{chunk_method}>"
|
||||
)
|
||||
|
||||
|
||||
def test_update_dataset_with_name(get_api_key_fixture):
|
||||
|
||||
Reference in New Issue
Block a user