test_create_kb.py

Overview

This file contains automated test cases for verifying the functionality and robustness of the "create knowledge base (KB)" API endpoint within the InfiniFlow system. The tests focus on validating authorization mechanisms, capability under high load and concurrency, and the correctness of dataset naming conventions. The test suite leverages pytest as the testing framework and uses hypothesis for property-based testing to cover a wide range of input scenarios.

The primary function under test is create_kb, imported from the common module, which presumably sends a request to the backend to create a new knowledge base or dataset. Authentication is handled via RAGFlowWebApiAuth, and the tests use predefined constants like DATASET_NAME_LIMIT and INVALID_API_TOKEN from configuration files.


Detailed Explanation

Imports and Fixtures

The tests use the clear_datasets fixture to ensure dataset state isolation by cleaning the datasets before each test class runs.


Classes and Their Tests

1. TestAuthorization

Tests the authorization behavior of the create_kb API.

2. TestCapability

Tests the system's capacity to handle a large number of dataset creations and concurrent requests.

3. TestDatasetCreate

Tests validation logic related to dataset naming conventions.


Important Implementation Details


Interaction With Other Parts of the System

The file focuses solely on testing the KB creation API; it does not implement any creation logic itself, but ensures the backend conforms to expected behavior under various conditions.


Usage Examples

Example of how one test case might be invoked (implicitly via pytest CLI):

pytest test_create_kb.py -k TestAuthorization -v

This would run all tests in the TestAuthorization class with verbose output.


Mermaid Class Diagram

Below is a class diagram illustrating the test classes and their main methods:

classDiagram
    class TestAuthorization {
        +test_auth_invalid(invalid_auth, expected_code, expected_message)
    }
    class TestCapability {
        +test_create_kb_1k(WebApiAuth)
        +test_create_kb_concurrent(WebApiAuth)
    }
    class TestDatasetCreate {
        +test_name(WebApiAuth, name)
        +test_name_invalid(WebApiAuth, name, expected_message)
        +test_name_duplicated(WebApiAuth)
        +test_name_case_insensitive(WebApiAuth)
    }

Summary