test_list_sessions_with_chat_assistant.py


Overview

This file contains automated tests for the functionality related to listing sessions associated with chat assistants in the InfiniFlow platform. It primarily focuses on validating the API endpoint behavior that retrieves session lists filtered and paginated by various parameters, ensuring correct authorization, parameter handling, sorting, filtering, and concurrency robustness.

The tests are implemented using the pytest framework and cover both positive and negative cases, including invalid authorization, edge cases in pagination, sorting order, filtering by name and session IDs, and concurrent access scenarios.


Detailed Component Descriptions

Imports and Dependencies


Classes and Methods

1. TestAuthorization

Tests related to the authorization mechanism when listing sessions with chat assistants.

Method: test_invalid_auth


2. TestSessionsWithChatAssistantList

Contains extensive test cases for the listing sessions API, focusing on parameter validation, filtering, sorting, and concurrency.


Parameterized Tests in this Class

a. test_page

b. test_page_size

c. test_orderby

d. test_desc

e. test_name

f. test_id

g. test_name_and_id

Additional Tests

h. test_concurrent_list

i. test_invalid_params

j. test_list_chats_after_deleting_associated_chat_assistant

Implementation Details and Algorithms


Interaction with Other System Components


Usage Example of the Main Tested Function

from libs.auth import RAGFlowHttpApiAuth
from common import list_session_with_chat_assistants

auth = RAGFlowHttpApiAuth("valid_api_token")
chat_assistant_id = "assistant_123"
params = {
    "page": 1,
    "page_size": 5,
    "orderby": "create_time",
    "desc": True,
    "name": "support_session"
}

response = list_session_with_chat_assistants(auth, chat_assistant_id, params=params)

if response["code"] == 0:
    for session in response["data"]:
        print(session["id"], session["name"], session["create_time"])
else:
    print(f"Error: {response['message']}")

Mermaid Diagram: Class Structure and Test Organization

classDiagram
    class TestAuthorization {
        +test_invalid_auth(invalid_auth, expected_code, expected_message)
    }
    class TestSessionsWithChatAssistantList {
        +test_page(params, expected_code, expected_page_size, expected_message)
        +test_page_size(params, expected_code, expected_page_size, expected_message)
        +test_orderby(params, expected_code, assertions, expected_message)
        +test_desc(params, expected_code, assertions, expected_message)
        +test_name(params, expected_code, expected_num, expected_message)
        +test_id(session_id, expected_code, expected_num, expected_message)
        +test_name_and_id(session_id, name, expected_code, expected_num, expected_message)
        +test_concurrent_list()
        +test_invalid_params()
        +test_list_chats_after_deleting_associated_chat_assistant()
    }
    TestSessionsWithChatAssistantList ..> "common.list_session_with_chat_assistants"
    TestAuthorization ..> "common.list_session_with_chat_assistants"
    TestSessionsWithChatAssistantList ..> "common.delete_chat_assistants"
    TestAuthorization ..> "libs.auth.RAGFlowHttpApiAuth"
    TestSessionsWithChatAssistantList ..> "libs.auth.RAGFlowHttpApiAuth"

Summary

This test suite is critical in maintaining the reliability and correctness of the session listing features associated with chat assistants. It ensures that:

The usage of pytest parametric tests and concurrency testing indicates a thorough approach to quality assurance for this part of the system.


End of Documentation for test_list_sessions_with_chat_assistant.py