test_delete_dialogs.py
Overview
test_delete_dialogs.py is a comprehensive test suite designed to validate the functionality, robustness, and correctness of the dialog deletion API endpoints in the InfiniFlow system. It uses the pytest testing framework to define and run tests that ensure dialogs can be deleted under various conditions including authorization checks, single and batch deletions, edge cases, concurrent operations, and special character handling.
This file primarily tests the following behaviors related to dialog deletion:
Authorization enforcement and invalid access handling.
Deletion of single dialogs.
Deletion of multiple dialogs in batch.
Partial deletion scenarios.
Handling of non-existent dialogs and invalid inputs.
Concurrent deletion operations.
Idempotency of the delete operation.
Deletion of dialogs with special characters.
Preservation of dialogs owned by other users.
By covering these scenarios, this test file ensures that the dialog deletion feature in InfiniFlow is reliable, secure, and behaves as expected across different usage patterns.
Classes and Methods
Class: TestAuthorization
This test class focuses on verifying that dialog deletion is properly restricted to authorized users.
Methods
test_auth_invalid(self, invalid_auth, expected_code, expected_message, add_dialog_func)Tests the API's response when dialog deletion is attempted with invalid or missing authorization tokens.
Parameters:
invalid_auth: Authorization object or None, representing invalid or missing auth.expected_code: Expected HTTP-like response code (e.g., 401).expected_message: Expected error message string.add_dialog_func: pytest fixture that adds a dialog and returns the dialog id.
Returns: None (asserts results)
Usage Example:
def test_auth_invalid_example(self, add_dialog_func): invalid_auth = None expected_code = 401 expected_message = "<Unauthorized '401: Unauthorized'>" _, dialog_id = add_dialog_func payload = {"dialog_ids": [dialog_id]} res = delete_dialog(invalid_auth, payload) assert res["code"] == expected_code assert res["message"] == expected_message
Class: TestDialogDelete
This class includes multiple test cases for the dialog deletion endpoint, covering various scenarios of usage and edge cases.
Methods
test_delete_single_dialog(self, WebApiAuth, add_dialog_func)Tests deleting a single dialog and verifies that it no longer appears in the dialog list.
test_delete_multiple_dialogs(self, WebApiAuth, add_dialogs_func)Tests batch deletion of multiple dialogs and verifies all are removed.
test_delete_partial_dialogs(self, WebApiAuth, add_dialogs_func)Tests deletion of a subset of dialogs and verifies only those are removed while others remain.
test_delete_nonexistent_dialog(self, WebApiAuth)Attempts to delete a dialog ID that does not exist and expects an authorization error.
test_delete_empty_dialog_ids(self, WebApiAuth)Tests deleting with an empty list of dialog IDs, expecting success with no effect.
test_delete_missing_dialog_ids(self, WebApiAuth)Tests deleting with a payload missing the required
dialog_idskey, expecting an error.test_delete_invalid_dialog_ids_format(self, WebApiAuth)Tests deletion with an invalid format for
dialog_ids(not a list), expecting an error.test_delete_mixed_valid_invalid_dialogs(self, WebApiAuth, add_dialog_func)Tests deletion with a mixture of valid and invalid dialog IDs, expecting failure and no deletion.
test_delete_dialog_concurrent(self, WebApiAuth, add_dialogs_func)Tests concurrent deletion of dialogs using a thread pool to simulate simultaneous requests.
test_delete_dialog_idempotent(self, WebApiAuth, add_dialog_func)Tests that deleting the same dialog multiple times does not cause errors (idempotency).
test_delete_large_batch_dialogs(self, WebApiAuth, add_document)Tests deletion of a large batch (50) of dialogs to verify scalability and performance.
test_delete_dialog_with_special_characters(self, WebApiAuth)Tests creation and deletion of dialogs with special and Unicode characters in the name and description.
test_delete_dialog_preserves_other_user_dialogs(self, WebApiAuth, add_dialog_func)Tests that deleting dialogs owned by one user does not affect dialogs owned by others.
Functions (Imported)
This test file makes extensive use of imported utility functions from other modules:
batch_create_dialogs(auth, count, dataset_ids): Creates multiple dialogs in batch.create_dialog(auth, payload): Creates a single dialog.delete_dialog(auth, payload): Deletes dialogs specified by dialog IDs.list_dialogs(auth): Lists all dialogs accessible by the authenticated user.
These functions abstract the API calls and enable concise test implementations.
Important Implementation Details
Authorization Testing: Tests verify that unauthorized or invalid tokens result in proper 401 Unauthorized responses.
Parameter Validation: Tests check that missing or improperly formatted request payloads trigger appropriate error codes and messages.
Concurrency: The concurrent deletion test uses
ThreadPoolExecutorto simulate parallel delete requests and ensures thread safety and consistency.Idempotency: Repeated deletions of the same dialog do not cause errors, ensuring robustness in client retry scenarios.
Unicode Support: Dialogs with names and descriptions containing special characters and emojis are successfully created and deleted, verifying Unicode handling.
Ownership Enforcement: Deletion operations are restricted to dialog owners, preventing unauthorized deletion of others' dialogs.
Batch Operations: Both batch creation and batch deletion are tested to verify performance and correctness when handling large numbers of dialogs.
Interaction with Other Parts of the System
Authentication (
libs.auth.RAGFlowWebApiAuth): The tests use authentication tokens to simulate authorized and unauthorized API access.Dialog API (
commonmodule): The test suite depends on shared utility functions for dialog CRUD operations.Configuration (
configs): Invalid API tokens are imported from configuration for negative tests.Pytest Fixtures: The test methods rely on fixtures such as
WebApiAuth,add_dialog_func,add_dialogs_func,add_document, andclear_dialogsfor setup and teardown, which are defined externally in the test environment.
This file is tightly coupled with the dialog management subsystem and tests the dialog deletion endpoint's adherence to business rules, security, and data integrity.
Visual Diagram
classDiagram
class TestAuthorization {
+test_auth_invalid(invalid_auth, expected_code, expected_message, add_dialog_func)
}
class TestDialogDelete {
+test_delete_single_dialog(WebApiAuth, add_dialog_func)
+test_delete_multiple_dialogs(WebApiAuth, add_dialogs_func)
+test_delete_partial_dialogs(WebApiAuth, add_dialogs_func)
+test_delete_nonexistent_dialog(WebApiAuth)
+test_delete_empty_dialog_ids(WebApiAuth)
+test_delete_missing_dialog_ids(WebApiAuth)
+test_delete_invalid_dialog_ids_format(WebApiAuth)
+test_delete_mixed_valid_invalid_dialogs(WebApiAuth, add_dialog_func)
+test_delete_dialog_concurrent(WebApiAuth, add_dialogs_func)
+test_delete_dialog_idempotent(WebApiAuth, add_dialog_func)
+test_delete_large_batch_dialogs(WebApiAuth, add_document)
+test_delete_dialog_with_special_characters(WebApiAuth)
+test_delete_dialog_preserves_other_user_dialogs(WebApiAuth, add_dialog_func)
}
TestAuthorization --> delete_dialog
TestDialogDelete --> delete_dialog
TestDialogDelete --> list_dialogs
TestDialogDelete --> create_dialog
TestDialogDelete --> batch_create_dialogs
Summary
test_delete_dialogs.py is a critical quality assurance component ensuring that dialog deletion in InfiniFlow is secure, reliable, and behaves correctly across diverse scenarios. It validates authorization, input validation, concurrent operations, and batch processing, while also verifying that deletion actions respect ownership boundaries and handle Unicode data gracefully. The tests use pytest fixtures and common helper functions to interact with the actual dialog API, making this suite a key part of the system's automated testing strategy.