Skip to content

Commit

Permalink
Merge pull request #521 from cody-scott/test-materialization-changes
Browse files Browse the repository at this point in the history
added test to validate swapping from table to view and view to table
  • Loading branch information
cody-scott authored Sep 3, 2024
2 parents 2c127f8 + 60b275b commit 7c85157
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/functional/adapter/mssql/test_materialize_change.py
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"])

0 comments on commit 7c85157

Please sign in to comment.