Test Models Mocking
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Test Models Mocking in the flext-tap-oracle project provides a structured framework for simulating Oracle database entities, Singer protocol streams, and extraction configurations. This system allows for rigorous unit and integration testing without requiring a live Oracle production environment by utilizing composition-based model definitions and runtime-checkable protocols.
The architecture relies on the TestsFlextTapOracleModels facade, which aggregates domain-specific test models under the TapOracle namespace. These models facilitate the validation of connection strings, stream selection logic, and data extraction parameters during the testing lifecycle.
Sources: tests/models.py:15-38, tests/protocols.py:17-35
Architecture and Composition
The testing infrastructure follows a strict "composition over inheritance" rule. The primary test facade, TestsFlextTapOracleModels, composes functionalities from FlextTestsModels and the production FlextTapOracleModels.
Model Hierarchy
Test models are organized into specific namespaces to separate generic framework tests from Oracle-specific domain logic:
- Tests namespace: Generic models derived from the base
flext_testspackage. - TapOracle namespace: Domain-specific models for Oracle tap functionality, including connection mocks and extraction configurations.
The diagram shows the compositional relationship where the test facade hosts specific namespaces containing mock models.
Sources: tests/models.py:21-39
Mock Data Models
The system defines several Pydantic-based entities used to simulate the Oracle environment and Singer protocol behavior.
Core Test Entities
| Model | Description | Key Fields |
|---|---|---|
TestOracleConnection | Simulates database connection parameters and string generation. | host, port, service_name, username, password |
TestSingerStream | Mocks Singer stream metadata and selection state. | stream_name, table_name, replication_method, is_selected |
TestOracleTable | Represents source table metadata for discovery tests. | table_name, schema_name, column_count, row_count |
TestExtractionConfig | Defines parameters for data extraction performance testing. | batch_size, parallel_streams, timeout_seconds |
Sources: tests/models.py:43-107
Protocols and Interfaces
Mocking is enforced through runtime_checkable protocols, allowing test components to interact with mock objects as if they were real Oracle connections or data providers.
Mock Connection Protocol
The MockOracleConnection protocol defines the required interface for any mock database client used in the test suite.
The diagram illustrates the standard interaction flow between the test suite and a mock connection object.
Sources: tests/protocols.py:40-61
Mock Utilities and Fixtures
The project provides utility methods to programmatically generate mock data and configurations, ensuring consistency across test cases.
Data Generation Helpers
Utilities within TestsFlextTapOracleUtilities.TapOracle allow for the rapid creation of test artifacts:
create_test_oracle_config: Generates a dictionary of connection settings.generate_mock_oracle_data: Produces a sequence of dictionaries simulating database rows.create_test_singer_stream: Constructs a mock Singer stream configuration.
Sources: tests/utilities.py:34-88
Environment and State Management
Fixtures in tests/unit/fixtures.py manage the lifecycle of the mock environment, including resetting settings singletons and setting up environment variables.
@pytest.fixture(autouse=True)
def reset_tap_oracle_settings(reset_settings: None) -> Generator[None]:
"""Reset the concrete tap settings singletons around every test."""
FlextTapOracleSettings.reset_for_testing()
TestsFlextTapOracleSettings.reset_for_testing()
yield
FlextTapOracleSettings.reset_for_testing()
TestsFlextTapOracleSettings.reset_for_testing()
Sources: tests/unit/fixtures.py:90-106
Summary
Test Models Mocking in flext-tap-oracle leverages a sophisticated composition-based architecture to provide high-fidelity simulations of Oracle database operations. By combining Pydantic models for data structures with runtime_checkable protocols for behavior, the system ensures that the Singer Tap logic remains robust and verifiable independent of the physical database state.