Skip to content

Commit

Permalink
Add test to build_test
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Oct 8, 2021
1 parent d860237 commit bb89fc9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from {{ ref('model_b') }}
41 changes: 41 additions & 0 deletions test/integration/069_build_test/models-interdependent/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2

models:
- name: model_a
columns:
- name: id
tests:
- unique
- not_null
- relationships:
to: ref('model_b')
field: id
- relationships:
to: ref('model_c')
field: id

- name: model_b
columns:
- name: id
tests:
- unique
- not_null
- relationships:
to: ref('model_a')
field: id
- relationships:
to: ref('model_c')
field: id

- name: model_c
columns:
- name: id
tests:
- unique
- not_null
- relationships:
to: ref('model_a')
field: id
- relationships:
to: ref('model_b')
field: id
1 change: 1 addition & 0 deletions test/integration/069_build_test/test-files/model_b.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from {{ ref('model_a') }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select null from {{ ref('model_a') }}
41 changes: 40 additions & 1 deletion test/integration/069_build_test/test_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from test.integration.base import DBTIntegrationTest, use_profile
from test.integration.base import DBTIntegrationTest, use_profile, normalize
import yaml
import shutil
import os


class TestBuildBase(DBTIntegrationTest):
Expand Down Expand Up @@ -79,3 +81,40 @@ def test__postgres_circular_relationship_test_success(self):
actual = [r.status for r in results]
expected = ['success']*7 + ['pass']*2
self.assertEqual(sorted(actual), sorted(expected))

class TestInterdependentModels(TestBuildBase):

@property
def project_config(self):
return {
"config-version": 2,
"snapshot-paths": ["snapshots-none"],
"seeds": {
"quote_columns": False,
},
}

@property
def models(self):
return "models-interdependent"

def tearDown(self):
if os.path.exists(normalize('models-interdependent/model_b.sql')):
os.remove(normalize('models-interdependent/model_b.sql'))


@use_profile("postgres")
def test__postgres_interdependent_models(self):
# check that basic build works
shutil.copyfile('test-files/model_b.sql', 'models-interdependent/model_b.sql')
results = self.build()
self.assertEqual(len(results), 16)

# return null from model_b
shutil.copyfile('test-files/model_b_null.sql', 'models-interdependent/model_b.sql')
results = self.build(expect_pass=False)
self.assertEqual(len(results), 16)
actual = [str(r.status) for r in results]
expected = ['error']*4 + ['skipped']*7 + ['pass']*2 + ['success']*3
self.assertEqual(sorted(actual), sorted(expected))

0 comments on commit bb89fc9

Please sign in to comment.