mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Test: add sdk Document test cases (#8094)
### What problem does this PR solve? Add sdk document test cases ### Type of change - [x] Add test cases
This commit is contained in:
@ -85,6 +85,7 @@ class TestCapability:
|
||||
futures = [executor.submit(create_dataset, api_key, {"name": f"dataset_{i}"}) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("clear_datasets")
|
||||
|
||||
@ -93,6 +93,7 @@ class TestCapability:
|
||||
futures = [executor.submit(delete_datasets, api_key, {"ids": ids[i : i + 1]}) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
|
||||
class TestDatasetsDelete:
|
||||
|
||||
@ -49,6 +49,7 @@ class TestCapability:
|
||||
futures = [executor.submit(list_datasets, api_key) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("add_datasets")
|
||||
|
||||
@ -95,6 +95,7 @@ class TestCapability:
|
||||
futures = [executor.submit(update_dataset, api_key, dataset_id, {"name": f"dataset_{i}"}) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
|
||||
class TestDatasetUpdate:
|
||||
|
||||
@ -25,7 +25,7 @@ def add_document_func(request, api_key, add_dataset, ragflow_tmp_dir):
|
||||
document_ids = bulk_upload_documents(api_key, dataset_id, 1, ragflow_tmp_dir)
|
||||
|
||||
def cleanup():
|
||||
delete_documents(api_key, dataset_id, {"ids": document_ids})
|
||||
delete_documents(api_key, dataset_id, {"ids": None})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return dataset_id, document_ids[0]
|
||||
@ -37,7 +37,7 @@ def add_documents(request, api_key, add_dataset, ragflow_tmp_dir):
|
||||
document_ids = bulk_upload_documents(api_key, dataset_id, 5, ragflow_tmp_dir)
|
||||
|
||||
def cleanup():
|
||||
delete_documents(api_key, dataset_id, {"ids": document_ids})
|
||||
delete_documents(api_key, dataset_id, {"ids": None})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return dataset_id, document_ids
|
||||
@ -49,7 +49,7 @@ def add_documents_func(request, api_key, add_dataset_func, ragflow_tmp_dir):
|
||||
document_ids = bulk_upload_documents(api_key, dataset_id, 3, ragflow_tmp_dir)
|
||||
|
||||
def cleanup():
|
||||
delete_documents(api_key, dataset_id, {"ids": document_ids})
|
||||
delete_documents(api_key, dataset_id, {"ids": None})
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
return dataset_id, document_ids
|
||||
|
||||
@ -13,7 +13,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
|
||||
import pytest
|
||||
from common import INVALID_API_TOKEN, bulk_upload_documents, delete_documents, list_documents
|
||||
@ -148,9 +149,9 @@ class TestDocumentsDeletion:
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_concurrent_deletion(api_key, add_dataset, tmp_path):
|
||||
documents_num = 100
|
||||
count = 100
|
||||
dataset_id = add_dataset
|
||||
document_ids = bulk_upload_documents(api_key, dataset_id, documents_num, tmp_path)
|
||||
document_ids = bulk_upload_documents(api_key, dataset_id, count, tmp_path)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [
|
||||
@ -160,10 +161,11 @@ def test_concurrent_deletion(api_key, add_dataset, tmp_path):
|
||||
dataset_id,
|
||||
{"ids": document_ids[i : i + 1]},
|
||||
)
|
||||
for i in range(documents_num)
|
||||
for i in range(count)
|
||||
]
|
||||
responses = [f.result() for f in futures]
|
||||
assert all(r["code"] == 0 for r in responses)
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
|
||||
@pytest.mark.p3
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from common import INVALID_API_TOKEN, list_documents
|
||||
@ -342,11 +342,13 @@ class TestDocumentsList:
|
||||
@pytest.mark.p3
|
||||
def test_concurrent_list(self, api_key, add_documents):
|
||||
dataset_id, _ = add_documents
|
||||
count = 100
|
||||
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [executor.submit(list_documents, api_key, dataset_id) for i in range(100)]
|
||||
responses = [f.result() for f in futures]
|
||||
assert all(r["code"] == 0 for r in responses)
|
||||
futures = [executor.submit(list_documents, api_key, dataset_id) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
@pytest.mark.p3
|
||||
def test_invalid_params(self, api_key, add_documents):
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
import pytest
|
||||
from common import INVALID_API_TOKEN, bulk_upload_documents, list_documents, parse_documents
|
||||
@ -195,9 +195,9 @@ def test_concurrent_parse(api_key, add_dataset_func, tmp_path):
|
||||
return False
|
||||
return True
|
||||
|
||||
document_num = 100
|
||||
count = 100
|
||||
dataset_id = add_dataset_func
|
||||
document_ids = bulk_upload_documents(api_key, dataset_id, document_num, tmp_path)
|
||||
document_ids = bulk_upload_documents(api_key, dataset_id, count, tmp_path)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||
futures = [
|
||||
@ -207,11 +207,12 @@ def test_concurrent_parse(api_key, add_dataset_func, tmp_path):
|
||||
dataset_id,
|
||||
{"document_ids": document_ids[i : i + 1]},
|
||||
)
|
||||
for i in range(document_num)
|
||||
for i in range(count)
|
||||
]
|
||||
responses = [f.result() for f in futures]
|
||||
assert all(r["code"] == 0 for r in responses)
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
condition(api_key, dataset_id, document_num)
|
||||
condition(api_key, dataset_id, count)
|
||||
|
||||
validate_document_details(api_key, dataset_id, document_ids)
|
||||
|
||||
@ -213,6 +213,7 @@ class TestDocumentsUpload:
|
||||
futures = [executor.submit(upload_documents, api_key, dataset_id, fps[i : i + 1]) for i in range(count)]
|
||||
responses = list(as_completed(futures))
|
||||
assert len(responses) == count, responses
|
||||
assert all(futures.result()["code"] == 0 for futures in futures)
|
||||
|
||||
res = list_datasets(api_key, {"id": dataset_id})
|
||||
assert res["data"][0]["document_count"] == count
|
||||
|
||||
Reference in New Issue
Block a user