Add test for API (#3134)

### What problem does this PR solve?

Add test for API

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
Co-authored-by: Zhichang Yu <yuzhichang@gmail.com>
This commit is contained in:
liuhua
2024-11-01 22:59:17 +08:00
committed by GitHub
parent 7eafccf78a
commit 44ad9a6cd7
10 changed files with 292 additions and 355 deletions

View File

@ -1,9 +1,7 @@
import os
from ragflow_sdk import RAGFlow
import random
import pytest
from ragflow_sdk import RAGFlow
HOST_ADDRESS = os.getenv('HOST_ADDRESS', 'http://127.0.0.1:9380')
from common import HOST_ADDRESS
def test_create_dataset_with_name(get_api_key_fixture):
API_KEY = get_api_key_fixture
@ -13,8 +11,9 @@ def test_create_dataset_with_name(get_api_key_fixture):
def test_create_dataset_with_duplicated_name(get_api_key_fixture):
API_KEY = get_api_key_fixture
rag = RAGFlow(API_KEY, HOST_ADDRESS)
rag.create_dataset("test_create_dataset_with_duplicated_name")
with pytest.raises(Exception) as exc_info:
rag.create_dataset("test_create_dataset_with_name")
rag.create_dataset("test_create_dataset_with_duplicated_name")
assert str(exc_info.value) == "Duplicated dataset name in creating dataset."
def test_create_dataset_with_random_chunk_method(get_api_key_fixture):
@ -31,7 +30,7 @@ def test_create_dataset_with_invalid_parameter(get_api_key_fixture):
"knowledge_graph", "email"]
chunk_method = "invalid_chunk_method"
with pytest.raises(Exception) as exc_info:
rag.create_dataset("test_create_dataset_with_name",chunk_method=chunk_method)
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}"
@ -45,7 +44,7 @@ def test_update_dataset_with_name(get_api_key_fixture):
def test_delete_datasets_with_success(get_api_key_fixture):
API_KEY = get_api_key_fixture
rag = RAGFlow(API_KEY, HOST_ADDRESS)
ds = rag.create_dataset("MA")
ds = rag.create_dataset("test_delete_dataset")
rag.delete_datasets(ids=[ds.id])