Skip to content

Commit bb37ae0

Browse files
authored
Merge pull request #380 from dbt-msft/repro-new-project
repro new project
2 parents e7a900a + 4e0238d commit bb37ae0

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import pytest
2+
from dbt.tests.util import run_dbt
3+
4+
schema_yml = """
5+
6+
version: 2
7+
8+
models:
9+
- name: my_first_dbt_model
10+
description: "A starter dbt model"
11+
columns:
12+
- name: id
13+
description: "The primary key for this table"
14+
tests:
15+
- unique
16+
17+
- name: my_second_dbt_model
18+
description: "A starter dbt model"
19+
columns:
20+
- name: id
21+
description: "The primary key for this table"
22+
tests:
23+
- unique
24+
- not_null
25+
"""
26+
27+
my_first_dbt_model_sql = """
28+
/*
29+
Welcome to your first dbt model!
30+
Did you know that you can also configure models directly within SQL files?
31+
This will override configurations stated in dbt_project.yml
32+
33+
Try changing "table" to "view" below
34+
*/
35+
36+
{{ config(materialized='table') }}
37+
38+
with source_data as (
39+
40+
select 1 as id
41+
union all
42+
select null as id
43+
44+
)
45+
46+
select *
47+
from source_data
48+
49+
/*
50+
Uncomment the line below to remove records with null `id` values
51+
*/
52+
53+
-- where id is not null
54+
"""
55+
56+
my_second_dbt_model_sql = """
57+
-- Use the `ref` function to select from other models
58+
59+
select *
60+
from {{ ref('my_first_dbt_model') }}
61+
where id = 1
62+
"""
63+
64+
65+
class TestNewProjectSQLServer:
66+
@pytest.fixture(scope="class")
67+
def project_config_update(self):
68+
return {"name": "my_new_project"}
69+
70+
@pytest.fixture(scope="class")
71+
def models(self):
72+
return {
73+
"my_first_dbt_model.sql": my_first_dbt_model_sql,
74+
"my_second_dbt_model.sql": my_second_dbt_model_sql,
75+
"schema.yml": schema_yml,
76+
}
77+
78+
def test_new_project(self, project):
79+
results = run_dbt(["build"])
80+
assert len(results) == 5
81+
82+
def test_run_same_model_multiple_times(self, project):
83+
results = run_dbt(["run"])
84+
assert len(results) == 2
85+
86+
for i in range(10):
87+
run_dbt(["run", "-s", "my_second_dbt_model"])
88+
assert len(results) == 2

0 commit comments

Comments
 (0)