test_delete_chunks.py

Overview

The test_delete_chunks.py file contains a comprehensive suite of automated test cases designed to verify the correctness, robustness, and security of the chunk deletion functionality in the InfiniFlow system. Specifically, it tests the delete_chunks API endpoint, which handles the removal of data chunks from documents within datasets.

This file uses the pytest testing framework and covers scenarios including authorization checks, validation of dataset and document IDs, handling of invalid or duplicate chunk IDs, concurrency in deletion operations, and performance on large-scale chunk deletion. It also validates the system's response messages and codes to ensure they conform to expected error handling and success criteria.

Detailed Explanation

Imports


Class: TestAuthorization

Tests authorization failures for the delete_chunks API.

Method: test_invalid_auth

test = TestAuthorization()
test.test_invalid_auth(None, 0, "`Authorization` can't be empty")

Class: TestChunksDeletion

Contains multiple test cases that validate different aspects of chunk deletion.


Method: test_invalid_dataset_id


Method: test_invalid_document_id


Method: test_delete_partial_invalid_id


Method: test_repeated_deletion


Method: test_duplicate_deletion


Method: test_concurrent_deletion


Method: test_delete_1k


Method: test_basic_scenarios


Important Implementation Details and Algorithms


Interaction with Other System Components


Usage Examples

Example: Test invalid authorization

auth = RAGFlowHttpApiAuth(INVALID_API_TOKEN)
response = delete_chunks(auth, "dataset_id", "document_id")
assert response["code"] == 109
assert "API key is invalid" in response["message"]

Example: Test deleting chunks with some invalid IDs

valid_chunk_ids = ["chunk1", "chunk2", "chunk3", "chunk4", "chunk5"]
payload = {"chunk_ids": ["invalid_id"] + valid_chunk_ids}
response = delete_chunks(auth, "dataset_id", "document_id", payload)
assert response["code"] == 102
assert "deleted chunks 4, expect 5" in response["message"]

Mermaid Diagram: Class and Test Structure

classDiagram
    class TestAuthorization {
        +test_invalid_auth(auth, expected_code, expected_message)
    }
    class TestChunksDeletion {
        +test_invalid_dataset_id(get_http_api_auth, add_chunks_func, dataset_id, expected_code, expected_message)
        +test_invalid_document_id(get_http_api_auth, add_chunks_func, document_id, expected_code, expected_message)
        +test_delete_partial_invalid_id(get_http_api_auth, add_chunks_func, payload)
        +test_repeated_deletion(get_http_api_auth, add_chunks_func)
        +test_duplicate_deletion(get_http_api_auth, add_chunks_func)
        +test_concurrent_deletion(get_http_api_auth, add_document)
        +test_delete_1k(get_http_api_auth, add_document)
        +test_basic_scenarios(get_http_api_auth, add_chunks_func, payload, expected_code, expected_message, remaining)
    }

Summary

This test suite is essential for maintaining the integrity and reliability of the chunk deletion feature within the InfiniFlow system, ensuring that data management behaves as expected under various edge cases and load conditions.