File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed
tests/functional/adapter/mssql Expand file tree Collapse file tree 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from dbt .tests .util import get_connection , run_dbt
3
+
4
+ model_sql = """
5
+ SELECT 1 AS data
6
+ """
7
+
8
+ table_mat = """
9
+ {{
10
+ config({
11
+ "materialized": 'table'
12
+ })
13
+ }}
14
+ SELECT 1 AS data
15
+ """
16
+
17
+ view_mat = """
18
+ {{
19
+ config({
20
+ "materialized": 'view'
21
+ })
22
+ }}
23
+ SELECT 1 AS data
24
+ """
25
+
26
+ schema = """
27
+ version: 2
28
+ models:
29
+ - name: mat_object
30
+ """
31
+
32
+
33
+ class BaseTableView :
34
+ def create_object (self , project , sql ):
35
+ with get_connection (project .adapter ):
36
+ project .adapter .execute (sql , fetch = True )
37
+
38
+
39
+ class TestTabletoView (BaseTableView ):
40
+ """Test if changing from a table object to a view object correctly replaces"""
41
+
42
+ @pytest .fixture (scope = "class" )
43
+ def models (self ):
44
+ return {"mat_object.sql" : view_mat , "schema.yml" : schema }
45
+
46
+ def test_passes (self , project ):
47
+ self .create_object (
48
+ project , f"SELECT * INTO { project .test_schema } .mat_object FROM ({ model_sql } ) t"
49
+ )
50
+ run_dbt (["run" ])
51
+
52
+
53
+ class TestViewtoTable (BaseTableView ):
54
+ """Test if changing from a view object to a table object correctly replaces"""
55
+
56
+ @pytest .fixture (scope = "class" )
57
+ def models (self ):
58
+ return {"mat_object.sql" : table_mat , "schema.yml" : schema }
59
+
60
+ def test_passes (self , project ):
61
+ self .create_object (project , f"CREATE VIEW { project .test_schema } .mat_object AS { model_sql } " )
62
+ run_dbt (["run" ])
You can’t perform that action at this time.
0 commit comments