Configuration Validation Tests
Relevant source files
The following files were used as context for generating this wiki page:
Configuration Validation Tests in the flext-dbt-oracle project ensure that the settings governing the dbt adapter for Oracle remain robust, consistent, and type-safe. These tests verify the lifecycle of the FlextDbtOracleSettings object, covering its construction, the application of default values, and strict validation of connection and performance parameters.
The test suite is structured as a composition of specialized "parts"—construction, validation, and connection mapping—which are aggregated into a primary configuration test class. This modular approach allows for targeted verification of Pydantic-based settings, ensuring that invalid inputs (such as mismatched pool sizes or unsupported materialization types) are caught early with appropriate error messages.
Sources: tests/unit/test_config.py:1-20, tests/unit/_config_parts/validation.py:1-15
Test Architecture and Composition
The configuration tests follow a mixin-based architecture where individual concerns are separated into discrete classes. These classes are then inherited by the main TestsFlextDbtOracleConfig class to provide comprehensive coverage.
The architecture ensures that the singleton settings state is reset before each test execution via FlextDbtOracleSettings.reset_for_testing() to prevent cross-test pollution.
Sources: tests/unit/test_config.py:12-20, tests/unit/_config_parts/init.py:1-30
Settings Construction and Defaults
Construction tests verify that the FlextDbtOracleSettings class can be instantiated with both minimal and exhaustive parameter sets. A key focus is the project's adherence to "validation by construction," where default values are automatically populated from internal constants if not explicitly provided.
Key Construction Behaviors
- Automatic Defaults: If
oracle_service_nameorsidare missing, the system applies default constants to ensure a valid connection object. - Optional Field Support: Verification that extended parameters like
nls_lang,ssl_server_dn_match, andsearch_pathare correctly mapped from input to the settings object. - Constant Integrity: Tests ensure that numeric defaults (port, timeouts, pool sizes) are within logical ranges (e.g., port > 0).
Sources: tests/unit/_config_parts/construction.py:12-88, src/flext_dbt_oracle/settings.py:16-90
Validation Logic and Constraint Enforcement
The validation suite uses Pydantic's validation engine to enforce business rules and technical constraints on the configuration data. This includes type checking, range validation, and cross-field consistency checks.
Validation Rules Summary
| Constraint Area | Logic Applied | Expected Outcome on Failure |
|---|---|---|
| Pool Sizes | pool_max_size must be greater than or equal to pool_min_size. | ValidationError: "Pool max size must be >= pool min size" |
| Materialization | Must be one of: table, view, incremental, snapshot. | ValidationError: "Input should be..." |
| Protocol | Must be either tcp or tcps. | ValidationError: "Input should be..." |
| Port | Must be a valid positive integer. | ValidationError |
The validate_pool_sizes method specifically implements a model_validator(mode="after") to ensure the integrity of the connection pool's upper and lower bounds.
Sources: tests/unit/_config_parts/validation.py:48-63, src/flext_dbt_oracle/settings.py:108-114
Connection String and Config Mapping
These tests verify how the internal settings state is projected into external formats, such as SQLAlchemy-style connection strings or configuration dictionaries for the Oracle database driver.
Connection Logic Flow
The diagram below illustrates how raw settings fields are transformed into a usable connection string based on the presence of a SID or Service Name.
Data Transformation Methods
to_connection_config(): Generates a flat dictionary containing core credentials and network parameters.to_oracle_config(): Converts the settings into a specializedOracleConnectionConfigmodel used by the underlyingflext-db-oraclelibrary.performance_settings: A computed property that aggregates pool sizes, timeouts, and fetch sizes into a mapping for performance tuning.
Sources: tests/unit/_config_parts/connection.py:15-117, src/flext_dbt_oracle/settings.py:128-183
Summary of Configuration Validation
Configuration Validation Tests ensure the flext-dbt-oracle adapter operates on a "Single Source of Truth" (SSOT) provided by the FlextDbtOracleSettings class. By validating construction, enforcing strict field constraints, and verifying complex transformation logic (like connection string generation), the test suite guarantees that the runtime environment is always configured with valid, predictable parameters. This prevents runtime failures related to malformed connection strings or invalid performance tuning.
Sources: tests/unit/test_config.py:18-20, src/flext_dbt_oracle/settings.py:15-18