mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-21 05:16:54 +08:00
Fix IDE warnings (#12010)
### What problem does this PR solve? As title ### Type of change - [x] Refactoring Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@ -49,10 +49,10 @@ repos = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def download_model(repo_id):
|
def download_model(repository_id):
|
||||||
local_dir = os.path.abspath(os.path.join("huggingface.co", repo_id))
|
local_directory = os.path.abspath(os.path.join("huggingface.co", repository_id))
|
||||||
os.makedirs(local_dir, exist_ok=True)
|
os.makedirs(local_directory, exist_ok=True)
|
||||||
snapshot_download(repo_id=repo_id, local_dir=local_dir)
|
snapshot_download(repo_id=repository_id, local_dir=local_directory)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -131,6 +131,7 @@ def get_tenant_info(auth):
|
|||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def set_tenant_info(auth):
|
def set_tenant_info(auth):
|
||||||
|
tenant_id = None
|
||||||
try:
|
try:
|
||||||
add_models(auth)
|
add_models(auth)
|
||||||
tenant_id = get_tenant_info(auth)
|
tenant_id = get_tenant_info(auth)
|
||||||
|
|||||||
@ -45,9 +45,9 @@ class TestChatAssistantCreate:
|
|||||||
client.create_chat(name=name.upper())
|
client.create_chat(name=name.upper())
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_chat(name=name)
|
client.create_chat(name=name)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant = client.create_chat(name=name)
|
chat_assistant = client.create_chat(name=name)
|
||||||
assert chat_assistant.name == name
|
assert chat_assistant.name == name
|
||||||
@ -68,9 +68,9 @@ class TestChatAssistantCreate:
|
|||||||
dataset_ids = dataset_ids(dataset.id)
|
dataset_ids = dataset_ids(dataset.id)
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_chat(name="ragflow test", dataset_ids=dataset_ids)
|
client.create_chat(name="ragflow test", dataset_ids=dataset_ids)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant = client.create_chat(name="ragflow test", dataset_ids=dataset_ids)
|
chat_assistant = client.create_chat(name="ragflow test", dataset_ids=dataset_ids)
|
||||||
assert chat_assistant.name == "ragflow test"
|
assert chat_assistant.name == "ragflow test"
|
||||||
@ -121,9 +121,9 @@ class TestChatAssistantCreate:
|
|||||||
llm_o = Chat.LLM(client, llm)
|
llm_o = Chat.LLM(client, llm)
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_chat(name="llm_test", dataset_ids=[dataset.id], llm=llm_o)
|
client.create_chat(name="llm_test", dataset_ids=[dataset.id], llm=llm_o)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant = client.create_chat(name="llm_test", dataset_ids=[dataset.id], llm=llm_o)
|
chat_assistant = client.create_chat(name="llm_test", dataset_ids=[dataset.id], llm=llm_o)
|
||||||
if llm:
|
if llm:
|
||||||
@ -189,9 +189,9 @@ class TestChatAssistantCreate:
|
|||||||
prompt_o = Chat.Prompt(client, prompt)
|
prompt_o = Chat.Prompt(client, prompt)
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_chat(name="prompt_test", dataset_ids=[dataset.id], prompt=prompt_o)
|
client.create_chat(name="prompt_test", dataset_ids=[dataset.id], prompt=prompt_o)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant = client.create_chat(name="prompt_test", dataset_ids=[dataset.id], prompt=prompt_o)
|
chat_assistant = client.create_chat(name="prompt_test", dataset_ids=[dataset.id], prompt=prompt_o)
|
||||||
if prompt:
|
if prompt:
|
||||||
@ -219,6 +219,6 @@ class TestChatAssistantCreate2:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_unparsed_document(self, client, add_document):
|
def test_unparsed_document(self, client, add_document):
|
||||||
dataset, _ = add_document
|
dataset, _ = add_document
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_chat(name="prompt_test", dataset_ids=[dataset.id])
|
client.create_chat(name="prompt_test", dataset_ids=[dataset.id])
|
||||||
assert "doesn't own parsed file" in str(excinfo.value)
|
assert "doesn't own parsed file" in str(exception_info.value)
|
||||||
|
|||||||
@ -37,9 +37,9 @@ class TestChatAssistantsDelete:
|
|||||||
payload = payload([chat_assistant.id for chat_assistant in chat_assistants])
|
payload = payload([chat_assistant.id for chat_assistant in chat_assistants])
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_chats(**payload)
|
client.delete_chats(**payload)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
if payload is None:
|
if payload is None:
|
||||||
client.delete_chats(payload)
|
client.delete_chats(payload)
|
||||||
@ -71,9 +71,9 @@ class TestChatAssistantsDelete:
|
|||||||
chat_ids = [chat.id for chat in chat_assistants]
|
chat_ids = [chat.id for chat in chat_assistants]
|
||||||
client.delete_chats(ids=chat_ids)
|
client.delete_chats(ids=chat_ids)
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_chats(ids=chat_ids)
|
client.delete_chats(ids=chat_ids)
|
||||||
assert "not found" in str(excinfo.value)
|
assert "not found" in str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_duplicate_deletion(self, client, add_chat_assistants_func):
|
def test_duplicate_deletion(self, client, add_chat_assistants_func):
|
||||||
|
|||||||
@ -49,9 +49,9 @@ class TestChatAssistantsList:
|
|||||||
)
|
)
|
||||||
def test_page(self, client, params, expected_page_size, expected_message):
|
def test_page(self, client, params, expected_page_size, expected_message):
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
assistants = client.list_chats(**params)
|
assistants = client.list_chats(**params)
|
||||||
assert len(assistants) == expected_page_size
|
assert len(assistants) == expected_page_size
|
||||||
@ -80,9 +80,9 @@ class TestChatAssistantsList:
|
|||||||
)
|
)
|
||||||
def test_page_size(self, client, params, expected_page_size, expected_message):
|
def test_page_size(self, client, params, expected_page_size, expected_message):
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
assistants = client.list_chats(**params)
|
assistants = client.list_chats(**params)
|
||||||
assert len(assistants) == expected_page_size
|
assert len(assistants) == expected_page_size
|
||||||
@ -99,9 +99,9 @@ class TestChatAssistantsList:
|
|||||||
)
|
)
|
||||||
def test_orderby(self, client, params, expected_message):
|
def test_orderby(self, client, params, expected_message):
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
|
|
||||||
@ -126,9 +126,9 @@ class TestChatAssistantsList:
|
|||||||
)
|
)
|
||||||
def test_desc(self, client, params, expected_message):
|
def test_desc(self, client, params, expected_message):
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
|
|
||||||
@ -144,9 +144,9 @@ class TestChatAssistantsList:
|
|||||||
)
|
)
|
||||||
def test_name(self, client, params, expected_num, expected_message):
|
def test_name(self, client, params, expected_num, expected_message):
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
assistants = client.list_chats(**params)
|
assistants = client.list_chats(**params)
|
||||||
if params["name"] in [None, ""]:
|
if params["name"] in [None, ""]:
|
||||||
@ -172,9 +172,9 @@ class TestChatAssistantsList:
|
|||||||
params = {"id": chat_assistant_id}
|
params = {"id": chat_assistant_id}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
assistants = client.list_chats(**params)
|
assistants = client.list_chats(**params)
|
||||||
if params["id"] in [None, ""]:
|
if params["id"] in [None, ""]:
|
||||||
@ -200,9 +200,9 @@ class TestChatAssistantsList:
|
|||||||
params = {"id": chat_assistant_id, "name": name}
|
params = {"id": chat_assistant_id, "name": name}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_chats(**params)
|
client.list_chats(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
assistants = client.list_chats(**params)
|
assistants = client.list_chats(**params)
|
||||||
assert len(assistants) == expected_num
|
assert len(assistants) == expected_num
|
||||||
|
|||||||
@ -39,9 +39,9 @@ class TestChatAssistantUpdate:
|
|||||||
chat_assistant = chat_assistants[0]
|
chat_assistant = chat_assistants[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.update(payload)
|
chat_assistant.update(payload)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant.update(payload)
|
chat_assistant.update(payload)
|
||||||
updated_chat = client.list_chats(id=chat_assistant.id)[0]
|
updated_chat = client.list_chats(id=chat_assistant.id)[0]
|
||||||
@ -101,9 +101,9 @@ class TestChatAssistantUpdate:
|
|||||||
payload = {"name": "llm_test", "llm": llm, "dataset_ids": [dataset.id]}
|
payload = {"name": "llm_test", "llm": llm, "dataset_ids": [dataset.id]}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.update(payload)
|
chat_assistant.update(payload)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant.update(payload)
|
chat_assistant.update(payload)
|
||||||
updated_chat = client.list_chats(id=chat_assistant.id)[0]
|
updated_chat = client.list_chats(id=chat_assistant.id)[0]
|
||||||
@ -178,9 +178,9 @@ class TestChatAssistantUpdate:
|
|||||||
payload = {"name": "prompt_test", "prompt": prompt, "dataset_ids": [dataset.id]}
|
payload = {"name": "prompt_test", "prompt": prompt, "dataset_ids": [dataset.id]}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.update(payload)
|
chat_assistant.update(payload)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant.update(payload)
|
chat_assistant.update(payload)
|
||||||
updated_chat = client.list_chats(id=chat_assistant.id)[0]
|
updated_chat = client.list_chats(id=chat_assistant.id)[0]
|
||||||
|
|||||||
@ -48,9 +48,9 @@ class TestAddChunk:
|
|||||||
chunks_count = len(document.list_chunks())
|
chunks_count = len(document.list_chunks())
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.add_chunk(**payload)
|
document.add_chunk(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunk = document.add_chunk(**payload)
|
chunk = document.add_chunk(**payload)
|
||||||
validate_chunk_details(dataset.id, document.id, payload, chunk)
|
validate_chunk_details(dataset.id, document.id, payload, chunk)
|
||||||
@ -76,9 +76,9 @@ class TestAddChunk:
|
|||||||
chunks_count = len(document.list_chunks())
|
chunks_count = len(document.list_chunks())
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.add_chunk(**payload)
|
document.add_chunk(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunk = document.add_chunk(**payload)
|
chunk = document.add_chunk(**payload)
|
||||||
validate_chunk_details(dataset.id, document.id, payload, chunk)
|
validate_chunk_details(dataset.id, document.id, payload, chunk)
|
||||||
@ -104,9 +104,9 @@ class TestAddChunk:
|
|||||||
chunks_count = len(document.list_chunks())
|
chunks_count = len(document.list_chunks())
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.add_chunk(**payload)
|
document.add_chunk(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunk = document.add_chunk(**payload)
|
chunk = document.add_chunk(**payload)
|
||||||
validate_chunk_details(dataset.id, document.id, payload, chunk)
|
validate_chunk_details(dataset.id, document.id, payload, chunk)
|
||||||
@ -138,9 +138,9 @@ class TestAddChunk:
|
|||||||
dataset, document = add_document
|
dataset, document = add_document
|
||||||
dataset.delete_documents(ids=[document.id])
|
dataset.delete_documents(ids=[document.id])
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.add_chunk(content="chunk test")
|
document.add_chunk(content="chunk test")
|
||||||
assert f"You don't own the document {document.id}" in str(excinfo.value), str(excinfo.value)
|
assert f"You don't own the document {document.id}" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.skip(reason="issues/6411")
|
@pytest.mark.skip(reason="issues/6411")
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
|
|||||||
@ -33,9 +33,9 @@ class TestChunksDeletion:
|
|||||||
chunk_ids = [chunk.id for chunk in chunks]
|
chunk_ids = [chunk.id for chunk in chunks]
|
||||||
payload = payload(chunk_ids)
|
payload = payload(chunk_ids)
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.delete_chunks(**payload)
|
document.delete_chunks(**payload)
|
||||||
assert "rm_chunk deleted chunks" in str(excinfo.value), str(excinfo.value)
|
assert "rm_chunk deleted chunks" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
remaining_chunks = document.list_chunks()
|
remaining_chunks = document.list_chunks()
|
||||||
assert len(remaining_chunks) == 1, str(remaining_chunks)
|
assert len(remaining_chunks) == 1, str(remaining_chunks)
|
||||||
@ -46,9 +46,9 @@ class TestChunksDeletion:
|
|||||||
chunk_ids = [chunk.id for chunk in chunks]
|
chunk_ids = [chunk.id for chunk in chunks]
|
||||||
document.delete_chunks(ids=chunk_ids)
|
document.delete_chunks(ids=chunk_ids)
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.delete_chunks(ids=chunk_ids)
|
document.delete_chunks(ids=chunk_ids)
|
||||||
assert "rm_chunk deleted chunks 0, expect" in str(excinfo.value), str(excinfo.value)
|
assert "rm_chunk deleted chunks 0, expect" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_duplicate_deletion(self, add_chunks_func):
|
def test_duplicate_deletion(self, add_chunks_func):
|
||||||
@ -103,9 +103,9 @@ class TestChunksDeletion:
|
|||||||
payload = payload(chunk_ids)
|
payload = payload(chunk_ids)
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.delete_chunks(**payload)
|
document.delete_chunks(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
document.delete_chunks(**payload)
|
document.delete_chunks(**payload)
|
||||||
|
|
||||||
|
|||||||
@ -38,9 +38,9 @@ class TestChunksList:
|
|||||||
_, document, _ = add_chunks
|
_, document, _ = add_chunks
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.list_chunks(**params)
|
document.list_chunks(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = document.list_chunks(**params)
|
chunks = document.list_chunks(**params)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
@ -62,9 +62,9 @@ class TestChunksList:
|
|||||||
_, document, _ = add_chunks
|
_, document, _ = add_chunks
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.list_chunks(**params)
|
document.list_chunks(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = document.list_chunks(**params)
|
chunks = document.list_chunks(**params)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
@ -106,9 +106,9 @@ class TestChunksList:
|
|||||||
params = {"id": chunk_id}
|
params = {"id": chunk_id}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.list_chunks(**params)
|
document.list_chunks(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = document.list_chunks(**params)
|
chunks = document.list_chunks(**params)
|
||||||
if params["id"] in [None, ""]:
|
if params["id"] in [None, ""]:
|
||||||
|
|||||||
@ -38,9 +38,9 @@ class TestChunksRetrieval:
|
|||||||
payload["document_ids"] = [document.id]
|
payload["document_ids"] = [document.id]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.retrieve(**payload)
|
client.retrieve(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = client.retrieve(**payload)
|
chunks = client.retrieve(**payload)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
@ -83,9 +83,9 @@ class TestChunksRetrieval:
|
|||||||
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.retrieve(**payload)
|
client.retrieve(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = client.retrieve(**payload)
|
chunks = client.retrieve(**payload)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
@ -116,9 +116,9 @@ class TestChunksRetrieval:
|
|||||||
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.retrieve(**payload)
|
client.retrieve(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = client.retrieve(**payload)
|
chunks = client.retrieve(**payload)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
@ -143,9 +143,9 @@ class TestChunksRetrieval:
|
|||||||
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.retrieve(**payload)
|
client.retrieve(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = client.retrieve(**payload)
|
chunks = client.retrieve(**payload)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
@ -192,9 +192,9 @@ class TestChunksRetrieval:
|
|||||||
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.retrieve(**payload)
|
client.retrieve(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = client.retrieve(**payload)
|
chunks = client.retrieve(**payload)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
@ -212,9 +212,9 @@ class TestChunksRetrieval:
|
|||||||
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
payload.update({"question": "chunk", "dataset_ids": [dataset.id]})
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.retrieve(**payload)
|
client.retrieve(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = client.retrieve(**payload)
|
chunks = client.retrieve(**payload)
|
||||||
assert len(chunks) > 0, str(chunks)
|
assert len(chunks) > 0, str(chunks)
|
||||||
@ -235,9 +235,9 @@ class TestChunksRetrieval:
|
|||||||
payload.update({"question": "chunk test", "dataset_ids": [dataset.id]})
|
payload.update({"question": "chunk test", "dataset_ids": [dataset.id]})
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.retrieve(**payload)
|
client.retrieve(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunks = client.retrieve(**payload)
|
chunks = client.retrieve(**payload)
|
||||||
assert len(chunks) == expected_page_size, str(chunks)
|
assert len(chunks) == expected_page_size, str(chunks)
|
||||||
|
|||||||
@ -50,9 +50,9 @@ class TestUpdatedChunk:
|
|||||||
chunk = chunks[0]
|
chunk = chunks[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
|
|
||||||
@ -73,9 +73,9 @@ class TestUpdatedChunk:
|
|||||||
chunk = chunks[0]
|
chunk = chunks[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
|
|
||||||
@ -96,9 +96,9 @@ class TestUpdatedChunk:
|
|||||||
chunk = chunks[0]
|
chunk = chunks[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
|
|
||||||
@ -119,9 +119,9 @@ class TestUpdatedChunk:
|
|||||||
chunk = chunks[0]
|
chunk = chunks[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chunk.update(payload)
|
chunk.update(payload)
|
||||||
|
|
||||||
@ -149,6 +149,6 @@ class TestUpdatedChunk:
|
|||||||
dataset, document, chunks = add_chunks
|
dataset, document, chunks = add_chunks
|
||||||
dataset.delete_documents(ids=[document.id])
|
dataset.delete_documents(ids=[document.id])
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chunks[0].update({})
|
chunks[0].update({})
|
||||||
assert str(excinfo.value) in [f"You don't own the document {chunks[0].document_id}", f"Can't find this chunk {chunks[0].id}"], str(excinfo.value)
|
assert str(exception_info.value) in [f"You don't own the document {chunks[0].document_id}", f"Can't find this chunk {chunks[0].id}"], str(exception_info.value)
|
||||||
|
|||||||
@ -38,9 +38,9 @@ class TestAuthorization:
|
|||||||
)
|
)
|
||||||
def test_auth_invalid(self, invalid_auth, expected_message):
|
def test_auth_invalid(self, invalid_auth, expected_message):
|
||||||
client = RAGFlow(invalid_auth, HOST_ADDRESS)
|
client = RAGFlow(invalid_auth, HOST_ADDRESS)
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**{"name": "auth_test"})
|
client.create_dataset(**{"name": "auth_test"})
|
||||||
assert str(excinfo.value) == expected_message
|
assert str(exception_info.value) == expected_message
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("clear_datasets")
|
@pytest.mark.usefixtures("clear_datasets")
|
||||||
@ -85,9 +85,9 @@ class TestDatasetCreate:
|
|||||||
ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
|
ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"],
|
||||||
)
|
)
|
||||||
def test_name_invalid(self, client, name, expected_message):
|
def test_name_invalid(self, client, name, expected_message):
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**{"name": name})
|
client.create_dataset(**{"name": name})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_name_duplicated(self, client):
|
def test_name_duplicated(self, client):
|
||||||
@ -120,9 +120,9 @@ class TestDatasetCreate:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_avatar_exceeds_limit_length(self, client):
|
def test_avatar_exceeds_limit_length(self, client):
|
||||||
payload = {"name": "avatar_exceeds_limit_length", "avatar": "a" * 65536}
|
payload = {"name": "avatar_exceeds_limit_length", "avatar": "a" * 65536}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value)
|
assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -141,9 +141,9 @@ class TestDatasetCreate:
|
|||||||
"name": name,
|
"name": name,
|
||||||
"avatar": f"{prefix}{encode_avatar(fn)}",
|
"avatar": f"{prefix}{encode_avatar(fn)}",
|
||||||
}
|
}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_avatar_unset(self, client):
|
def test_avatar_unset(self, client):
|
||||||
@ -160,9 +160,9 @@ class TestDatasetCreate:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_description_exceeds_limit_length(self, client):
|
def test_description_exceeds_limit_length(self, client):
|
||||||
payload = {"name": "description_exceeds_limit_length", "description": "a" * 65536}
|
payload = {"name": "description_exceeds_limit_length", "description": "a" * 65536}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value)
|
assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_description_unset(self, client):
|
def test_description_unset(self, client):
|
||||||
@ -203,12 +203,12 @@ class TestDatasetCreate:
|
|||||||
)
|
)
|
||||||
def test_embedding_model_invalid(self, client, name, embedding_model):
|
def test_embedding_model_invalid(self, client, name, embedding_model):
|
||||||
payload = {"name": name, "embedding_model": embedding_model}
|
payload = {"name": name, "embedding_model": embedding_model}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
if "tenant_no_auth" in name:
|
if "tenant_no_auth" in name:
|
||||||
assert str(excinfo.value) == f"Unauthorized model: <{embedding_model}>", str(excinfo.value)
|
assert str(exception_info.value) == f"Unauthorized model: <{embedding_model}>", str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
assert str(excinfo.value) == f"Unsupported model: <{embedding_model}>", str(excinfo.value)
|
assert str(exception_info.value) == f"Unsupported model: <{embedding_model}>", str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -226,12 +226,12 @@ class TestDatasetCreate:
|
|||||||
)
|
)
|
||||||
def test_embedding_model_format(self, client, name, embedding_model):
|
def test_embedding_model_format(self, client, name, embedding_model):
|
||||||
payload = {"name": name, "embedding_model": embedding_model}
|
payload = {"name": name, "embedding_model": embedding_model}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
if name in ["empty", "space", "missing_at"]:
|
if name in ["empty", "space", "missing_at"]:
|
||||||
assert "Embedding model identifier must follow <model_name>@<provider> format" in str(excinfo.value), str(excinfo.value)
|
assert "Embedding model identifier must follow <model_name>@<provider> format" in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
assert "Both model_name and provider must be non-empty strings" in str(excinfo.value), str(excinfo.value)
|
assert "Both model_name and provider must be non-empty strings" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_embedding_model_unset(self, client):
|
def test_embedding_model_unset(self, client):
|
||||||
@ -273,9 +273,9 @@ class TestDatasetCreate:
|
|||||||
)
|
)
|
||||||
def test_permission_invalid(self, client, name, permission):
|
def test_permission_invalid(self, client, name, permission):
|
||||||
payload = {"name": name, "permission": permission}
|
payload = {"name": name, "permission": permission}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert "Input should be 'me' or 'team'" in str(excinfo.value)
|
assert "Input should be 'me' or 'team'" in str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_permission_unset(self, client):
|
def test_permission_unset(self, client):
|
||||||
@ -286,9 +286,9 @@ class TestDatasetCreate:
|
|||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_permission_none(self, client):
|
def test_permission_none(self, client):
|
||||||
payload = {"name": "permission_none", "permission": None}
|
payload = {"name": "permission_none", "permission": None}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert "not instance of" in str(excinfo.value), str(excinfo.value)
|
assert "not instance of" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p1
|
@pytest.mark.p1
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -325,9 +325,9 @@ class TestDatasetCreate:
|
|||||||
)
|
)
|
||||||
def test_chunk_method_invalid(self, client, name, chunk_method):
|
def test_chunk_method_invalid(self, client, name, chunk_method):
|
||||||
payload = {"name": name, "chunk_method": chunk_method}
|
payload = {"name": name, "chunk_method": chunk_method}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(excinfo.value), str(excinfo.value)
|
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_chunk_method_unset(self, client):
|
def test_chunk_method_unset(self, client):
|
||||||
@ -338,9 +338,9 @@ class TestDatasetCreate:
|
|||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_chunk_method_none(self, client):
|
def test_chunk_method_none(self, client):
|
||||||
payload = {"name": "chunk_method_none", "chunk_method": None}
|
payload = {"name": "chunk_method_none", "chunk_method": None}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert "not instance of" in str(excinfo.value), str(excinfo.value)
|
assert "not instance of" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p1
|
@pytest.mark.p1
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -576,9 +576,9 @@ class TestDatasetCreate:
|
|||||||
def test_parser_config_invalid(self, client, name, parser_config, expected_message):
|
def test_parser_config_invalid(self, client, name, parser_config, expected_message):
|
||||||
parser_config_o = DataSet.ParserConfig(client, parser_config)
|
parser_config_o = DataSet.ParserConfig(client, parser_config)
|
||||||
payload = {"name": name, "parser_config": parser_config_o}
|
payload = {"name": name, "parser_config": parser_config_o}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_parser_config_empty(self, client):
|
def test_parser_config_empty(self, client):
|
||||||
@ -631,9 +631,9 @@ class TestDatasetCreate:
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_unsupported_field(self, client, payload):
|
def test_unsupported_field(self, client, payload):
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.create_dataset(**payload)
|
client.create_dataset(**payload)
|
||||||
assert "got an unexpected keyword argument" in str(excinfo.value), str(excinfo.value)
|
assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("clear_datasets")
|
@pytest.mark.usefixtures("clear_datasets")
|
||||||
|
|||||||
@ -33,9 +33,9 @@ class TestAuthorization:
|
|||||||
)
|
)
|
||||||
def test_auth_invalid(self, invalid_auth, expected_message):
|
def test_auth_invalid(self, invalid_auth, expected_message):
|
||||||
client = RAGFlow(invalid_auth, HOST_ADDRESS)
|
client = RAGFlow(invalid_auth, HOST_ADDRESS)
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets()
|
client.delete_datasets()
|
||||||
assert str(excinfo.value) == expected_message
|
assert str(exception_info.value) == expected_message
|
||||||
|
|
||||||
|
|
||||||
class TestCapability:
|
class TestCapability:
|
||||||
@ -71,6 +71,7 @@ class TestDatasetsDelete:
|
|||||||
ids=["single_dataset", "multiple_datasets"],
|
ids=["single_dataset", "multiple_datasets"],
|
||||||
)
|
)
|
||||||
def test_ids(self, client, add_datasets_func, func, remaining):
|
def test_ids(self, client, add_datasets_func, func, remaining):
|
||||||
|
payload = None
|
||||||
if callable(func):
|
if callable(func):
|
||||||
payload = func([dataset.id for dataset in add_datasets_func])
|
payload = func([dataset.id for dataset in add_datasets_func])
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
@ -100,9 +101,9 @@ class TestDatasetsDelete:
|
|||||||
@pytest.mark.usefixtures("add_dataset_func")
|
@pytest.mark.usefixtures("add_dataset_func")
|
||||||
def test_id_not_uuid(self, client):
|
def test_id_not_uuid(self, client):
|
||||||
payload = {"ids": ["not_uuid"]}
|
payload = {"ids": ["not_uuid"]}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value)
|
assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
datasets = client.list_datasets()
|
datasets = client.list_datasets()
|
||||||
assert len(datasets) == 1, str(datasets)
|
assert len(datasets) == 1, str(datasets)
|
||||||
@ -111,17 +112,17 @@ class TestDatasetsDelete:
|
|||||||
@pytest.mark.usefixtures("add_dataset_func")
|
@pytest.mark.usefixtures("add_dataset_func")
|
||||||
def test_id_not_uuid1(self, client):
|
def test_id_not_uuid1(self, client):
|
||||||
payload = {"ids": [uuid.uuid4().hex]}
|
payload = {"ids": [uuid.uuid4().hex]}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value)
|
assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
@pytest.mark.usefixtures("add_dataset_func")
|
@pytest.mark.usefixtures("add_dataset_func")
|
||||||
def test_id_wrong_uuid(self, client):
|
def test_id_wrong_uuid(self, client):
|
||||||
payload = {"ids": ["d94a8dc02c9711f0930f7fbc369eab6d"]}
|
payload = {"ids": ["d94a8dc02c9711f0930f7fbc369eab6d"]}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value)
|
assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
datasets = client.list_datasets()
|
datasets = client.list_datasets()
|
||||||
assert len(datasets) == 1, str(datasets)
|
assert len(datasets) == 1, str(datasets)
|
||||||
@ -138,9 +139,9 @@ class TestDatasetsDelete:
|
|||||||
def test_ids_partial_invalid(self, client, add_datasets_func, func):
|
def test_ids_partial_invalid(self, client, add_datasets_func, func):
|
||||||
if callable(func):
|
if callable(func):
|
||||||
payload = func([dataset.id for dataset in add_datasets_func])
|
payload = func([dataset.id for dataset in add_datasets_func])
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value)
|
assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
datasets = client.list_datasets()
|
datasets = client.list_datasets()
|
||||||
assert len(datasets) == 3, str(datasets)
|
assert len(datasets) == 3, str(datasets)
|
||||||
@ -149,9 +150,9 @@ class TestDatasetsDelete:
|
|||||||
def test_ids_duplicate(self, client, add_datasets_func):
|
def test_ids_duplicate(self, client, add_datasets_func):
|
||||||
dataset_ids = [dataset.id for dataset in add_datasets_func]
|
dataset_ids = [dataset.id for dataset in add_datasets_func]
|
||||||
payload = {"ids": dataset_ids + dataset_ids}
|
payload = {"ids": dataset_ids + dataset_ids}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
assert "Duplicate ids:" in str(excinfo.value), str(excinfo.value)
|
assert "Duplicate ids:" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
datasets = client.list_datasets()
|
datasets = client.list_datasets()
|
||||||
assert len(datasets) == 3, str(datasets)
|
assert len(datasets) == 3, str(datasets)
|
||||||
@ -162,17 +163,17 @@ class TestDatasetsDelete:
|
|||||||
payload = {"ids": dataset_ids}
|
payload = {"ids": dataset_ids}
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value)
|
assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
@pytest.mark.usefixtures("add_dataset_func")
|
@pytest.mark.usefixtures("add_dataset_func")
|
||||||
def test_field_unsupported(self, client):
|
def test_field_unsupported(self, client):
|
||||||
payload = {"unknown_field": "unknown_field"}
|
payload = {"unknown_field": "unknown_field"}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.delete_datasets(**payload)
|
client.delete_datasets(**payload)
|
||||||
assert "got an unexpected keyword argument 'unknown_field'" in str(excinfo.value), str(excinfo.value)
|
assert "got an unexpected keyword argument 'unknown_field'" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
datasets = client.list_datasets()
|
datasets = client.list_datasets()
|
||||||
assert len(datasets) == 1, str(datasets)
|
assert len(datasets) == 1, str(datasets)
|
||||||
|
|||||||
@ -32,9 +32,9 @@ class TestAuthorization:
|
|||||||
)
|
)
|
||||||
def test_auth_invalid(self, invalid_auth, expected_message):
|
def test_auth_invalid(self, invalid_auth, expected_message):
|
||||||
client = RAGFlow(invalid_auth, HOST_ADDRESS)
|
client = RAGFlow(invalid_auth, HOST_ADDRESS)
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets()
|
client.list_datasets()
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
|
|
||||||
|
|
||||||
class TestCapability:
|
class TestCapability:
|
||||||
@ -46,7 +46,7 @@ class TestCapability:
|
|||||||
executor.submit(
|
executor.submit(
|
||||||
client.list_datasets,
|
client.list_datasets,
|
||||||
)
|
)
|
||||||
for i in range(count)
|
for _ in range(count)
|
||||||
]
|
]
|
||||||
responses = list(as_completed(futures))
|
responses = list(as_completed(futures))
|
||||||
assert len(responses) == count, responses
|
assert len(responses) == count, responses
|
||||||
@ -89,16 +89,16 @@ class TestDatasetsList:
|
|||||||
ids=["page_0", "page_a"],
|
ids=["page_0", "page_a"],
|
||||||
)
|
)
|
||||||
def test_page_invalid(self, client, params, expected_message):
|
def test_page_invalid(self, client, params, expected_message):
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_page_none(self, client):
|
def test_page_none(self, client):
|
||||||
params = {"page": None}
|
params = {"page": None}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "not instance of" in str(excinfo.value), str(excinfo.value)
|
assert "not instance of" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p1
|
@pytest.mark.p1
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -124,16 +124,16 @@ class TestDatasetsList:
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_page_size_invalid(self, client, params, expected_message):
|
def test_page_size_invalid(self, client, params, expected_message):
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_page_size_none(self, client):
|
def test_page_size_none(self, client):
|
||||||
params = {"page_size": None}
|
params = {"page_size": None}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "not instance of" in str(excinfo.value), str(excinfo.value)
|
assert "not instance of" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -160,16 +160,16 @@ class TestDatasetsList:
|
|||||||
ids=["empty", "unknown", "orderby_create_time_upper", "orderby_update_time_upper", "whitespace"],
|
ids=["empty", "unknown", "orderby_create_time_upper", "orderby_update_time_upper", "whitespace"],
|
||||||
)
|
)
|
||||||
def test_orderby_invalid(self, client, params):
|
def test_orderby_invalid(self, client, params):
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "Input should be 'create_time' or 'update_time'" in str(excinfo.value), str(excinfo.value)
|
assert "Input should be 'create_time' or 'update_time'" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_orderby_none(self, client):
|
def test_orderby_none(self, client):
|
||||||
params = {"orderby": None}
|
params = {"orderby": None}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "not instance of" in str(excinfo.value), str(excinfo.value)
|
assert "not instance of" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -193,16 +193,16 @@ class TestDatasetsList:
|
|||||||
ids=["float_value", "invalid_string"],
|
ids=["float_value", "invalid_string"],
|
||||||
)
|
)
|
||||||
def test_desc_invalid(self, client, params):
|
def test_desc_invalid(self, client, params):
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "not instance of" in str(excinfo.value), str(excinfo.value)
|
assert "not instance of" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_desc_none(self, client):
|
def test_desc_none(self, client):
|
||||||
params = {"desc": None}
|
params = {"desc": None}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "not instance of" in str(excinfo.value), str(excinfo.value)
|
assert "not instance of" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p1
|
@pytest.mark.p1
|
||||||
def test_name(self, client):
|
def test_name(self, client):
|
||||||
@ -214,9 +214,9 @@ class TestDatasetsList:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_name_wrong(self, client):
|
def test_name_wrong(self, client):
|
||||||
params = {"name": "wrong name"}
|
params = {"name": "wrong name"}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value)
|
assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_name_empty(self, client):
|
def test_name_empty(self, client):
|
||||||
@ -241,30 +241,30 @@ class TestDatasetsList:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_id_not_uuid(self, client):
|
def test_id_not_uuid(self, client):
|
||||||
params = {"id": "not_uuid"}
|
params = {"id": "not_uuid"}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value)
|
assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_id_not_uuid1(self, client):
|
def test_id_not_uuid1(self, client):
|
||||||
params = {"id": uuid.uuid4().hex}
|
params = {"id": uuid.uuid4().hex}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value)
|
assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_id_wrong_uuid(self, client):
|
def test_id_wrong_uuid(self, client):
|
||||||
params = {"id": "d94a8dc02c9711f0930f7fbc369eab6d"}
|
params = {"id": "d94a8dc02c9711f0930f7fbc369eab6d"}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value)
|
assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_id_empty(self, client):
|
def test_id_empty(self, client):
|
||||||
params = {"id": ""}
|
params = {"id": ""}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value)
|
assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_id_none(self, client):
|
def test_id_none(self, client):
|
||||||
@ -282,6 +282,7 @@ class TestDatasetsList:
|
|||||||
ids=["name_and_id_match", "name_and_id_mismatch"],
|
ids=["name_and_id_match", "name_and_id_mismatch"],
|
||||||
)
|
)
|
||||||
def test_name_and_id(self, client, add_datasets, func, name, expected_num):
|
def test_name_and_id(self, client, add_datasets, func, name, expected_num):
|
||||||
|
params = None
|
||||||
if callable(func):
|
if callable(func):
|
||||||
params = {"id": func(add_datasets), "name": name}
|
params = {"id": func(add_datasets), "name": name}
|
||||||
datasets = client.list_datasets(**params)
|
datasets = client.list_datasets(**params)
|
||||||
@ -301,13 +302,13 @@ class TestDatasetsList:
|
|||||||
params = {"id": dataset_id(add_datasets), "name": name}
|
params = {"id": dataset_id(add_datasets), "name": name}
|
||||||
else:
|
else:
|
||||||
params = {"id": dataset_id, "name": name}
|
params = {"id": dataset_id, "name": name}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value)
|
assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_field_unsupported(self, client):
|
def test_field_unsupported(self, client):
|
||||||
params = {"unknown_field": "unknown_field"}
|
params = {"unknown_field": "unknown_field"}
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
client.list_datasets(**params)
|
client.list_datasets(**params)
|
||||||
assert "got an unexpected keyword argument" in str(excinfo.value), str(excinfo.value)
|
assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|||||||
@ -30,9 +30,9 @@ class TestRquest:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_payload_empty(self, add_dataset_func):
|
def test_payload_empty(self, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({})
|
dataset.update({})
|
||||||
assert "No properties were modified" in str(excinfo.value), str(excinfo.value)
|
assert "No properties were modified" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
|
|
||||||
class TestCapability:
|
class TestCapability:
|
||||||
@ -74,25 +74,25 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_name_invalid(self, add_dataset_func, name, expected_message):
|
def test_name_invalid(self, add_dataset_func, name, expected_message):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"name": name})
|
dataset.update({"name": name})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_name_duplicated(self, add_datasets_func):
|
def test_name_duplicated(self, add_datasets_func):
|
||||||
datasets = add_datasets_func
|
datasets = add_datasets_func
|
||||||
name = "dataset_1"
|
name = "dataset_1"
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
datasets[0].update({"name": name})
|
datasets[0].update({"name": name})
|
||||||
assert f"Dataset name '{name}' already exists" in str(excinfo.value), str(excinfo.value)
|
assert f"Dataset name '{name}' already exists" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_name_case_insensitive(self, add_datasets_func):
|
def test_name_case_insensitive(self, add_datasets_func):
|
||||||
dataset = add_datasets_func[0]
|
dataset = add_datasets_func[0]
|
||||||
name = "DATASET_1"
|
name = "DATASET_1"
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"name": name})
|
dataset.update({"name": name})
|
||||||
assert f"Dataset name '{name}' already exists" in str(excinfo.value), str(excinfo.value)
|
assert f"Dataset name '{name}' already exists" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_avatar(self, client, add_dataset_func, tmp_path):
|
def test_avatar(self, client, add_dataset_func, tmp_path):
|
||||||
@ -108,9 +108,9 @@ class TestDatasetUpdate:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_avatar_exceeds_limit_length(self, add_dataset_func):
|
def test_avatar_exceeds_limit_length(self, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"avatar": "a" * 65536})
|
dataset.update({"avatar": "a" * 65536})
|
||||||
assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value)
|
assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -126,9 +126,9 @@ class TestDatasetUpdate:
|
|||||||
def test_avatar_invalid_prefix(self, add_dataset_func, tmp_path, avatar_prefix, expected_message):
|
def test_avatar_invalid_prefix(self, add_dataset_func, tmp_path, avatar_prefix, expected_message):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
fn = create_image_file(tmp_path / "ragflow_test.png")
|
fn = create_image_file(tmp_path / "ragflow_test.png")
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"avatar": f"{avatar_prefix}{encode_avatar(fn)}"})
|
dataset.update({"avatar": f"{avatar_prefix}{encode_avatar(fn)}"})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_avatar_none(self, client, add_dataset_func):
|
def test_avatar_none(self, client, add_dataset_func):
|
||||||
@ -151,9 +151,9 @@ class TestDatasetUpdate:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_description_exceeds_limit_length(self, add_dataset_func):
|
def test_description_exceeds_limit_length(self, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"description": "a" * 65536})
|
dataset.update({"description": "a" * 65536})
|
||||||
assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value)
|
assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_description_none(self, client, add_dataset_func):
|
def test_description_none(self, client, add_dataset_func):
|
||||||
@ -194,9 +194,9 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_embedding_model_invalid(self, add_dataset_func, name, embedding_model):
|
def test_embedding_model_invalid(self, add_dataset_func, name, embedding_model):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"name": name, "embedding_model": embedding_model})
|
dataset.update({"name": name, "embedding_model": embedding_model})
|
||||||
error_msg = str(excinfo.value)
|
error_msg = str(exception_info.value)
|
||||||
if "tenant_no_auth" in name:
|
if "tenant_no_auth" in name:
|
||||||
assert error_msg == f"Unauthorized model: <{embedding_model}>", error_msg
|
assert error_msg == f"Unauthorized model: <{embedding_model}>", error_msg
|
||||||
else:
|
else:
|
||||||
@ -218,9 +218,9 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_embedding_model_format(self, add_dataset_func, name, embedding_model):
|
def test_embedding_model_format(self, add_dataset_func, name, embedding_model):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"name": name, "embedding_model": embedding_model})
|
dataset.update({"name": name, "embedding_model": embedding_model})
|
||||||
error_msg = str(excinfo.value)
|
error_msg = str(exception_info.value)
|
||||||
if name in ["empty", "space", "missing_at"]:
|
if name in ["empty", "space", "missing_at"]:
|
||||||
assert "Embedding model identifier must follow <model_name>@<provider> format" in error_msg, error_msg
|
assert "Embedding model identifier must follow <model_name>@<provider> format" in error_msg, error_msg
|
||||||
else:
|
else:
|
||||||
@ -267,16 +267,16 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_permission_invalid(self, add_dataset_func, permission):
|
def test_permission_invalid(self, add_dataset_func, permission):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"permission": permission})
|
dataset.update({"permission": permission})
|
||||||
assert "Input should be 'me' or 'team'" in str(excinfo.value), str(excinfo.value)
|
assert "Input should be 'me' or 'team'" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_permission_none(self, add_dataset_func):
|
def test_permission_none(self, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"permission": None})
|
dataset.update({"permission": None})
|
||||||
assert "Input should be 'me' or 'team'" in str(excinfo.value), str(excinfo.value)
|
assert "Input should be 'me' or 'team'" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p1
|
@pytest.mark.p1
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -317,16 +317,16 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_chunk_method_invalid(self, add_dataset_func, chunk_method):
|
def test_chunk_method_invalid(self, add_dataset_func, chunk_method):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"chunk_method": chunk_method})
|
dataset.update({"chunk_method": chunk_method})
|
||||||
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(excinfo.value), str(excinfo.value)
|
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_chunk_method_none(self, add_dataset_func):
|
def test_chunk_method_none(self, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"chunk_method": None})
|
dataset.update({"chunk_method": None})
|
||||||
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(excinfo.value), str(excinfo.value)
|
assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="#8208")
|
@pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="#8208")
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
@ -359,9 +359,9 @@ class TestDatasetUpdate:
|
|||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_pagerank_infinity(self, client, add_dataset_func):
|
def test_pagerank_infinity(self, client, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"pagerank": 50})
|
dataset.update({"pagerank": 50})
|
||||||
assert "'pagerank' can only be set when doc_engine is elasticsearch" in str(excinfo.value), str(excinfo.value)
|
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.p2
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -374,16 +374,16 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_pagerank_invalid(self, add_dataset_func, pagerank, expected_message):
|
def test_pagerank_invalid(self, add_dataset_func, pagerank, expected_message):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"pagerank": pagerank})
|
dataset.update({"pagerank": pagerank})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_pagerank_none(self, add_dataset_func):
|
def test_pagerank_none(self, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"pagerank": None})
|
dataset.update({"pagerank": None})
|
||||||
assert "Input should be a valid integer" in str(excinfo.value), str(excinfo.value)
|
assert "Input should be a valid integer" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p1
|
@pytest.mark.p1
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -625,9 +625,9 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_parser_config_invalid(self, add_dataset_func, parser_config, expected_message):
|
def test_parser_config_invalid(self, add_dataset_func, parser_config, expected_message):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update({"parser_config": parser_config})
|
dataset.update({"parser_config": parser_config})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_parser_config_empty(self, client, add_dataset_func):
|
def test_parser_config_empty(self, client, add_dataset_func):
|
||||||
@ -723,9 +723,9 @@ class TestDatasetUpdate:
|
|||||||
)
|
)
|
||||||
def test_field_unsupported(self, add_dataset_func, payload):
|
def test_field_unsupported(self, add_dataset_func, payload):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.update(payload)
|
dataset.update(payload)
|
||||||
assert "Extra inputs are not permitted" in str(excinfo.value), str(excinfo.value)
|
assert "Extra inputs are not permitted" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_field_unset(self, client, add_dataset_func):
|
def test_field_unset(self, client, add_dataset_func):
|
||||||
|
|||||||
@ -45,9 +45,9 @@ class TestDocumentsDeletion:
|
|||||||
payload = payload([document.id for document in documents])
|
payload = payload([document.id for document in documents])
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.delete_documents(**payload)
|
dataset.delete_documents(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
dataset.delete_documents(**payload)
|
dataset.delete_documents(**payload)
|
||||||
|
|
||||||
@ -67,9 +67,9 @@ class TestDocumentsDeletion:
|
|||||||
dataset, documents = add_documents_func
|
dataset, documents = add_documents_func
|
||||||
payload = payload([document.id for document in documents])
|
payload = payload([document.id for document in documents])
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.delete_documents(**payload)
|
dataset.delete_documents(**payload)
|
||||||
assert "Documents not found: ['invalid_id']" in str(excinfo.value), str(excinfo.value)
|
assert "Documents not found: ['invalid_id']" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
documents = dataset.list_documents()
|
documents = dataset.list_documents()
|
||||||
assert len(documents) == 0, str(documents)
|
assert len(documents) == 0, str(documents)
|
||||||
@ -79,9 +79,9 @@ class TestDocumentsDeletion:
|
|||||||
dataset, documents = add_documents_func
|
dataset, documents = add_documents_func
|
||||||
document_ids = [document.id for document in documents]
|
document_ids = [document.id for document in documents]
|
||||||
dataset.delete_documents(ids=document_ids)
|
dataset.delete_documents(ids=document_ids)
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.delete_documents(ids=document_ids)
|
dataset.delete_documents(ids=document_ids)
|
||||||
assert "Documents not found" in str(excinfo.value), str(excinfo.value)
|
assert "Documents not found" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_duplicate_deletion(self, add_documents_func):
|
def test_duplicate_deletion(self, add_documents_func):
|
||||||
|
|||||||
@ -51,9 +51,9 @@ class TestDocumentsList:
|
|||||||
def test_page(self, add_documents, params, expected_page_size, expected_message):
|
def test_page(self, add_documents, params, expected_page_size, expected_message):
|
||||||
dataset, _ = add_documents
|
dataset, _ = add_documents
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
documents = dataset.list_documents(**params)
|
documents = dataset.list_documents(**params)
|
||||||
assert len(documents) == expected_page_size, str(documents)
|
assert len(documents) == expected_page_size, str(documents)
|
||||||
@ -84,9 +84,9 @@ class TestDocumentsList:
|
|||||||
def test_page_size(self, add_documents, params, expected_page_size, expected_message):
|
def test_page_size(self, add_documents, params, expected_page_size, expected_message):
|
||||||
dataset, _ = add_documents
|
dataset, _ = add_documents
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
documents = dataset.list_documents(**params)
|
documents = dataset.list_documents(**params)
|
||||||
assert len(documents) == expected_page_size, str(documents)
|
assert len(documents) == expected_page_size, str(documents)
|
||||||
@ -105,9 +105,9 @@ class TestDocumentsList:
|
|||||||
def test_orderby(self, add_documents, params, expected_message):
|
def test_orderby(self, add_documents, params, expected_message):
|
||||||
dataset, _ = add_documents
|
dataset, _ = add_documents
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
|
|
||||||
@ -129,9 +129,9 @@ class TestDocumentsList:
|
|||||||
def test_desc(self, add_documents, params, expected_message):
|
def test_desc(self, add_documents, params, expected_message):
|
||||||
dataset, _ = add_documents
|
dataset, _ = add_documents
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
|
|
||||||
@ -164,9 +164,9 @@ class TestDocumentsList:
|
|||||||
def test_name(self, add_documents, params, expected_num, expected_message):
|
def test_name(self, add_documents, params, expected_num, expected_message):
|
||||||
dataset, _ = add_documents
|
dataset, _ = add_documents
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
documents = dataset.list_documents(**params)
|
documents = dataset.list_documents(**params)
|
||||||
assert len(documents) == expected_num, str(documents)
|
assert len(documents) == expected_num, str(documents)
|
||||||
@ -191,9 +191,9 @@ class TestDocumentsList:
|
|||||||
params = {"id": document_id}
|
params = {"id": document_id}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
documents = dataset.list_documents(**params)
|
documents = dataset.list_documents(**params)
|
||||||
assert len(documents) == expected_num, str(documents)
|
assert len(documents) == expected_num, str(documents)
|
||||||
@ -215,9 +215,9 @@ class TestDocumentsList:
|
|||||||
params = {"id": document_id(documents) if callable(document_id) else document_id, "name": name}
|
params = {"id": document_id(documents) if callable(document_id) else document_id, "name": name}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
documents = dataset.list_documents(**params)
|
documents = dataset.list_documents(**params)
|
||||||
assert len(documents) == expected_num, str(documents)
|
assert len(documents) == expected_num, str(documents)
|
||||||
@ -242,6 +242,6 @@ class TestDocumentsList:
|
|||||||
def test_invalid_params(self, add_documents):
|
def test_invalid_params(self, add_documents):
|
||||||
dataset, _ = add_documents
|
dataset, _ = add_documents
|
||||||
params = {"a": "b"}
|
params = {"a": "b"}
|
||||||
with pytest.raises(TypeError) as excinfo:
|
with pytest.raises(TypeError) as exception_info:
|
||||||
dataset.list_documents(**params)
|
dataset.list_documents(**params)
|
||||||
assert "got an unexpected keyword argument" in str(excinfo.value), str(excinfo.value)
|
assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|||||||
@ -69,9 +69,9 @@ class TestDocumentsParse:
|
|||||||
payload = payload([doc.id for doc in documents])
|
payload = payload([doc.id for doc in documents])
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.async_parse_documents(**payload)
|
dataset.async_parse_documents(**payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
dataset.async_parse_documents(**payload)
|
dataset.async_parse_documents(**payload)
|
||||||
condition(dataset, payload["document_ids"])
|
condition(dataset, payload["document_ids"])
|
||||||
@ -90,9 +90,9 @@ class TestDocumentsParse:
|
|||||||
document_ids = [doc.id for doc in documents]
|
document_ids = [doc.id for doc in documents]
|
||||||
payload = payload(document_ids)
|
payload = payload(document_ids)
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.async_parse_documents(**payload)
|
dataset.async_parse_documents(**payload)
|
||||||
assert "Documents not found: ['invalid_id']" in str(excinfo.value), str(excinfo.value)
|
assert "Documents not found: ['invalid_id']" in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
condition(dataset, document_ids)
|
condition(dataset, document_ids)
|
||||||
validate_document_details(dataset, document_ids)
|
validate_document_details(dataset, document_ids)
|
||||||
@ -117,9 +117,9 @@ class TestDocumentsParse:
|
|||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_parse_100_files(add_dataset_func, tmp_path):
|
def test_parse_100_files(add_dataset_func, tmp_path):
|
||||||
@wait_for(200, 1, "Document parsing timeout")
|
@wait_for(200, 1, "Document parsing timeout")
|
||||||
def condition(_dataset: DataSet, _count: int):
|
def condition_inner(_dataset: DataSet, _count: int):
|
||||||
documents = _dataset.list_documents(page_size=_count * 2)
|
docs = _dataset.list_documents(page_size=_count * 2)
|
||||||
for document in documents:
|
for document in docs:
|
||||||
if document.run != "DONE":
|
if document.run != "DONE":
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -130,16 +130,16 @@ def test_parse_100_files(add_dataset_func, tmp_path):
|
|||||||
document_ids = [doc.id for doc in documents]
|
document_ids = [doc.id for doc in documents]
|
||||||
|
|
||||||
dataset.async_parse_documents(document_ids=document_ids)
|
dataset.async_parse_documents(document_ids=document_ids)
|
||||||
condition(dataset, count)
|
condition_inner(dataset, count)
|
||||||
validate_document_details(dataset, document_ids)
|
validate_document_details(dataset, document_ids)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_concurrent_parse(add_dataset_func, tmp_path):
|
def test_concurrent_parse(add_dataset_func, tmp_path):
|
||||||
@wait_for(200, 1, "Document parsing timeout")
|
@wait_for(200, 1, "Document parsing timeout")
|
||||||
def condition(_dataset: DataSet, _count: int):
|
def condition_inner(_dataset: DataSet, _count: int):
|
||||||
documents = _dataset.list_documents(page_size=_count * 2)
|
docs = _dataset.list_documents(page_size=_count * 2)
|
||||||
for document in documents:
|
for document in docs:
|
||||||
if document.run != "DONE":
|
if document.run != "DONE":
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -158,5 +158,5 @@ def test_concurrent_parse(add_dataset_func, tmp_path):
|
|||||||
responses = list(as_completed(futures))
|
responses = list(as_completed(futures))
|
||||||
assert len(responses) == count, responses
|
assert len(responses) == count, responses
|
||||||
|
|
||||||
condition(dataset, count)
|
condition_inner(dataset, count)
|
||||||
validate_document_details(dataset, document_ids)
|
validate_document_details(dataset, document_ids)
|
||||||
|
|||||||
@ -39,9 +39,9 @@ class TestDocumentsUpdated:
|
|||||||
document = documents[0]
|
document = documents[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.update({"name": name})
|
document.update({"name": name})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
document.update({"name": name})
|
document.update({"name": name})
|
||||||
updated_doc = dataset.list_documents(id=document.id)[0]
|
updated_doc = dataset.list_documents(id=document.id)[0]
|
||||||
@ -60,9 +60,9 @@ class TestDocumentsUpdated:
|
|||||||
document = documents[0]
|
document = documents[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.update({"meta_fields": meta_fields})
|
document.update({"meta_fields": meta_fields})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
document.update({"meta_fields": meta_fields})
|
document.update({"meta_fields": meta_fields})
|
||||||
|
|
||||||
@ -92,9 +92,9 @@ class TestDocumentsUpdated:
|
|||||||
document = documents[0]
|
document = documents[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.update({"chunk_method": chunk_method})
|
document.update({"chunk_method": chunk_method})
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
document.update({"chunk_method": chunk_method})
|
document.update({"chunk_method": chunk_method})
|
||||||
updated_doc = dataset.list_documents(id=document.id)[0]
|
updated_doc = dataset.list_documents(id=document.id)[0]
|
||||||
@ -193,9 +193,9 @@ class TestDocumentsUpdated:
|
|||||||
_, documents = add_documents
|
_, documents = add_documents
|
||||||
document = documents[0]
|
document = documents[0]
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.update(payload)
|
document.update(payload)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
|
|
||||||
|
|
||||||
class TestUpdateDocumentParserConfig:
|
class TestUpdateDocumentParserConfig:
|
||||||
@ -382,9 +382,9 @@ class TestUpdateDocumentParserConfig:
|
|||||||
update_data = {"chunk_method": chunk_method, "parser_config": parser_config}
|
update_data = {"chunk_method": chunk_method, "parser_config": parser_config}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
document.update(update_data)
|
document.update(update_data)
|
||||||
assert expected_message in str(excinfo.value), str(excinfo.value)
|
assert expected_message in str(exception_info.value), str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
document.update(update_data)
|
document.update(update_data)
|
||||||
updated_doc = dataset.list_documents(id=document.id)[0]
|
updated_doc = dataset.list_documents(id=document.id)[0]
|
||||||
|
|||||||
@ -76,16 +76,16 @@ class TestDocumentsUpload:
|
|||||||
with fp.open("rb") as f:
|
with fp.open("rb") as f:
|
||||||
blob = f.read()
|
blob = f.read()
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.upload_documents([{"display_name": fp.name, "blob": blob}])
|
dataset.upload_documents([{"display_name": fp.name, "blob": blob}])
|
||||||
assert str(excinfo.value) == f"ragflow_test.{file_type}: This type of file has not been supported yet!", str(excinfo.value)
|
assert str(exception_info.value) == f"ragflow_test.{file_type}: This type of file has not been supported yet!", str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_missing_file(self, add_dataset_func):
|
def test_missing_file(self, add_dataset_func):
|
||||||
dataset = add_dataset_func
|
dataset = add_dataset_func
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.upload_documents([])
|
dataset.upload_documents([])
|
||||||
assert str(excinfo.value) == "No file part!", str(excinfo.value)
|
assert str(exception_info.value) == "No file part!", str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_empty_file(self, add_dataset_func, tmp_path):
|
def test_empty_file(self, add_dataset_func, tmp_path):
|
||||||
@ -108,9 +108,9 @@ class TestDocumentsUpload:
|
|||||||
with fp.open("rb") as f:
|
with fp.open("rb") as f:
|
||||||
blob = f.read()
|
blob = f.read()
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
dataset.upload_documents([{"display_name": "", "blob": blob}])
|
dataset.upload_documents([{"display_name": "", "blob": blob}])
|
||||||
assert str(excinfo.value) == "No file selected!", str(excinfo.value)
|
assert str(exception_info.value) == "No file selected!", str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p2
|
@pytest.mark.p2
|
||||||
def test_filename_max_length(self, add_dataset_func, tmp_path):
|
def test_filename_max_length(self, add_dataset_func, tmp_path):
|
||||||
|
|||||||
@ -25,7 +25,8 @@ def add_sessions_with_chat_assistant(request: FixtureRequest, add_chat_assistant
|
|||||||
for chat_assistant in chat_assistants:
|
for chat_assistant in chat_assistants:
|
||||||
try:
|
try:
|
||||||
chat_assistant.delete_sessions(ids=None)
|
chat_assistant.delete_sessions(ids=None)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
print(f"Exception: {e}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
request.addfinalizer(cleanup)
|
request.addfinalizer(cleanup)
|
||||||
@ -40,8 +41,8 @@ def add_sessions_with_chat_assistant_func(request: FixtureRequest, add_chat_assi
|
|||||||
for chat_assistant in chat_assistants:
|
for chat_assistant in chat_assistants:
|
||||||
try:
|
try:
|
||||||
chat_assistant.delete_sessions(ids=None)
|
chat_assistant.delete_sessions(ids=None)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
print(f"Exception: {e}")
|
||||||
|
|
||||||
request.addfinalizer(cleanup)
|
request.addfinalizer(cleanup)
|
||||||
|
|
||||||
|
|||||||
@ -43,9 +43,9 @@ class TestSessionWithChatAssistantCreate:
|
|||||||
chat_assistant.create_session(name=name.upper())
|
chat_assistant.create_session(name=name.upper())
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.create_session(name=name)
|
chat_assistant.create_session(name=name)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
session = chat_assistant.create_session(name=name)
|
session = chat_assistant.create_session(name=name)
|
||||||
assert session.name == name, str(session)
|
assert session.name == name, str(session)
|
||||||
@ -71,6 +71,6 @@ class TestSessionWithChatAssistantCreate:
|
|||||||
chat_assistant = chat_assistants[0]
|
chat_assistant = chat_assistants[0]
|
||||||
|
|
||||||
client.delete_chats(ids=[chat_assistant.id])
|
client.delete_chats(ids=[chat_assistant.id])
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.create_session(name="valid_name")
|
chat_assistant.create_session(name="valid_name")
|
||||||
assert "You do not own the assistant" in str(excinfo.value)
|
assert "You do not own the assistant" in str(exception_info.value)
|
||||||
|
|||||||
@ -46,9 +46,9 @@ class TestSessionWithChatAssistantDelete:
|
|||||||
|
|
||||||
chat_assistant.delete_sessions(**session_ids)
|
chat_assistant.delete_sessions(**session_ids)
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.delete_sessions(**session_ids)
|
chat_assistant.delete_sessions(**session_ids)
|
||||||
assert "The chat doesn't own the session" in str(excinfo.value)
|
assert "The chat doesn't own the session" in str(exception_info.value)
|
||||||
|
|
||||||
@pytest.mark.p3
|
@pytest.mark.p3
|
||||||
def test_duplicate_deletion(self, add_sessions_with_chat_assistant_func):
|
def test_duplicate_deletion(self, add_sessions_with_chat_assistant_func):
|
||||||
@ -98,9 +98,9 @@ class TestSessionWithChatAssistantDelete:
|
|||||||
payload = payload([session.id for session in sessions])
|
payload = payload([session.id for session in sessions])
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.delete_sessions(**payload)
|
chat_assistant.delete_sessions(**payload)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant.delete_sessions(**payload)
|
chat_assistant.delete_sessions(**payload)
|
||||||
|
|
||||||
|
|||||||
@ -34,9 +34,9 @@ class TestSessionsWithChatAssistantList:
|
|||||||
def test_page(self, add_sessions_with_chat_assistant, params, expected_page_size, expected_message):
|
def test_page(self, add_sessions_with_chat_assistant, params, expected_page_size, expected_message):
|
||||||
chat_assistant, _ = add_sessions_with_chat_assistant
|
chat_assistant, _ = add_sessions_with_chat_assistant
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
sessions = chat_assistant.list_sessions(**params)
|
sessions = chat_assistant.list_sessions(**params)
|
||||||
assert len(sessions) == expected_page_size
|
assert len(sessions) == expected_page_size
|
||||||
@ -57,9 +57,9 @@ class TestSessionsWithChatAssistantList:
|
|||||||
def test_page_size(self, add_sessions_with_chat_assistant, params, expected_page_size, expected_message):
|
def test_page_size(self, add_sessions_with_chat_assistant, params, expected_page_size, expected_message):
|
||||||
chat_assistant, _ = add_sessions_with_chat_assistant
|
chat_assistant, _ = add_sessions_with_chat_assistant
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
sessions = chat_assistant.list_sessions(**params)
|
sessions = chat_assistant.list_sessions(**params)
|
||||||
assert len(sessions) == expected_page_size
|
assert len(sessions) == expected_page_size
|
||||||
@ -78,9 +78,9 @@ class TestSessionsWithChatAssistantList:
|
|||||||
def test_orderby(self, add_sessions_with_chat_assistant, params, expected_message):
|
def test_orderby(self, add_sessions_with_chat_assistant, params, expected_message):
|
||||||
chat_assistant, _ = add_sessions_with_chat_assistant
|
chat_assistant, _ = add_sessions_with_chat_assistant
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
|
|
||||||
@ -102,9 +102,9 @@ class TestSessionsWithChatAssistantList:
|
|||||||
def test_desc(self, add_sessions_with_chat_assistant, params, expected_message):
|
def test_desc(self, add_sessions_with_chat_assistant, params, expected_message):
|
||||||
chat_assistant, _ = add_sessions_with_chat_assistant
|
chat_assistant, _ = add_sessions_with_chat_assistant
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
|
|
||||||
@ -121,9 +121,9 @@ class TestSessionsWithChatAssistantList:
|
|||||||
def test_name(self, add_sessions_with_chat_assistant, params, expected_num, expected_message):
|
def test_name(self, add_sessions_with_chat_assistant, params, expected_num, expected_message):
|
||||||
chat_assistant, _ = add_sessions_with_chat_assistant
|
chat_assistant, _ = add_sessions_with_chat_assistant
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
sessions = chat_assistant.list_sessions(**params)
|
sessions = chat_assistant.list_sessions(**params)
|
||||||
if params["name"] == "session_with_chat_assistant_1":
|
if params["name"] == "session_with_chat_assistant_1":
|
||||||
@ -149,9 +149,9 @@ class TestSessionsWithChatAssistantList:
|
|||||||
params = {"id": session_id}
|
params = {"id": session_id}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
list_sessions = chat_assistant.list_sessions(**params)
|
list_sessions = chat_assistant.list_sessions(**params)
|
||||||
if "id" in params and params["id"] == sessions[0].id:
|
if "id" in params and params["id"] == sessions[0].id:
|
||||||
@ -177,9 +177,9 @@ class TestSessionsWithChatAssistantList:
|
|||||||
params = {"id": session_id, "name": name}
|
params = {"id": session_id, "name": name}
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions(**params)
|
chat_assistant.list_sessions(**params)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
list_sessions = chat_assistant.list_sessions(**params)
|
list_sessions = chat_assistant.list_sessions(**params)
|
||||||
assert len(list_sessions) == expected_num
|
assert len(list_sessions) == expected_num
|
||||||
@ -189,7 +189,7 @@ class TestSessionsWithChatAssistantList:
|
|||||||
count = 100
|
count = 100
|
||||||
chat_assistant, _ = add_sessions_with_chat_assistant
|
chat_assistant, _ = add_sessions_with_chat_assistant
|
||||||
with ThreadPoolExecutor(max_workers=5) as executor:
|
with ThreadPoolExecutor(max_workers=5) as executor:
|
||||||
futures = [executor.submit(chat_assistant.list_sessions) for i in range(count)]
|
futures = [executor.submit(chat_assistant.list_sessions) for _ in range(count)]
|
||||||
responses = list(as_completed(futures))
|
responses = list(as_completed(futures))
|
||||||
assert len(responses) == count, responses
|
assert len(responses) == count, responses
|
||||||
|
|
||||||
@ -198,6 +198,6 @@ class TestSessionsWithChatAssistantList:
|
|||||||
chat_assistant, _ = add_sessions_with_chat_assistant
|
chat_assistant, _ = add_sessions_with_chat_assistant
|
||||||
client.delete_chats(ids=[chat_assistant.id])
|
client.delete_chats(ids=[chat_assistant.id])
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
chat_assistant.list_sessions()
|
chat_assistant.list_sessions()
|
||||||
assert "You don't own the assistant" in str(excinfo.value)
|
assert "You don't own the assistant" in str(exception_info.value)
|
||||||
|
|||||||
@ -42,9 +42,9 @@ class TestSessionWithChatAssistantUpdate:
|
|||||||
session.update({"name": payload["name"].upper()})
|
session.update({"name": payload["name"].upper()})
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
session.update(payload)
|
session.update(payload)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
session.update(payload)
|
session.update(payload)
|
||||||
updated_session = chat_assistant.list_sessions(id=session.id)[0]
|
updated_session = chat_assistant.list_sessions(id=session.id)[0]
|
||||||
@ -72,9 +72,9 @@ class TestSessionWithChatAssistantUpdate:
|
|||||||
session = sessions[0]
|
session = sessions[0]
|
||||||
|
|
||||||
if expected_message:
|
if expected_message:
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
session.update(payload)
|
session.update(payload)
|
||||||
assert expected_message in str(excinfo.value)
|
assert expected_message in str(exception_info.value)
|
||||||
else:
|
else:
|
||||||
session.update(payload)
|
session.update(payload)
|
||||||
|
|
||||||
@ -93,6 +93,6 @@ class TestSessionWithChatAssistantUpdate:
|
|||||||
chat_assistant, sessions = add_sessions_with_chat_assistant_func
|
chat_assistant, sessions = add_sessions_with_chat_assistant_func
|
||||||
client.delete_chats(ids=[chat_assistant.id])
|
client.delete_chats(ids=[chat_assistant.id])
|
||||||
|
|
||||||
with pytest.raises(Exception) as excinfo:
|
with pytest.raises(Exception) as exception_info:
|
||||||
sessions[0].update({"name": "valid_name"})
|
sessions[0].update({"name": "valid_name"})
|
||||||
assert "You do not own the session" in str(excinfo.value)
|
assert "You do not own the session" in str(exception_info.value)
|
||||||
|
|||||||
Reference in New Issue
Block a user