test_upload_documents.py

Overview

test_upload_documents.py is a test suite designed to validate the functionality, robustness, and security of the document upload feature within the InfiniFlow system. Using the pytest framework, it systematically tests various scenarios related to uploading documents to knowledge bases (KBs) via a web API.

The file contains tests for:

This suite ensures the document upload endpoint behaves correctly under diverse conditions and meets the expected API contract.


Detailed Explanation of Classes and Methods

Class: TestAuthorization

This class focuses on verifying that the API properly handles authorization failures.

Method: test_invalid_auth(invalid_auth, expected_code, expected_message)


Class: TestDocumentsUpload

This class contains multiple test methods to validate various document upload scenarios.

Method: test_valid_single_upload(WebApiAuth, add_dataset_func, tmp_path)


Method: test_file_type_validation(WebApiAuth, add_dataset_func, generate_test_files, request)


Method: test_unsupported_file_type(WebApiAuth, add_dataset_func, tmp_path, file_type)


Method: test_missing_file(WebApiAuth, add_dataset_func)


Method: test_empty_file(WebApiAuth, add_dataset_func, tmp_path)


Method: test_filename_empty(WebApiAuth, add_dataset_func, tmp_path)


Method: test_filename_exceeds_max_length(WebApiAuth, add_dataset_func, tmp_path)


Method: test_invalid_kb_id(WebApiAuth, tmp_path)


Method: test_duplicate_files(WebApiAuth, add_dataset_func, tmp_path)


Method: test_filename_special_characters(WebApiAuth, add_dataset_func, tmp_path)


Method: test_multiple_files(WebApiAuth, add_dataset_func, tmp_path)


Method: test_concurrent_upload(WebApiAuth, add_dataset_func, tmp_path)


Important Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram

classDiagram
    class TestAuthorization {
        +test_invalid_auth(invalid_auth, expected_code, expected_message)
    }
    class TestDocumentsUpload {
        +test_valid_single_upload(WebApiAuth, add_dataset_func, tmp_path)
        +test_file_type_validation(WebApiAuth, add_dataset_func, generate_test_files, request)
        +test_unsupported_file_type(WebApiAuth, add_dataset_func, tmp_path, file_type)
        +test_missing_file(WebApiAuth, add_dataset_func)
        +test_empty_file(WebApiAuth, add_dataset_func, tmp_path)
        +test_filename_empty(WebApiAuth, add_dataset_func, tmp_path)
        +test_filename_exceeds_max_length(WebApiAuth, add_dataset_func, tmp_path)
        +test_invalid_kb_id(WebApiAuth, tmp_path)
        +test_duplicate_files(WebApiAuth, add_dataset_func, tmp_path)
        +test_filename_special_characters(WebApiAuth, add_dataset_func, tmp_path)
        +test_multiple_files(WebApiAuth, add_dataset_func, tmp_path)
        +test_concurrent_upload(WebApiAuth, add_dataset_func, tmp_path)
    }
    TestAuthorization ..> upload_documents : uses
    TestDocumentsUpload ..> upload_documents : uses
    TestDocumentsUpload ..> create_txt_file : uses
    TestDocumentsUpload ..> list_kbs : uses
    TestAuthorization ..> RAGFlowWebApiAuth : uses
    TestDocumentsUpload ..> RAGFlowWebApiAuth : uses

Summary