Skip to content

Commit

Permalink
Add tests to see if pre_model_hook works for tests around snowflake_w…
Browse files Browse the repository at this point in the history
…arehouse (#1070)

* init attempt of adding logger.info for model_hooks

* modify logging to not post full config (unnessecary on every run)

* init form of test added

* change core pointer in dev-requirements

* removing logging as unneeded per feedback, and adding assert to new test

* add in passing test

* add in passing test

* consolidate sql fixtures

* revert core pointer

* remove unneeded quote
  • Loading branch information
McKnight-42 authored Jun 14, 2024
1 parent a4e22b0 commit a886ac1
Showing 1 changed file with 48 additions and 5 deletions.
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")
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")

0 comments on commit a886ac1

Please sign in to comment.