Extension Core Tests
Relevant source files
The following files were used as context for generating this wiki page:
The core tests for the superset-ext utility focus on validating the integration between Meltano's Extension Developer Kit (EDK) and the Apache Superset CLI. These tests ensure that configuration environments are correctly prepared, prefix-based environment variables are properly mapped to Superset's expected format, and the CLI entry points are correctly named and initialized.
The testing suite leverages pytest and unittest.mock to verify utility functions in superset_ext/utils.py and the main application logic in superset_ext/main.py. The primary goal is to guarantee that the extension can dynamically generate Superset configurations and manage the underlying database and application state through automated CLI invocations.
Sources: pyproject.toml:22-23, tests/test_superset_ext.py:1-5, tests/test_superset_ext_utils.py:1-12
Environment and Utility Testing
The utility tests verify the logic used to transform Meltano environment variables into a format compatible with Superset. This includes string manipulation for prefixes and complex dictionary mapping to establish the Superset instance's execution context.
Configuration Logic Verification
The test_superset_ext_utils.py file contains critical checks for environment variable isolation and transformation. It validates that the extension can strip prefixes and load specific subsets of the environment.
| Function | Test Case | Purpose |
|---|---|---|
trim_prefix | test_trim_prefix | Ensures foo_bar becomes bar when foo_ is provided as a prefix. |
load_config_from_env | test_load_config_from_env | Validates that only environment variables starting with a specific prefix are retrieved. |
prepared_env | test_parsed_env | Confirms that required Superset keys (e.g., SUPERSET_HOME, SQLALCHEMY_DATABASE_URI) are correctly derived. |
Sources: tests/test_superset_ext_utils.py:15-62, superset_ext/utils.py:12-45
Environment Preparation Flow
The following diagram illustrates how the prepared_env function processes system environment variables into a configuration dictionary used by the Superset invoker.
The flow ensures that variables like SUPERSET_CONFIG_PATH are extracted from the raw environment and normalized for the extension's internal use.
Sources: superset_ext/utils.py:48-93, tests/test_superset_ext_utils.py:32-62
Configuration Management Tests
Tests for write_config ensure that the extension can safely generate the superset_config.py file required by the underlying application.
File System Operations
The test_write_config test utilizes a tmp_path fixture to verify that:
- The configuration file is created at the specified path.
- The extension respects existing files unless the
forceflag is set toTrue. - The content is properly formatted as a Python script that injects uppercase dictionary keys into the module namespace.
Sources: tests/test_superset_ext_utils.py:65-73, superset_ext/utils.py:96-136
This sequence demonstrates the safety mechanism preventing accidental overwrites of existing Superset configurations.
Sources: superset_ext/utils.py:114-121, tests/test_superset_ext_utils.py:70-73
Application Entry Point Tests
Testing the main application entry point ensures that the Typer-based CLI is correctly configured.
App Initialization
The tests/test_superset_ext.py file performs a basic check on the app object defined in superset_ext/main.py. This confirms that the CLI application is correctly named "superset", which is critical for consistent command-line behavior when the extension is installed via Meltano.
Sources: tests/test_superset_ext.py:4-5, superset_ext/main.py:15-19
Command Structure
The extension exposes several commands which are implicitly tested through their presence in the Superset.describe() output and their definitions in the Typer app.
| Command | Description | Function Implementation |
|---|---|---|
initialize | Prepares DB and config | ext.initialize(force) |
create-admin | Interactive admin creation | ext.create_admin(...) |
invoke | Passthrough to Superset CLI | ext.pass_through_invoker(...) |
describe | Metadata about the extension | ext.describe_formatted(...) |
Sources: superset_ext/main.py:22-95, superset_ext/extension.py:133-157
Summary
The extension core tests validate the fundamental plumbing required to bridge Meltano's environment with the Apache Superset application. By focusing on environment variable transformation, idempotent configuration file generation, and CLI entry point naming, the test suite ensures that the superset-ext utility functions as a reliable wrapper for complex Superset operations like database migrations and user management.
Sources: tests/test_superset_ext_utils.py:1-73, tests/test_superset_ext.py:1-5