Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to see if pre_model_hook works for tests around snowflake_warehouse #1070

Merged
merged 13 commits into from
Jun 14, 2024
Merged
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# install latest changes in dbt-core
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
# install latest changes in dbt-core"
git+https://github.com/dbt-labs/dbt-core.git@mcknight/10198#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-adapters.git
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
git+https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-tests-adapter
git+https://github.com/dbt-labs/dbt-common.git
Expand Down
53 changes: 48 additions & 5 deletions tests/functional/warehouse_test/test_warehouses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,34 @@

import os


models__override_warehouse_sql = """
{{ config(snowflake_warehouse=env_var('SNOWFLAKE_TEST_ALT_WAREHOUSE', 'DBT_TEST_ALT'), materialized='table') }}
select current_warehouse() as warehouse
"""

models__expected_warehouse_sql = """
{{ config(materialized='table') }}
select '{{ env_var("SNOWFLAKE_TEST_ALT_WAREHOUSE", "DBT_TEST_ALT") }}' as warehouse
"""

models__invalid_warehouse_sql = """
{{ config(snowflake_warehouse='DBT_TEST_DOES_NOT_EXIST') }}
select current_warehouse() as warehouse
"""

project_config_models__override_warehouse_sql = """
{{ config(materialized='table') }}
select current_warehouse() as warehouse
"""

project_config_models__expected_warehouse_sql = """
{{ config(materialized='table') }}
select '{{ env_var("SNOWFLAKE_TEST_ALT_WAREHOUSE", "DBT_TEST_ALT") }}' as warehouse
"""

project_config_models__warehouse_sql = """
{{ config(materialized='table') }}
select current_warehouse() as warehouse
"""


Expand Down Expand Up @@ -90,3 +89,47 @@ def test_snowflake_override_ok(self, project):
]
)
check_relations_equal(project.adapter, ["OVERRIDE_WAREHOUSE", "EXPECTED_WAREHOUSE"])


class TestInvalidConfigWarehouse:
@pytest.fixture(scope="class")
def models(self):
return {
"invalid_warehouse.sql": project_config_models__warehouse_sql,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"config-version": 2,
"models": {
"test": {"snowflake_warehouse": "DBT_TEST_DOES_NOT_EXIST"},
},
}

def test_snowflake_override_invalid(self, project):
result = run_dbt(["run", "--models", "invalid_warehouse"], expect_pass=False)
assert "Object does not exist, or operation cannot be performed" in result[0].message


class TestValidConfigWarehouse:
@pytest.fixture(scope="class")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you just need to define this and the other model in outside of all classes once.

def models(self):
return {
"valid_warehouse.sql": project_config_models__warehouse_sql,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"config-version": 2,
"models": {
"test": {
"snowflake_warehouse": "DBT_TESTING",
},
},
}

def test_snowflake_warehouse_valid(self, project):
result = run_dbt(["run", "--models", "valid_warehouse"])
assert "DBT_TESTING" in result[0].node.config.get("snowflake_warehouse")
Loading