Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for source overriding (#2264) #2291

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
- Fix skipped node count in stdout at the end of a run ([#2095](https:/fishtown-analytics/dbt/issues/2095), [#2310](https:/fishtown-analytics/dbt/pull/2310))
- Fix an issue where BigQuery incorrectly used a relation's quote policy as the basis for the information schema's include policy, instead of the relation's include policy. ([#2188](https:/fishtown-analytics/dbt/issues/2188), [#2325](https:/fishtown-analytics/dbt/pull/2325))

### Under the hood
- Added more tests for source inheritance ([#2264](https:/fishtown-analytics/dbt/issues/2264), [#2291](https:/fishtown-analytics/dbt/pull/2291))

Contributors:
- [@raalsky](https:/Raalsky) ([#2224](https:/fishtown-analytics/dbt/pull/2224), [#2228](https:/fishtown-analytics/dbt/pull/2228))
- [@ilkinulas](https:/ilkinulas) [#2199](https:/fishtown-analytics/dbt/pull/2199)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
sources:
- name: my_source
schema: invalid_schema
tables:
- name: my_table
sources:
- name: seed_source
schema: "{{ var('schema_override', target.schema) }}"
tables:
- name: "seed"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{# If our dependency source didn't exist, this would be an errror #}
select * from {{ source('seed_source', 'seed') }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
sources:
- name: my_source
schema: "{{ var('schema_override', target.schema) }}"
tables:
- name: my_table
identifier: seed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{# If our source override didn't take, this would be an errror #}
select * from {{ source('my_source', 'my_table') }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import json
import shutil
import yaml
from unittest import mock

import dbt.semver
Expand Down Expand Up @@ -56,14 +57,17 @@ def test_postgres_local_dependency(self):
self.run_dbt(['deps'])
self.run_dbt(['seed'])
results = self.run_dbt(['run'])
self.assertEqual(len(results), 3)
self.assertEqual(len(results), 5)
self.assertEqual({r.node.schema for r in results},
{self.base_schema(), self.configured_schema()})
self.assertEqual(
len([r.node for r in results
if r.node.schema == self.base_schema()]),
2
)

base_schema_nodes = [
r.node for r in results
if r.node.schema == self.base_schema()
]
self.assertEqual(len(base_schema_nodes), 4)
self.assertTablesEqual('source_override_model', 'seed', self.base_schema(), self.base_schema())
self.assertTablesEqual('dep_source_model', 'seed', self.base_schema(), self.base_schema())

@use_profile('postgres')
def test_postgres_no_dependency_paths(self):
Expand Down Expand Up @@ -106,13 +110,24 @@ def test_postgres_missing_dependency(self):


class TestSimpleDependencyWithSchema(TestSimpleDependency):
def run_dbt(self, cmd, *args, **kwargs):
# we can't add this to the config because Sources don't respect dbt_project.yml
vars_arg = yaml.safe_dump({
'schema_override': self.base_schema(),
})
cmd.extend(['--vars', vars_arg])
return super().run_dbt(cmd, *args, **kwargs)

@property
def project_config(self):
return {
'macro-paths': ['schema_override_macros'],
'models': {
'schema': 'dbt_test',
}
},
'seeds': {
'schema': 'dbt_test',
},
}

def base_schema(self):
Expand Down Expand Up @@ -142,7 +157,7 @@ def test_postgres_local_dependency_out_of_date_no_check(self, mock_get):
self.run_dbt(['deps'])
self.run_dbt(['seed', '--no-version-check'])
results = self.run_dbt(['run', '--no-version-check'])
self.assertEqual(len(results), 3)
self.assertEqual(len(results), 5)


class TestSimpleDependencyHooks(DBTIntegrationTest):
Expand Down