test_delete_chat_assistants.py

Overview

This file contains a suite of automated tests for the deletion functionality of chat assistants in the InfiniFlow platform. It primarily validates the behavior of the delete_chat_assistants API endpoint under various scenarios, including authorization validation, input correctness, concurrency, and edge cases such as duplicate or invalid IDs.

The tests use the pytest framework and leverage helper functions from other modules (common, configs, libs.auth) to perform setup, authentication, and API interactions. The goal is to ensure that the deletion process is robust, correctly handles errors, and maintains data integrity.


Test Classes and Their Functionalities

1. TestAuthorization

Purpose:
Validates that the delete_chat_assistants API enforces proper authorization and returns appropriate error codes and messages when invalid or missing credentials are used.

Key Method:


2. TestChatAssistantsDelete

Purpose:
Tests the core functionality of deleting chat assistants, including handling of various payloads, invalid IDs, duplicates, repeated deletions, and concurrency.

Key Methods:


Important Implementation Details and Algorithms


Interactions with Other Parts of the System


Usage Example

def test_delete_single_assistant(HttpApiAuth, add_chat_assistants_func):
    _, _, chat_assistant_ids = add_chat_assistants_func
    payload = {"ids": chat_assistant_ids[:1]}
    res = delete_chat_assistants(HttpApiAuth, payload)
    assert res["code"] == 0

    remaining = list_chat_assistants(HttpApiAuth)
    assert len(remaining["data"]) == len(chat_assistant_ids) - 1

Mermaid Class Diagram

classDiagram
    class TestAuthorization {
        +test_invalid_auth(invalid_auth, expected_code, expected_message)
    }

    class TestChatAssistantsDelete {
        +test_basic_scenarios(HttpApiAuth, add_chat_assistants_func, payload, expected_code, expected_message, remaining)
        +test_delete_partial_invalid_id(HttpApiAuth, add_chat_assistants_func, payload)
        +test_repeated_deletion(HttpApiAuth, add_chat_assistants_func)
        +test_duplicate_deletion(HttpApiAuth, add_chat_assistants_func)
        +test_concurrent_deletion(HttpApiAuth)
        +test_delete_10k(HttpApiAuth)
    }

Summary

test_delete_chat_assistants.py is a critical part of the InfiniFlow testing suite targeting the chat assistant deletion API. It ensures the API correctly handles authentication, validates input payloads, deals gracefully with invalid or duplicate IDs, and supports high concurrency and large batch operations without failure. Through comprehensive parameterized and concurrent tests, it safeguards the robustness and reliability of chat assistant management in the platform.