test_delete_documents.py

Overview

test_delete_documents.py is a test suite designed to validate the functionality and robustness of the document deletion API endpoints within the InfiniFlow system. It leverages the pytest framework to organize and run a series of automated tests that check authorization, input validation, concurrency handling, and performance when deleting documents from datasets.

The tests primarily focus on the delete_documnets API (noting the consistent misspelling in the source), ensuring that it behaves correctly under various scenarios including invalid authorization, invalid input payloads, partial and full deletions, repeated or duplicate deletions, and high-volume deletion requests.


Detailed Description of Classes and Functions

Imported Modules and Dependencies


Class: TestAuthorization

Purpose:
Tests how the deletion API handles authorization failures.

Method: test_invalid_auth(auth, expected_code, expected_message)

auth = RAGFlowHttpApiAuth(INVALID_API_TOKEN)
res = delete_documnets(auth, "dataset_id")
assert res["code"] == 109
assert res["message"] == "Authentication error: API key is invalid!"

Class: TestDocumentsDeletion

Purpose:
Contains comprehensive tests for document deletion with varying input payloads and dataset states.

Method: test_basic_scenarios(get_http_api_auth, add_documents_func, payload, expected_code, expected_message, remaining)

Method: test_invalid_dataset_id(get_http_api_auth, add_documents_func, dataset_id, expected_code, expected_message)

Method: test_delete_partial_invalid_id(get_http_api_auth, add_documents_func, payload)

Method: test_repeated_deletion(get_http_api_auth, add_documents_func)

Method: test_duplicate_deletion(get_http_api_auth, add_documents_func)


Function: test_concurrent_deletion(get_http_api_auth, add_dataset, tmp_path)

with ThreadPoolExecutor(max_workers=5) as executor:
    futures = [executor.submit(delete_documnets, auth, dataset_id, {"ids": [doc_id]}) for doc_id in document_ids]
responses = [f.result() for f in futures]
assert all(r["code"] == 0 for r in responses)

Function: test_delete_1k(get_http_api_auth, add_dataset, tmp_path)


Important Implementation Details and Algorithms


Interaction with Other System Components


Usage and Running Tests

Example command to run all tests:

pytest test_delete_documents.py

Mermaid Class Diagram

classDiagram
    class TestAuthorization {
        +test_invalid_auth(auth, expected_code, expected_message)
    }
    class TestDocumentsDeletion {
        +test_basic_scenarios(get_http_api_auth, add_documents_func, payload, expected_code, expected_message, remaining)
        +test_invalid_dataset_id(get_http_api_auth, add_documents_func, dataset_id, expected_code, expected_message)
        +test_delete_partial_invalid_id(get_http_api_auth, add_documents_func, payload)
        +test_repeated_deletion(get_http_api_auth, add_documents_func)
        +test_duplicate_deletion(get_http_api_auth, add_documents_func)
    }
    TestAuthorization ..> RAGFlowHttpApiAuth : uses
    TestDocumentsDeletion ..> delete_documnets : calls
    TestDocumentsDeletion ..> list_documnets : calls

    %% Standalone test functions
    class test_concurrent_deletion {
        +test_concurrent_deletion(get_http_api_auth, add_dataset, tmp_path)
    }
    class test_delete_1k {
        +test_delete_1k(get_http_api_auth, add_dataset, tmp_path)
    }
    test_concurrent_deletion ..> ThreadPoolExecutor : uses
    test_concurrent_deletion ..> delete_documnets : calls
    test_delete_1k ..> bulk_upload_documents : calls
    test_delete_1k ..> delete_documnets : calls

Summary

test_delete_documents.py is a critical component of the InfiniFlow testing infrastructure, ensuring that document deletion operations are secure, reliable, and performant. It validates error handling, concurrency, and edge cases, thereby helping maintain the integrity of the document management subsystem.