-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for generic tests config (#1172)
* add test cases for generic tests config * update tests --------- Co-authored-by: Colin Rogers <[email protected]> Co-authored-by: Colin <[email protected]>
- Loading branch information
1 parent
ad4ccad
commit 1d29992
Showing
5 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,90 @@ | ||
SCHEMA__CONTROL = """ | ||
version: 2 | ||
models: | ||
- name: colors | ||
columns: | ||
- name: color | ||
data_tests: | ||
- not_null | ||
""" | ||
|
||
|
||
SCHEMA__EXPLICIT_WAREHOUSE = """ | ||
version: 2 | ||
models: | ||
- name: colors | ||
columns: | ||
- name: color | ||
data_tests: | ||
- not_null: | ||
config: | ||
snowflake_warehouse: DBT_TESTING_ALT | ||
""" | ||
|
||
|
||
SCHEMA__NOT_NULL = """ | ||
version: 2 | ||
models: | ||
- name: facts | ||
columns: | ||
- name: value | ||
data_tests: | ||
- not_null: | ||
config: | ||
snowflake_warehouse: DBT_TESTING_ALT | ||
""" | ||
|
||
|
||
SCHEMA__RELATIONSHIPS = """ | ||
version: 2 | ||
models: | ||
- name: facts | ||
columns: | ||
- name: color | ||
data_tests: | ||
- relationships: | ||
to: ref('my_colors') | ||
field: color | ||
config: | ||
snowflake_warehouse: DBT_TESTING_ALT | ||
""" | ||
|
||
|
||
SCHEMA__ACCEPTED_VALUES = """ | ||
version: 2 | ||
models: | ||
- name: colors | ||
columns: | ||
- name: color | ||
data_tests: | ||
- accepted_values: | ||
values: ['blue', 'red', 'green'] | ||
config: | ||
snowflake_warehouse: DBT_TESTING_ALT | ||
""" | ||
|
||
|
||
SEED__COLORS = """ | ||
color | ||
blue | ||
green | ||
red | ||
yellow | ||
""".strip() | ||
|
||
|
||
# record 10 is missing a value | ||
# record 7 has a color that's not on COLORS | ||
SEED__FACTS = """ | ||
id,color,value | ||
1,blue,10 | ||
2,red,20 | ||
3,green,30 | ||
4,yellow,40 | ||
5,blue,50 | ||
6,red,60 | ||
7,orange,70 | ||
8,green,80 | ||
9,yellow,90 | ||
10,blue, | ||
""".strip() |
Empty file.
Empty file.
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,54 @@ | ||
import pytest | ||
|
||
from dbt.tests.util import run_dbt, run_dbt_and_capture | ||
|
||
from tests.functional.generic_test_tests import _files | ||
|
||
|
||
class TestWarehouseConfig: | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return { | ||
"colors.csv": _files.SEED__COLORS, | ||
"facts.csv": _files.SEED__FACTS, | ||
} | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def setup(self, project): | ||
run_dbt(["seed"]) | ||
run_dbt(["run"]) | ||
yield | ||
|
||
|
||
class TestWarehouseConfigControl(TestWarehouseConfig): | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"schema.yml": _files.SCHEMA__CONTROL} | ||
|
||
def test_expected_warehouse(self, project): | ||
results, logs = run_dbt_and_capture(["test"]) | ||
assert len(results) == 1 | ||
|
||
|
||
class TestWarehouseConfigExplicitWarehouse(TestWarehouseConfig): | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"schema.yml": _files.SCHEMA__EXPLICIT_WAREHOUSE} | ||
|
||
def test_expected_warehouse(self, project): | ||
_, logs = run_dbt_and_capture(["test", "--log-level", "debug"]) | ||
assert "use warehouse " in logs | ||
|
||
|
||
class TestWarehouseConfigNotNull(TestWarehouseConfig): | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"schema.yml": _files.SCHEMA__NOT_NULL} | ||
|
||
def test_expected_warehouse(self, project): | ||
_, logs = run_dbt_and_capture(["test", "--log-level", "debug"], expect_pass=False) | ||
assert "use warehouse " in logs |