test_create_dataset.py

Overview

test_create_dataset.py is a comprehensive test suite designed to validate the dataset creation functionality of the InfiniFlow system through its HTTP API. Utilizing the pytest framework combined with property-based testing from hypothesis, this file rigorously tests various aspects of dataset creation including authorization, input validation, concurrency, and detailed field-specific constraints.

The primary function under test is create_dataset, which interacts with the API to create datasets with different attributes. This test suite ensures that the API behaves correctly for valid inputs and gracefully handles invalid inputs, enforcing business rules and data integrity.


Detailed Explanation

Imports and Dependencies


Classes and Test Cases

1. TestAuthorization

Tests related to API authorization when creating a dataset.

2. TestRquest (likely a typo, should be TestRequest)

Tests API requests with invalid content types and malformed JSON payloads.

3. TestCapability

Tests system capacity and concurrency.

4. TestDatasetCreate

Extensive tests on dataset creation validating different fields and constraints.


Important Implementation Details and Algorithms


Interactions with Other Parts of the System

This file acts as a critical quality gate ensuring the dataset creation endpoint behaves correctly, enforcing API contract and business rules.


Usage Examples

Example of a simple test case usage inside this file:

@pytest.mark.p1
@given(name=valid_names())
@example("a" * 128)
@settings(max_examples=20)
def test_name(self, get_http_api_auth, name):
    res = create_dataset(get_http_api_auth, {"name": name})
    assert res["code"] == 0
    assert res["data"]["name"] == name

This test uses a property-based approach generating various valid names to verify that dataset creation succeeds with those names.


Mermaid Diagram: Test Class Structure

classDiagram
    class TestAuthorization {
        +test_auth_invalid(auth, expected_code, expected_message)
    }
    class TestRquest {
        +test_content_type_bad(get_http_api_auth)
        +test_payload_bad(get_http_api_auth, payload, expected_message)
    }
    class TestCapability {
        +test_create_dataset_1k(get_http_api_auth)
        +test_create_dataset_concurrent(get_http_api_auth)
    }
    class TestDatasetCreate {
        +test_name(get_http_api_auth, name)
        +test_name_invalid(get_http_api_auth, name, expected_message)
        +test_name_duplicated(get_http_api_auth)
        +test_name_case_insensitive(get_http_api_auth)
        +test_avatar(get_http_api_auth, tmp_path)
        +test_avatar_exceeds_limit_length(get_http_api_auth)
        +test_avatar_invalid_prefix(get_http_api_auth, tmp_path, name, prefix, expected_message)
        +test_avatar_unset(get_http_api_auth)
        +test_avatar_none(get_http_api_auth)
        +test_description(get_http_api_auth)
        +test_description_exceeds_limit_length(get_http_api_auth)
        +test_description_unset(get_http_api_auth)
        +test_description_none(get_http_api_auth)
        +test_embedding_model(get_http_api_auth, name, embedding_model)
        +test_embedding_model_invalid(get_http_api_auth, name, embedding_model)
        +test_embedding_model_format(get_http_api_auth, name, embedding_model)
        +test_embedding_model_unset(get_http_api_auth)
        +test_embedding_model_none(get_http_api_auth)
        +test_permission(get_http_api_auth, name, permission)
        +test_permission_invalid(get_http_api_auth, name, permission)
        +test_permission_unset(get_http_api_auth)
        +test_permission_none(get_http_api_auth)
        +test_chunk_method(get_http_api_auth, name, chunk_method)
        +test_chunk_method_invalid(get_http_api_auth, name, chunk_method)
        +test_chunk_method_unset(get_http_api_auth)
        +test_chunk_method_none(get_http_api_auth)
        +test_pagerank(get_http_api_auth, name, pagerank)
        +test_pagerank_invalid(get_http_api_auth, name, pagerank, expected_message)
        +test_pagerank_unset(get_http_api_auth)
        +test_pagerank_none(get_http_api_auth)
        +test_parser_config(get_http_api_auth, name, parser_config)
        +test_parser_config_invalid(get_http_api_auth, name, parser_config, expected_message)
        +test_parser_config_empty(get_http_api_auth)
        +test_parser_config_unset(get_http_api_auth)
        +test_parser_config_none(get_http_api_auth)
        +test_unsupported_field(get_http_api_auth, payload)
    }

    TestAuthorization <|-- TestRquest

Summary


This documentation should help developers understand the purpose, scope, and detailed functionality of the test_create_dataset.py file, supporting maintenance, extension, and debugging efforts.