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,40 +14,28 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
import pytest
|
||||
from common import create_session_with_chat_assistant, delete_session_with_chat_assistants
|
||||
from common import batch_add_sessions_with_chat_assistant, delete_session_with_chat_assistants
|
||||
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def add_sessions_with_chat_assistant(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)
|
||||
|
||||
session_ids = []
|
||||
for i in range(5):
|
||||
res = create_session_with_chat_assistant(api_key, chat_assistant_ids[0], {"name": f"session_with_chat_assistant_{i}"})
|
||||
session_ids.append(res["data"]["id"])
|
||||
|
||||
return chat_assistant_ids[0], session_ids
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
return chat_assistant_ids[0], batch_add_sessions_with_chat_assistant(api_key, chat_assistant_ids[0], 5)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def add_sessions_with_chat_assistant_func(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)
|
||||
|
||||
session_ids = []
|
||||
for i in range(5):
|
||||
res = create_session_with_chat_assistant(api_key, chat_assistant_ids[0], {"name": f"session_with_chat_assistant_{i}"})
|
||||
session_ids.append(res["data"]["id"])
|
||||
|
||||
return chat_assistant_ids[0], session_ids
|
||||
_, _, chat_assistant_ids = add_chat_assistants
|
||||
return chat_assistant_ids[0], batch_add_sessions_with_chat_assistant(api_key, chat_assistant_ids[0], 5)
|
||||
|
||||
Reference in New Issue
Block a user