test_stop_parse_documents.py


Overview

This file contains automated tests for the stop_parse_documents API endpoint within the InfiniFlow system. The primary focus is to verify the behavior and robustness of stopping document parsing operations in various scenarios, including authorization validation, input validation, concurrency, and edge cases. It also ensures that document parsing states are correctly updated when parsing is stopped.

The tests are written using the pytest framework and leverage utility functions from shared modules for document operations (uploading, listing, parsing, and stopping parsing). Some tests are marked as skipped due to instability or incomplete implementation.


Detailed Explanation

Imported Modules and Utilities


Functions

validate_document_parse_done(auth, dataset_id, document_ids)

Purpose:
Verify that each document in the given list has completed parsing successfully.

Parameters:

Behavior:

Usage Example:

validate_document_parse_done(auth, "dataset123", ["doc1", "doc2"])

validate_document_parse_cancel(auth, dataset_id, document_ids)

Purpose:
Confirm that each document's parsing was canceled correctly.

Parameters:

Behavior:

Usage Example:

validate_document_parse_cancel(auth, "dataset123", ["doc3", "doc4"])

Classes

TestAuthorization

Tests related to authorization validation for the stop_parse_documents API.

test_invalid_auth(self, invalid_auth, expected_code, expected_message)

Parameters:

Behavior:

Test Cases:


TestDocumentsParseStop

Contains parameterized tests for stopping document parsing with various payloads and conditions.

Note: This class is currently marked with @pytest.mark.skip indicating tests are skipped during runs.

test_basic_scenarios(self, HttpApiAuth, add_documents_func, payload, expected_code, expected_message)

Parameters:

Behavior:

Important Implementation Detail:


test_invalid_dataset_id(self, HttpApiAuth, add_documents_func, invalid_dataset_id, expected_code, expected_message)

Parameters:

Behavior:


test_stop_parse_partial_invalid_document_id(self, HttpApiAuth, add_documents_func, payload)

Behavior:


test_repeated_stop_parse(self, HttpApiAuth, add_documents_func)

Behavior:


test_duplicate_stop_parse(self, HttpApiAuth, add_documents_func)

Behavior:


Standalone Tests (Marked as skipped)

test_stop_parse_100_files(HttpApiAuth, add_dataset_func, tmp_path)


test_concurrent_parse(HttpApiAuth, add_dataset_func, tmp_path)


Important Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram

The following Mermaid class diagram summarizes the structure of the test classes and utility functions used in this file:

classDiagram
    class TestAuthorization {
        +test_invalid_auth(invalid_auth, expected_code, expected_message)
    }
    class TestDocumentsParseStop {
        +test_basic_scenarios(HttpApiAuth, add_documents_func, payload, expected_code, expected_message)
        +test_invalid_dataset_id(HttpApiAuth, add_documents_func, invalid_dataset_id, expected_code, expected_message)
        +test_stop_parse_partial_invalid_document_id(HttpApiAuth, add_documents_func, payload)
        +test_repeated_stop_parse(HttpApiAuth, add_documents_func)
        +test_duplicate_stop_parse(HttpApiAuth, add_documents_func)
    }
    class UtilityFunctions {
        +validate_document_parse_done(auth, dataset_id, document_ids)
        +validate_document_parse_cancel(auth, dataset_id, document_ids)
    }
    class ConcurrentTests {
        +test_stop_parse_100_files(HttpApiAuth, add_dataset_func, tmp_path)
        +test_concurrent_parse(HttpApiAuth, add_dataset_func, tmp_path)
    }

    TestAuthorization --> UtilityFunctions
    TestDocumentsParseStop --> UtilityFunctions
    ConcurrentTests --> UtilityFunctions

Summary


This documentation should enable developers and testers to understand the purpose, design, and usage of the tests in this file, and how to extend or maintain them effectively.