-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #521 from cody-scott/test-materialization-changes
added test to validate swapping from table to view and view to table
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pytest | ||
from dbt.tests.util import get_connection, run_dbt | ||
|
||
model_sql = """ | ||
SELECT 1 AS data | ||
""" | ||
|
||
table_mat = """ | ||
{{ | ||
config({ | ||
"materialized": 'table' | ||
}) | ||
}} | ||
SELECT 1 AS data | ||
""" | ||
|
||
view_mat = """ | ||
{{ | ||
config({ | ||
"materialized": 'view' | ||
}) | ||
}} | ||
SELECT 1 AS data | ||
""" | ||
|
||
schema = """ | ||
version: 2 | ||
models: | ||
- name: mat_object | ||
""" | ||
|
||
|
||
class BaseTableView: | ||
def create_object(self, project, sql): | ||
with get_connection(project.adapter): | ||
project.adapter.execute(sql, fetch=True) | ||
|
||
|
||
class TestTabletoView(BaseTableView): | ||
"""Test if changing from a table object to a view object correctly replaces""" | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"mat_object.sql": view_mat, "schema.yml": schema} | ||
|
||
def test_passes(self, project): | ||
self.create_object( | ||
project, f"SELECT * INTO {project.test_schema}.mat_object FROM ({model_sql}) t" | ||
) | ||
run_dbt(["run"]) | ||
|
||
|
||
class TestViewtoTable(BaseTableView): | ||
"""Test if changing from a view object to a table object correctly replaces""" | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return {"mat_object.sql": table_mat, "schema.yml": schema} | ||
|
||
def test_passes(self, project): | ||
self.create_object(project, f"CREATE VIEW {project.test_schema}.mat_object AS {model_sql}") | ||
run_dbt(["run"]) |