-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BaseDocsGenerate and BaseDocsGenReferences Tests (#52)
### Summary Added these tests as part of the requirements for upgrading to dbt-core 1.2. ### Description #### BaseDocsGenerate - Modify second_model.sql to explicitly use alternate schema - Modify models fixture to use our version of second_model.sql - Modify verify_catalog from dbt-core to exclude source table verification - Modify unique_schema fixture to prepend schema with rav-test folder - Modify project_config_update fixture to prevent the seed being created as a view - Modify profiles fixture to make root_path the same as schema - Modify expected_catalog fixture to accommodate dremio data types - Include test_run_and_generate methods so they use our version of verify_catalog #### BaseDocsGenReferences - Modify project_config_update fixture to allow creating a view for seeds. This is because the ephemeral_summary models looks for the seed under database.schema (which is only used for views). - Modify unique_schema, profiles, and expected catalog fixtures for same reasons as above #### Utilities - Modify base_expected_catalog to look for datalake instead of database - Modify expected_references_catalog for the same reason above #### Other - Relevant imports - Remove staging snapshot macro ### Related Issue #43 #36 ### Additional Reviewers @jlarue26 @ArgusLi
- Loading branch information
1 parent
d8a3b7a
commit a373dd9
Showing
13 changed files
with
977 additions
and
613 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,87 @@ | ||
import pytest | ||
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod | ||
from dbt.tests.adapter.basic.test_adapter_methods import models__upstream_sql | ||
from tests.functional.adapter.utils.test_utils import DATALAKE | ||
|
||
models__my_model_sql = """ | ||
{% set upstream = ref('upstream_view') %} | ||
{% if execute %} | ||
{# don't ever do any of this #} | ||
{%- do adapter.drop_schema(upstream) -%} | ||
{% set existing = adapter.get_relation(upstream.database, upstream.schema, upstream.identifier) %} | ||
{% if existing is not defined %} | ||
{% do exceptions.raise_compiler_error('expected ' ~ ' to not exist, but it did') %} | ||
{% endif %} | ||
{%- do adapter.create_schema(upstream) -%} | ||
{% set sql = create_view_as(upstream, 'select 2 as id') %} | ||
{% do run_query(sql) %} | ||
{% endif %} | ||
select * from {{ upstream }} | ||
""" | ||
|
||
models__expected_sql = """ | ||
-- make sure this runs after 'model' | ||
-- {{ ref('model_view') }} | ||
select 2 as id | ||
""" | ||
|
||
|
||
class TestBaseAdapterMethodDremio(BaseAdapterMethod): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"models": { | ||
"+twin_strategy": "clone", | ||
}, | ||
"name": "adapter_methods", | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"upstream_view.sql": models__upstream_sql, | ||
"expected_view.sql": models__expected_sql, | ||
"model_view.sql": models__my_model_sql, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def unique_schema(self, request, prefix) -> str: | ||
test_file = request.module.__name__ | ||
# We only want the last part of the name | ||
test_file = test_file.split(".")[-1] | ||
unique_schema = f"{DATALAKE}.{prefix}_{test_file}" | ||
return unique_schema | ||
|
||
@pytest.fixture(scope="class") | ||
def dbt_profile_data( | ||
self, unique_schema, dbt_profile_target, profiles_config_update | ||
): | ||
profile = { | ||
"config": {"send_anonymous_usage_stats": False}, | ||
"test": { | ||
"outputs": { | ||
"default": {}, | ||
}, | ||
"target": "default", | ||
}, | ||
} | ||
target = dbt_profile_target | ||
target["schema"] = unique_schema | ||
target["root_path"] = unique_schema | ||
profile["test"]["outputs"]["default"] = target | ||
|
||
if profiles_config_update: | ||
profile.update(profiles_config_update) | ||
return profile | ||
|
||
@pytest.fixture(scope="class") | ||
def equal_tables(self): | ||
return ["model_view", "expected_view"] |
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,165 @@ | ||
import pytest | ||
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations | ||
from tests.functional.adapter.utils.test_utils import ( | ||
relation_from_name, | ||
check_relations_equal, | ||
check_relation_types, | ||
) | ||
from dbt.tests.adapter.basic.files import ( | ||
base_view_sql, | ||
base_table_sql, | ||
base_materialized_var_sql, | ||
) | ||
from dbt.tests.util import ( | ||
run_dbt, | ||
check_result_nodes_by_name, | ||
) | ||
from tests.functional.adapter.utils.test_utils import DATALAKE | ||
|
||
# Unable to insert variable into docstring, so "rav-test" is hardcoded | ||
schema_base_yml = """ | ||
version: 2 | ||
sources: | ||
- name: raw | ||
database: "rav-test" | ||
schema: "{{ target.schema }}" | ||
tables: | ||
- name: seed | ||
identifier: "{{ var('seed_name', 'base') }}" | ||
""" | ||
|
||
|
||
class TestSimpleMaterializationsDremio(BaseSimpleMaterializations): | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"view_model.sql": base_view_sql, | ||
"table_model.sql": base_table_sql, | ||
"swappable.sql": base_materialized_var_sql, | ||
"schema.yml": schema_base_yml, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"models": { | ||
"+twin_strategy": "prevent", | ||
}, | ||
"seeds": {"+twin_strategy": "allow"}, | ||
"name": "base", | ||
"vars": {"dremio:reflections": "false"}, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def unique_schema(self, request, prefix) -> str: | ||
test_file = request.module.__name__ | ||
# We only want the last part of the name | ||
test_file = test_file.split(".")[-1] | ||
unique_schema = f"{DATALAKE}.{prefix}_{test_file}" | ||
return unique_schema | ||
|
||
@pytest.fixture(scope="class") | ||
def dbt_profile_data( | ||
self, unique_schema, dbt_profile_target, profiles_config_update | ||
): | ||
profile = { | ||
"config": {"send_anonymous_usage_stats": False}, | ||
"test": { | ||
"outputs": { | ||
"default": {}, | ||
}, | ||
"target": "default", | ||
}, | ||
} | ||
target = dbt_profile_target | ||
target["schema"] = unique_schema | ||
target["root_path"] = unique_schema | ||
profile["test"]["outputs"]["default"] = target | ||
|
||
if profiles_config_update: | ||
profile.update(profiles_config_update) | ||
return profile | ||
|
||
def test_base(self, project): | ||
|
||
# seed command | ||
results = run_dbt(["seed"]) | ||
# seed result length | ||
assert len(results) == 1 | ||
|
||
# run command | ||
results = run_dbt() | ||
# run result length | ||
assert len(results) == 3 | ||
|
||
# names exist in result nodes | ||
check_result_nodes_by_name(results, ["view_model", "table_model", "swappable"]) | ||
|
||
# check relation types | ||
expected = { | ||
"base": "table", | ||
"view_model": "view", | ||
"table_model": "table", | ||
"swappable": "table", | ||
} | ||
check_relation_types(project.adapter, expected) | ||
|
||
# base table rowcount | ||
relation = relation_from_name(project.adapter, "base") | ||
result = project.run_sql( | ||
f"select count(*) as num_rows from {relation}", fetch="one" | ||
) | ||
assert result[0] == 10 | ||
|
||
# relations_equal | ||
check_relations_equal( | ||
project.adapter, ["base", "view_model", "table_model", "swappable"] | ||
) | ||
|
||
# check relations in catalog | ||
catalog = run_dbt(["docs", "generate"]) | ||
assert len(catalog.nodes) == 4 | ||
assert len(catalog.sources) == 1 | ||
|
||
# run_dbt changing materialized_var to view | ||
# required for BigQuery | ||
if project.test_config.get("require_full_refresh", False): | ||
results = run_dbt( | ||
[ | ||
"run", | ||
"--full-refresh", | ||
"-m", | ||
"swappable", | ||
"--vars", | ||
"materialized_var: view", | ||
] | ||
) | ||
else: | ||
results = run_dbt( | ||
["run", "-m", "swappable", "--vars", "materialized_var: view"] | ||
) | ||
assert len(results) == 1 | ||
# check relation types, swappable is view | ||
expected = { | ||
"base": "table", | ||
"view_model": "view", | ||
"table_model": "table", | ||
"swappable": "view", | ||
} | ||
|
||
check_relation_types(project.adapter, expected) | ||
|
||
# run_dbt changing materialized_var to incremental | ||
results = run_dbt( | ||
["run", "-m", "swappable", "--vars", "materialized_var: incremental"] | ||
) | ||
assert len(results) == 1 | ||
|
||
# check relation types, swappable is table | ||
expected = { | ||
"base": "table", | ||
"view_model": "view", | ||
"table_model": "table", | ||
"swappable": "table", | ||
} | ||
check_relation_types(project.adapter, expected) |
Oops, something went wrong.