mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Test: Refactor test fixtures and add SDK session management tests (#8141)
### What problem does this PR solve? - Consolidate HTTP API test fixtures using batch operations (batch_add_chunks, batch_create_chat_assistants) - Fix fixture initialization order in clear_session_with_chat_assistants - Add new SDK API test suite for session management (create/delete/list/update) ### Type of change - [x] Add test cases - [x] Refactoring
This commit is contained in:
@ -14,12 +14,14 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
from time import sleep
|
||||
|
||||
import pytest
|
||||
from common import (
|
||||
add_chunk,
|
||||
batch_add_chunks,
|
||||
batch_create_chat_assistants,
|
||||
batch_create_datasets,
|
||||
bulk_upload_documents,
|
||||
create_chat_assistant,
|
||||
delete_chat_assistants,
|
||||
delete_datasets,
|
||||
delete_session_with_chat_assistants,
|
||||
@ -103,14 +105,14 @@ def clear_chat_assistants(request, api_key):
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def clear_session_with_chat_assistants(request, api_key, add_chat_assistants):
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
|
||||
def cleanup():
|
||||
for chat_assistant_id in chat_assistant_ids:
|
||||
delete_session_with_chat_assistants(api_key, chat_assistant_id)
|
||||
|
||||
request.addfinalizer(cleanup)
|
||||
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def add_dataset(request, api_key):
|
||||
@ -145,16 +147,8 @@ def add_chunks(api_key, add_document):
|
||||
dataset_id, document_id = add_document
|
||||
parse_documents(api_key, dataset_id, {"document_ids": [document_id]})
|
||||
condition(api_key, dataset_id)
|
||||
|
||||
chunk_ids = []
|
||||
for i in range(4):
|
||||
res = add_chunk(api_key, dataset_id, document_id, {"content": f"chunk test {i}"})
|
||||
chunk_ids.append(res["data"]["chunk"]["id"])
|
||||
|
||||
# issues/6487
|
||||
from time import sleep
|
||||
|
||||
sleep(1)
|
||||
chunk_ids = batch_add_chunks(api_key, dataset_id, document_id, 4)
|
||||
sleep(1) # issues/6487
|
||||
return dataset_id, document_id, chunk_ids
|
||||
|
||||
|
||||
@ -168,10 +162,4 @@ def add_chat_assistants(request, api_key, add_document):
|
||||
dataset_id, document_id = add_document
|
||||
parse_documents(api_key, dataset_id, {"document_ids": [document_id]})
|
||||
condition(api_key, dataset_id)
|
||||
|
||||
chat_assistant_ids = []
|
||||
for i in range(5):
|
||||
res = create_chat_assistant(api_key, {"name": f"test_chat_assistant_{i}", "dataset_ids": [dataset_id]})
|
||||
chat_assistant_ids.append(res["data"]["id"])
|
||||
|
||||
return dataset_id, document_id, chat_assistant_ids
|
||||
return dataset_id, document_id, batch_create_chat_assistants(api_key, 5)
|
||||
|
||||
Reference in New Issue
Block a user