-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests & make final edits to functional tests
- Loading branch information
1 parent
087d7da
commit 17b4821
Showing
2 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
from dbt.adapters.snowflake.relation import SnowflakeRelation | ||
|
||
|
||
@pytest.fixture | ||
def iceberg_config() -> dict: | ||
"""Fixture providing standard Iceberg configuration.""" | ||
return { | ||
"schema": "my_schema", | ||
"identifier": "my_table", | ||
"external_volume": "s3_iceberg_snow", | ||
"base_location_root": "root_path", | ||
"base_location_subpath": "subpath", | ||
} | ||
|
||
|
||
def get_actual_base_location(config: dict[str, str]) -> str: | ||
"""Get the actual base location from the configuration by parsing the DDL predicates.""" | ||
|
||
relation = SnowflakeRelation.create( | ||
schema=config["schema"], | ||
identifier=config["identifier"], | ||
) | ||
|
||
actual_ddl_predicates = relation.get_iceberg_ddl_options(config).strip() | ||
actual_base_location = actual_ddl_predicates.split("base_location = ")[1] | ||
|
||
return actual_base_location | ||
|
||
|
||
def test_iceberg_path_and_subpath(iceberg_config: dict[str, str]): | ||
"""Test when base_location_root and base_location_subpath are provided""" | ||
expected_base_location = ( | ||
f"'{iceberg_config['base_location_root']}/" | ||
f"{iceberg_config['schema']}/" | ||
f"{iceberg_config['identifier']}/" | ||
f"{iceberg_config['base_location_subpath']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location | ||
|
||
|
||
def test_iceberg_only_subpath(iceberg_config: dict[str, str]): | ||
"""Test when only base_location_subpath is provided""" | ||
del iceberg_config["base_location_root"] | ||
|
||
expected_base_location = ( | ||
f"'_dbt/" | ||
f"{iceberg_config['schema']}/" | ||
f"{iceberg_config['identifier']}/" | ||
f"{iceberg_config['base_location_subpath']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location | ||
|
||
|
||
def test_iceberg_only_path(iceberg_config: dict[str, str]): | ||
"""Test when only base_location_root is provided""" | ||
del iceberg_config["base_location_subpath"] | ||
|
||
expected_base_location = ( | ||
f"'{iceberg_config['base_location_root']}/" | ||
f"{iceberg_config['schema']}/" | ||
f"{iceberg_config['identifier']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location | ||
|
||
|
||
def test_iceberg_no_path(iceberg_config: dict[str, str]): | ||
"""Test when no base_location_root or is base_location_subpath provided""" | ||
del iceberg_config["base_location_root"] | ||
del iceberg_config["base_location_subpath"] | ||
|
||
expected_base_location = ( | ||
f"'_dbt/" | ||
f"{iceberg_config['schema']}/" | ||
f"{iceberg_config['identifier']}'" | ||
).strip() | ||
|
||
assert get_actual_base_location(iceberg_config) == expected_base_location |