-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow use of sources as unit testing inputs (#9059)
- Loading branch information
Showing
7 changed files
with
196 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Features | ||
body: Support source inputs in unit tests | ||
time: 2023-11-11T19:11:50.870494-05:00 | ||
custom: | ||
Author: gshank | ||
Issue: "8507" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import pytest | ||
from dbt.tests.util import run_dbt | ||
|
||
raw_customers_csv = """id,first_name,last_name,email | ||
1,Michael,Perez,[email protected] | ||
2,Shawn,Mccoy,[email protected] | ||
3,Kathleen,Payne,[email protected] | ||
4,Jimmy,Cooper,[email protected] | ||
5,Katherine,Rice,[email protected] | ||
6,Sarah,Ryan,[email protected] | ||
7,Martin,Mcdonald,[email protected] | ||
8,Frank,Robinson,[email protected] | ||
9,Jennifer,Franklin,[email protected] | ||
10,Henry,Welch,[email protected] | ||
""" | ||
|
||
schema_sources_yml = """ | ||
sources: | ||
- name: seed_sources | ||
schema: "{{ target.schema }}" | ||
tables: | ||
- name: raw_customers | ||
columns: | ||
- name: id | ||
tests: | ||
- not_null: | ||
severity: "{{ 'error' if target.name == 'prod' else 'warn' }}" | ||
- unique | ||
- name: first_name | ||
- name: last_name | ||
- name: email | ||
unit_tests: | ||
- name: test_customers | ||
model: customers | ||
given: | ||
- input: source('seed_sources', 'raw_customers') | ||
rows: | ||
- {id: 1, first_name: Emily} | ||
expect: | ||
rows: | ||
- {id: 1, first_name: Emily} | ||
""" | ||
|
||
customers_sql = """ | ||
select * from {{ source('seed_sources', 'raw_customers') }} | ||
""" | ||
|
||
|
||
class TestUnitTestSourceInput: | ||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return { | ||
"raw_customers.csv": raw_customers_csv, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"customers.sql": customers_sql, | ||
"sources.yml": schema_sources_yml, | ||
} | ||
|
||
def test_source_input(self, project): | ||
results = run_dbt(["seed"]) | ||
results = run_dbt(["run"]) | ||
len(results) == 1 | ||
|
||
results = run_dbt(["unit-test"]) | ||
assert len(results) == 1 |