|
|
|
@@ -34,10 +34,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_two_files") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert res['code'] == RetCode.SUCCESS and res['message'] == 'success' |
|
|
|
assert res["code"] == RetCode.SUCCESS and res["message"] == "success" |
|
|
|
|
|
|
|
def test_upload_one_file(self): |
|
|
|
""" |
|
|
|
@@ -45,10 +45,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_one_file") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert res['code'] == RetCode.SUCCESS and res['message'] == 'success' |
|
|
|
assert res["code"] == RetCode.SUCCESS and res["message"] == "success" |
|
|
|
|
|
|
|
def test_upload_nonexistent_files(self): |
|
|
|
""" |
|
|
|
@@ -56,10 +56,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_nonexistent_files") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/imagination.txt"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert res['code'] == RetCode.DATA_ERROR and "does not exist" in res['message'] |
|
|
|
assert res["code"] == RetCode.DATA_ERROR and "does not exist" in res["message"] |
|
|
|
|
|
|
|
def test_upload_file_if_dataset_does_not_exist(self): |
|
|
|
""" |
|
|
|
@@ -68,7 +68,7 @@ class TestFile(TestSdk): |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
res = ragflow.upload_local_file("111", file_paths) |
|
|
|
assert res['code'] == RetCode.DATA_ERROR and res['message'] == "Can't find this dataset" |
|
|
|
assert res["code"] == RetCode.DATA_ERROR and res["message"] == "Can't find this dataset" |
|
|
|
|
|
|
|
def test_upload_file_without_name(self): |
|
|
|
""" |
|
|
|
@@ -76,10 +76,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_file_without_name") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/.txt"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert res['code'] == RetCode.SUCCESS |
|
|
|
assert res["code"] == RetCode.SUCCESS |
|
|
|
|
|
|
|
def test_upload_file_without_name1(self): |
|
|
|
""" |
|
|
|
@@ -87,10 +87,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_file_without_name") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/.txt", "test_data/empty.txt"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert res['code'] == RetCode.SUCCESS |
|
|
|
assert res["code"] == RetCode.SUCCESS |
|
|
|
|
|
|
|
def test_upload_files_exceeding_the_number_limit(self): |
|
|
|
""" |
|
|
|
@@ -98,12 +98,12 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_files_exceeding_the_number_limit") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] * 256 |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert (res['message'] == |
|
|
|
'You try to upload 512 files, which exceeds the maximum number of uploading files: 256' |
|
|
|
and res['code'] == RetCode.DATA_ERROR) |
|
|
|
assert (res["message"] == |
|
|
|
"You try to upload 512 files, which exceeds the maximum number of uploading files: 256" |
|
|
|
and res["code"] == RetCode.DATA_ERROR) |
|
|
|
|
|
|
|
def test_upload_files_without_files(self): |
|
|
|
""" |
|
|
|
@@ -111,10 +111,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_files_without_files") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = [None] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert (res['message'] == 'None is not string.' and res['code'] == RetCode.ARGUMENT_ERROR) |
|
|
|
assert (res["message"] == "None is not string." and res["code"] == RetCode.ARGUMENT_ERROR) |
|
|
|
|
|
|
|
def test_upload_files_with_two_files_with_same_name(self): |
|
|
|
""" |
|
|
|
@@ -122,10 +122,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_files_with_two_files_with_same_name") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
file_paths = ['test_data/test.txt'] * 2 |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] * 2 |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert (res['message'] == 'success' and res['code'] == RetCode.SUCCESS) |
|
|
|
assert (res["message"] == "success" and res["code"] == RetCode.SUCCESS) |
|
|
|
|
|
|
|
def test_upload_files_with_file_paths(self): |
|
|
|
""" |
|
|
|
@@ -133,10 +133,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_files_with_file_paths") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
file_paths = ['test_data/'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert (res['message'] == 'The file test_data/ does not exist' and res['code'] == RetCode.DATA_ERROR) |
|
|
|
assert (res["message"] == "The file test_data/ does not exist" and res["code"] == RetCode.DATA_ERROR) |
|
|
|
|
|
|
|
def test_upload_files_with_remote_file_path(self): |
|
|
|
""" |
|
|
|
@@ -144,10 +144,10 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_upload_files_with_remote_file_path") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
file_paths = ['https://github.com/genostack/ragflow'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["https://github.com/genostack/ragflow"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
assert res['code'] == RetCode.ARGUMENT_ERROR and res['message'] == 'Remote files have not unsupported.' |
|
|
|
assert res["code"] == RetCode.ARGUMENT_ERROR and res["message"] == "Remote files have not unsupported." |
|
|
|
|
|
|
|
# ----------------------------delete a file----------------------------------------------------- |
|
|
|
def test_delete_one_file(self): |
|
|
|
@@ -156,16 +156,16 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_delete_one_file") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = res['data'][0] |
|
|
|
doc_id = data['id'] |
|
|
|
data = res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# delete the files |
|
|
|
deleted_res = ragflow.delete_files(doc_id, dataset_id) |
|
|
|
# assert value |
|
|
|
assert deleted_res['code'] == RetCode.SUCCESS and deleted_res['data'] is True |
|
|
|
assert deleted_res["code"] == RetCode.SUCCESS and deleted_res["data"] is True |
|
|
|
|
|
|
|
def test_delete_document_with_not_existing_document(self): |
|
|
|
""" |
|
|
|
@@ -173,9 +173,9 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_delete_document_with_not_existing_document") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
res = ragflow.delete_files("111", dataset_id) |
|
|
|
assert res['code'] == RetCode.DATA_ERROR and res['message'] == 'Document 111 not found!' |
|
|
|
assert res["code"] == RetCode.DATA_ERROR and res["message"] == "Document 111 not found!" |
|
|
|
|
|
|
|
def test_delete_document_with_creating_100_documents_and_deleting_100_documents(self): |
|
|
|
""" |
|
|
|
@@ -184,18 +184,18 @@ class TestFile(TestSdk): |
|
|
|
# upload 100 docs |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_delete_one_file") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] * 100 |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
|
|
|
|
# get the doc_id |
|
|
|
data = res['data'] |
|
|
|
data = res["data"] |
|
|
|
for d in data: |
|
|
|
doc_id = d['id'] |
|
|
|
doc_id = d["id"] |
|
|
|
# delete the files |
|
|
|
deleted_res = ragflow.delete_files(doc_id, dataset_id) |
|
|
|
# assert value |
|
|
|
assert deleted_res['code'] == RetCode.SUCCESS and deleted_res['data'] is True |
|
|
|
assert deleted_res["code"] == RetCode.SUCCESS and deleted_res["data"] is True |
|
|
|
|
|
|
|
def test_delete_document_from_nonexistent_dataset(self): |
|
|
|
""" |
|
|
|
@@ -203,17 +203,17 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_delete_one_file") |
|
|
|
dataset_id = created_res['data']['dataset_id'] |
|
|
|
dataset_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
res = ragflow.upload_local_file(dataset_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = res['data'][0] |
|
|
|
doc_id = data['id'] |
|
|
|
data = res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# delete the files |
|
|
|
deleted_res = ragflow.delete_files(doc_id, "000") |
|
|
|
# assert value |
|
|
|
assert (deleted_res['code'] == RetCode.ARGUMENT_ERROR and deleted_res['message'] == |
|
|
|
f'The document {doc_id} is not in the dataset: 000, but in the dataset: {dataset_id}.') |
|
|
|
assert (deleted_res["code"] == RetCode.ARGUMENT_ERROR and deleted_res["message"] == |
|
|
|
f"The document {doc_id} is not in the dataset: 000, but in the dataset: {dataset_id}.") |
|
|
|
|
|
|
|
def test_delete_document_which_is_located_in_other_dataset(self): |
|
|
|
""" |
|
|
|
@@ -222,20 +222,20 @@ class TestFile(TestSdk): |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
# upload a document |
|
|
|
created_res = ragflow.create_dataset("test_delete_document_which_is_located_in_other_dataset") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# other dataset |
|
|
|
other_res = ragflow.create_dataset("other_dataset") |
|
|
|
other_dataset_id = other_res['data']['dataset_id'] |
|
|
|
other_dataset_id = other_res["data"]["dataset_id"] |
|
|
|
# get the doc_id |
|
|
|
data = res['data'][0] |
|
|
|
doc_id = data['id'] |
|
|
|
data = res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# delete the files from the other dataset |
|
|
|
deleted_res = ragflow.delete_files(doc_id, other_dataset_id) |
|
|
|
# assert value |
|
|
|
assert (deleted_res['code'] == RetCode.ARGUMENT_ERROR and deleted_res['message'] == |
|
|
|
f'The document {doc_id} is not in the dataset: {other_dataset_id}, but in the dataset: {created_res_id}.') |
|
|
|
assert (deleted_res["code"] == RetCode.ARGUMENT_ERROR and deleted_res["message"] == |
|
|
|
f"The document {doc_id} is not in the dataset: {other_dataset_id}, but in the dataset: {created_res_id}.") |
|
|
|
|
|
|
|
# ----------------------------list files----------------------------------------------------- |
|
|
|
def test_list_documents_with_success(self): |
|
|
|
@@ -245,12 +245,12 @@ class TestFile(TestSdk): |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
# upload a document |
|
|
|
created_res = ragflow.create_dataset("test_list_documents_with_success") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id) |
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 1 |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 1 |
|
|
|
|
|
|
|
def test_list_documents_with_checking_size(self): |
|
|
|
""" |
|
|
|
@@ -259,12 +259,12 @@ class TestFile(TestSdk): |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
# upload 10 documents |
|
|
|
created_res = ragflow.create_dataset("test_list_documents_with_checking_size") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] * 10 |
|
|
|
ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id) |
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 10 |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 10 |
|
|
|
|
|
|
|
def test_list_documents_with_getting_empty_result(self): |
|
|
|
""" |
|
|
|
@@ -273,10 +273,10 @@ class TestFile(TestSdk): |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
# upload 0 documents |
|
|
|
created_res = ragflow.create_dataset("test_list_documents_with_getting_empty_result") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id) |
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 0 |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 0 |
|
|
|
|
|
|
|
def test_list_documents_with_creating_100_documents(self): |
|
|
|
""" |
|
|
|
@@ -285,12 +285,12 @@ class TestFile(TestSdk): |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
# upload 100 documents |
|
|
|
created_res = ragflow.create_dataset("test_list_documents_with_creating_100_documents") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt"] * 100 |
|
|
|
ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id) |
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 100 |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 100 |
|
|
|
|
|
|
|
def test_list_document_with_failure(self): |
|
|
|
""" |
|
|
|
@@ -298,9 +298,9 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_list_document_with_failure") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
response = ragflow.list_files(created_res_id, offset=-1, count=-1) |
|
|
|
assert "IndexError" in response['message'] and response['code'] == RetCode.EXCEPTION_ERROR |
|
|
|
assert "IndexError" in response["message"] and response["code"] == RetCode.EXCEPTION_ERROR |
|
|
|
|
|
|
|
def test_list_document_with_verifying_offset_and_count(self): |
|
|
|
""" |
|
|
|
@@ -308,13 +308,13 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_list_document_with_verifying_offset_and_count") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt", "test_data/empty.txt"] * 10 |
|
|
|
ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id, offset=2, count=10) |
|
|
|
|
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 10 |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 10 |
|
|
|
|
|
|
|
def test_list_document_with_verifying_keywords(self): |
|
|
|
""" |
|
|
|
@@ -322,13 +322,13 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_list_document_with_verifying_keywords") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt", "test_data/empty.txt"] |
|
|
|
ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id, keywords="empty") |
|
|
|
|
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 1 |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 1 |
|
|
|
|
|
|
|
def test_list_document_with_verifying_order_by_and_descend(self): |
|
|
|
""" |
|
|
|
@@ -336,17 +336,17 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_list_document_with_verifying_order_by_and_descend") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt", "test_data/empty.txt"] |
|
|
|
ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id) |
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 2 |
|
|
|
docs = response['data']['docs'] |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 2 |
|
|
|
docs = response["data"]["docs"] |
|
|
|
# reverse |
|
|
|
i = 1 |
|
|
|
for doc in docs: |
|
|
|
assert doc['name'] in file_paths[i] |
|
|
|
assert doc["name"] in file_paths[i] |
|
|
|
i -= 1 |
|
|
|
|
|
|
|
def test_list_document_with_verifying_order_by_and_ascend(self): |
|
|
|
@@ -355,24 +355,277 @@ class TestFile(TestSdk): |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_list_document_with_verifying_order_by_and_ascend") |
|
|
|
created_res_id = created_res['data']['dataset_id'] |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt", "test_data/empty.txt"] |
|
|
|
ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# Call the list_document method |
|
|
|
response = ragflow.list_files(created_res_id, descend=False) |
|
|
|
assert response['code'] == RetCode.SUCCESS and len(response['data']['docs']) == 3 |
|
|
|
assert response["code"] == RetCode.SUCCESS and len(response["data"]["docs"]) == 3 |
|
|
|
|
|
|
|
docs = response['data']['docs'] |
|
|
|
docs = response["data"]["docs"] |
|
|
|
|
|
|
|
i = 0 |
|
|
|
for doc in docs: |
|
|
|
assert doc['name'] in file_paths[i] |
|
|
|
assert doc["name"] in file_paths[i] |
|
|
|
i += 1 |
|
|
|
|
|
|
|
# TODO: have to set the limitation of the number of documents |
|
|
|
# ----------------------------download a file----------------------------------------------------- |
|
|
|
# ----------------------------update files: enable, rename, template_type------------------------------------------- |
|
|
|
|
|
|
|
def test_update_nonexistent_document(self): |
|
|
|
""" |
|
|
|
Test updating a document which does not exist. |
|
|
|
""" |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_nonexistent_document") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
params = { |
|
|
|
"name": "new_name" |
|
|
|
} |
|
|
|
res = ragflow.update_file(created_res_id, "weird_doc_id", **params) |
|
|
|
assert res["code"] == RetCode.ARGUMENT_ERROR and res["message"] == f"This document weird_doc_id cannot be found!" |
|
|
|
|
|
|
|
def test_update_document_without_parameters(self): |
|
|
|
""" |
|
|
|
Test updating a document without giving parameters. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_without_parameters") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.DATA_ERROR and |
|
|
|
update_res["message"] == "Please input at least one parameter that you want to update!") |
|
|
|
|
|
|
|
def test_update_document_in_nonexistent_dataset(self): |
|
|
|
""" |
|
|
|
Test updating a document in the nonexistent dataset. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_in_nonexistent_dataset") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"name": "new_name" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file("fake_dataset_id", doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.DATA_ERROR and |
|
|
|
update_res["message"] == f"This dataset fake_dataset_id cannot be found!") |
|
|
|
|
|
|
|
def test_update_document_with_different_extension_name(self): |
|
|
|
""" |
|
|
|
Test the updating of a document with an extension name that differs from its original. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_different_extension_name") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"name": "new_name.doc" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.ARGUMENT_ERROR and |
|
|
|
update_res["message"] == "The extension of file cannot be changed") |
|
|
|
|
|
|
|
def test_update_document_with_duplicate_name(self): |
|
|
|
""" |
|
|
|
Test the updating of a document with a duplicate name. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_different_extension_name") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"name": "test.txt" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.ARGUMENT_ERROR and |
|
|
|
update_res["message"] == "Duplicated document name in the same dataset.") |
|
|
|
|
|
|
|
def test_update_document_with_updating_its_name_with_success(self): |
|
|
|
""" |
|
|
|
Test the updating of a document's name with success. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"name": "new_name.txt" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.SUCCESS and |
|
|
|
update_res["message"] == "Success" and update_res["data"]["name"] == "new_name.txt") |
|
|
|
|
|
|
|
def test_update_document_with_updating_its_template_type_with_success(self): |
|
|
|
""" |
|
|
|
Test the updating of a document's template type with success. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_updating_its_template_type_with_success") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"template_type": "laws" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.SUCCESS and |
|
|
|
update_res["message"] == "Success" and update_res["data"]["parser_id"] == "laws") |
|
|
|
|
|
|
|
def test_update_document_with_updating_its_enable_value_with_success(self): |
|
|
|
""" |
|
|
|
Test the updating of a document's enable value with success. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_updating_its_enable_value_with_success") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"enable": "0" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.SUCCESS and |
|
|
|
update_res["message"] == "Success" and update_res["data"]["status"] == "0") |
|
|
|
|
|
|
|
def test_update_document_with_updating_illegal_parameter(self): |
|
|
|
""" |
|
|
|
Test the updating of a document's illegal parameter. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_updating_illegal_parameter") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"illegal_parameter": "0" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
|
|
|
|
assert (update_res["code"] == RetCode.ARGUMENT_ERROR and |
|
|
|
update_res["message"] == "illegal_parameter is an illegal parameter.") |
|
|
|
|
|
|
|
# ----------------------------enable rename----------------------------------------------------- |
|
|
|
def test_update_document_with_giving_its_name_value(self): |
|
|
|
""" |
|
|
|
Test the updating of a document's name without its name value. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"name": "" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.DATA_ERROR and |
|
|
|
update_res["message"] == "There is no new name.") |
|
|
|
|
|
|
|
def test_update_document_with_giving_illegal_value_for_enable(self): |
|
|
|
""" |
|
|
|
Test the updating of a document's with giving illegal enable's value. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"enable": "?" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.DATA_ERROR and |
|
|
|
update_res["message"] == "Illegal value ? for 'enable' field.") |
|
|
|
|
|
|
|
def test_update_document_with_giving_illegal_value_for_type(self): |
|
|
|
""" |
|
|
|
Test the updating of a document's with giving illegal type's value. |
|
|
|
""" |
|
|
|
# create a dataset |
|
|
|
ragflow = RAGFlow(API_KEY, HOST_ADDRESS) |
|
|
|
created_res = ragflow.create_dataset("test_update_document_with_updating_its_name_with_success") |
|
|
|
created_res_id = created_res["data"]["dataset_id"] |
|
|
|
# upload files |
|
|
|
file_paths = ["test_data/test.txt", "test_data/test1.txt"] |
|
|
|
uploading_res = ragflow.upload_local_file(created_res_id, file_paths) |
|
|
|
# get the doc_id |
|
|
|
data = uploading_res["data"][0] |
|
|
|
doc_id = data["id"] |
|
|
|
# update file |
|
|
|
params = { |
|
|
|
"template_type": "?" |
|
|
|
} |
|
|
|
update_res = ragflow.update_file(created_res_id, doc_id, **params) |
|
|
|
assert (update_res["code"] == RetCode.DATA_ERROR and |
|
|
|
update_res["message"] == "Illegal value ? for 'template_type' field.") |
|
|
|
# ----------------------------download a file----------------------------------------------------- |
|
|
|
|
|
|
|
# ----------------------------start parsing----------------------------------------------------- |
|
|
|
|