test_rm_documents.py

Overview

This file contains automated test cases focused on verifying the document deletion functionality within the InfiniFlow system. It extensively tests the delete_document API endpoint, covering scenarios around authorization, input validation, concurrency, and system behavior when deleting multiple documents. The tests use the pytest framework for structuring tests and assertions.

The primary goals of this test suite are to ensure that:

Classes and Functions

TestAuthorization

Purpose:
This test class verifies that the API properly enforces authorization rules for the document deletion endpoint.

Method: test_invalid_auth

test_auth = RAGFlowWebApiAuth("invalid_token")
res = delete_document(test_auth)
assert res["code"] == 401
assert "<Unauthorized" in res["message"]

TestDocumentsDeletion

Purpose:
These tests validate various document deletion scenarios, focusing on input validation, repeated deletion attempts, and expected system state after deletion.

Method: test_basic_scenarios

payload = {"doc_id": "some_doc_id"}
res = delete_document(WebApiAuth, payload)
assert res["code"] == 0  # success

Method: test_repeated_deletion


test_concurrent_deletion


test_delete_100

Important Implementation Details

Interaction with Other Components

Visual Diagram

classDiagram
    class TestAuthorization {
        +test_invalid_auth(invalid_auth, expected_code, expected_message)
    }
    class TestDocumentsDeletion {
        +test_basic_scenarios(WebApiAuth, add_documents_func, payload, expected_code, expected_message, remaining)
        +test_repeated_deletion(WebApiAuth, add_documents_func)
    }
    class Functions {
        +test_concurrent_deletion(WebApiAuth, add_dataset, tmp_path)
        +test_delete_100(WebApiAuth, add_dataset, tmp_path)
    }
    TestAuthorization --|> pytest
    TestDocumentsDeletion --|> pytest
    Functions --|> pytest

Summary

test_rm_documents.py is a critical test suite verifying document deletion in the InfiniFlow platform. It ensures robustness against invalid authorizations, input errors, and concurrency issues. By validating both error handling and success paths, it helps maintain the integrity and reliability of document management APIs. The file collaborates closely with common utility functions and authentication mechanisms to set up realistic test scenarios.