test_upload_documents.py

Overview

test_upload_documents.py is a comprehensive test suite designed to validate the document upload functionality of the InfiniFlow system, specifically focusing on API interactions related to uploading documents to datasets. The tests cover authorization checks, file type validations, file naming constraints, dataset ID verification, handling of duplicates, large batch uploads, and concurrency.

The file uses the pytest framework and integrates with common utility functions and fixtures to simulate real-world upload scenarios. It ensures the robustness, security, and correctness of the document upload API endpoints.


Detailed Breakdown

Imports and Dependencies


Classes and Tests

Class: TestAuthorization


Class: TestDocumentsUpload


Important Implementation Details


Interaction with Other Components


Usage Examples

Example: Uploading a Single Valid File

def test_valid_single_upload(get_http_api_auth, add_dataset_func, tmp_path):
    dataset_id = add_dataset_func
    fp = create_txt_file(tmp_path / "ragflow_test.txt")
    res = upload_documnets(get_http_api_auth, dataset_id, [fp])
    assert res["code"] == 0
    assert res["data"][0]["dataset_id"] == dataset_id
    assert res["data"][0]["name"] == fp.name

This example demonstrates how to create a text file, upload it to a dataset using authenticated API calls, and assert the expected success response.


Mermaid Class Diagram

classDiagram
    class TestAuthorization {
        +test_invalid_auth(auth, expected_code, expected_message)
    }
    class TestDocumentsUpload {
        +test_valid_single_upload(get_http_api_auth, add_dataset_func, tmp_path)
        +test_file_type_validation(get_http_api_auth, add_dataset_func, generate_test_files, request)
        +test_unsupported_file_type(get_http_api_auth, add_dataset_func, tmp_path, file_type)
        +test_missing_file(get_http_api_auth, add_dataset_func)
        +test_empty_file(get_http_api_auth, add_dataset_func, tmp_path)
        +test_filename_empty(get_http_api_auth, add_dataset_func, tmp_path)
        +test_filename_exceeds_max_length(get_http_api_auth, add_dataset_func, tmp_path)
        +test_invalid_dataset_id(get_http_api_auth, tmp_path)
        +test_duplicate_files(get_http_api_auth, add_dataset_func, tmp_path)
        +test_same_file_repeat(get_http_api_auth, add_dataset_func, tmp_path)
        +test_filename_special_characters(get_http_api_auth, add_dataset_func, tmp_path)
        +test_multiple_files(get_http_api_auth, add_dataset_func, tmp_path)
        +test_concurrent_upload(get_http_api_auth, add_dataset_func, tmp_path)
    }
    TestAuthorization <|-- TestDocumentsUpload

Summary

test_upload_documents.py is a robust and well-structured test suite that ensures the integrity and correctness of the document upload feature in the InfiniFlow project. By covering authorization, file validation, error conditions, concurrency, and edge cases, it provides high confidence in the upload API's behavior under various conditions. Integration with shared utilities and adherence to pytest conventions make it maintainable and extensible for future enhancements.


End of Documentation for test_upload_documents.py