Compare commits

...

33 Commits

Author SHA1 Message Date
Mila Page
fbc5d701c7 Refactor to make dbt snowflake override in a test easier. 2022-04-14 03:30:52 -07:00
Mila Page
0b6a15502f Merge branch 'main' into CT-355/migrate_simple_seed 2022-04-14 01:00:31 -07:00
Mila Page
c6457ad635 Moving tests to adapter zone. 2022-04-14 00:59:41 -07:00
Mila Page
e7619649d1 Some cleanup. 2022-04-14 00:59:41 -07:00
Amy Byrum
251e1f2b24 Add updated dbt diagram for readme (#5055) 2022-04-14 00:59:41 -07:00
Michael Manganiello
0b24e68ad5 Flexibilize MarkupSafe pinned version (#5039)
* Flexibilize MarkupSafe pinned version

The current `MarkupSafe` pinned version has been added in #4746 as a
temporary fix for #4745.

However, the current restrictive approach isn't compatible with other
libraries that could require an even older version of `MarkupSafe`, like
Airflow `2.2.2` [0], which requires `markupsafe>=1.1.1, <2.0`.

To avoid that issue, we can allow a greater range of supported
`MarkupSafe` versions. Considering the direct dependency `dbt-core` has
is `Jinja2==2.11.3`, we can use its pinning as the lower bound, which is
`MarkupSafe>=0.23` [1].

This fix should be also backported this to `1.0.latest` for inclusion in
the next v1.0 patch.

[0] https://github.com/adamantike/airflow/blob/2.2.2/setup.cfg#L125
[1] https://github.com/pallets/jinja/blob/2.11.3/setup.py#L53
2022-04-14 00:59:41 -07:00
github-actions[bot]
415d86fc55 Bumping version to 1.2.0a1 (#5045)
* Bumping version to 1.2.0a1

* Fixing spacing issue

Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com>
Co-authored-by: leahwicz <60146280+leahwicz@users.noreply.github.com>
2022-04-14 00:59:41 -07:00
leahwicz
d319ab9313 Bumping manifest schema to v5 (#5032)
* Bumping manifest schema to v5

* Adding changelog
2022-04-14 00:59:41 -07:00
Nathaniel May
ad8a5612fe Perf regression testing - overhaul of readme and runner (#4602) 2022-04-14 00:59:41 -07:00
Stu Kilgore
bf6ad95181 Update version output and logic (#5029)
Update version output and logic
2022-04-14 00:59:41 -07:00
Benoit Perigaud
43ae71c8ba Add selected_resources to the Jinja context (#5001)
* Add selected_resources in the Jinja context

* Add tests for the Jinja variable selected_resources

* Add Changie entry for the addition of selected_resources

* Move variable to the ProviderContext

* Move selected_resources from ModelContext to ProviderContext

* Update unit tests for context to cater for the new selected_resources variable

* Move tests to a Class where tests are run after a dbt build
2022-04-14 00:59:41 -07:00
Jeremy Cohen
2dd575f555 Add experimental cache_selected_only config (#5036)
* cache schema for selected models

* Create Features-20220316-003847.yaml

* rename flag, update postgres adapter

rename flag to cache_selected_only, update postgres adapter: function _relations_cache_for_schemas

* Update Features-20220316-003847.yaml

* added test for cache_selected_only flag

* formatted as per pre-commit

* Add breaking change note for adapter plugin maintainers

* Fix whitespace

* Add a test

Co-authored-by: karunpoudel-chr <poudel.karun@gmail.com>
Co-authored-by: karunpoudel-chr <62040859+karunpoudel@users.noreply.github.com>
2022-04-14 00:59:41 -07:00
Emily Rockman
8ab2f9ea18 add more complete logic around changelog contributors section (#5037)
* add more complete logic around changelog contributors section

* add instructions for future core team members

* Update .changie.yaml
2022-04-14 00:59:41 -07:00
Emily Rockman
bd3ffe6bb9 Add enabled as a source config (#5008)
* initial pass at source config test w/o overrides

* Update tests/functional/sources/test_source_configs.py

Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>

* Update tests/functional/sources/test_source_configs.py

Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>

* tweaks from feedback

* clean up some test logic - add override tests

* add new fields to source config class

* fix odd formatting

* got a test working

* removed unused tests

* removed extra fields from SourceConfig class

* fixed next failing unit test

* adding back missing import

* first pass at adding source table configs

* updated remaining tests to pass

* remove source override tests

* add comment for config merging

* changelog

* remove old comments

* hacky fix for permission test

* remove unhelpful test

* adding back test file that was accidentally deleted

Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
Co-authored-by: Nathaniel May <nathaniel.may@fishtownanalytics.com>
Co-authored-by: Chenyu Li <chenyu.li@dbtlabs.com>
2022-04-14 00:59:40 -07:00
leahwicz
3fe5977b44 Updating tests and doc to support Python 3.10 (#5025)
* Updating tests and doc to support Python 3.10

* Single quotes needed for python version matrix

* Adding changelog
2022-04-14 00:59:40 -07:00
Sung Won Chung
1ad89aad64 Smart Source Freshness Runs (#4256)
* first draft

* working selector code

* remove debug print logs

* copy test template

* add todo

* smarter depends on graph searching notes

* add excluded source children nodes

* remove prints and clean up logger

* opinionated fresh node selection

* better if handling

* include logs with meaningul info

* add concurrent selectors note

* cleaner logging

* Revert "Merge branch 'main' of https://github.com/dbt-labs/dbt into feature/smart-source-freshness-runs"

This reverts commit 7fee4d44bf, reversing
changes made to 17c47ff42d.

* tidy up logs

* remove comments

* handle criterion that does not match nodes

* use a blank set instead

* Revert "Revert "Merge branch 'main' of https://github.com/dbt-labs/dbt into feature/smart-source-freshness-runs""

This reverts commit 71125167a1.

* make compatible with rc and new logger

* new log format

* new selector flag name

* clarify that status needs to be correct

* compare current and previous state

* correct import

* add current state

* remove print

* add todo

* fix error conditions

* clearer refresh language

* don't run wasteful logs

* remove for now

* cleaner syntax

* turn generator into set

* remove print

* add fresh selector

* data bookmarks matter only

* remove exclusion logic for status

* keep it DRY

* remove unused import

* dynamic project root

* dynamic cwd

* add TODO

* simple profiles_dir import

* add default target path

* headless path utils

* draft work

* add previous sources artifact read

* make PreviousState aware of t-2 sources

* make SourceFreshSelectorMethod aware of t-2 sources

* add archive_path() for t-2 sources to freshness.py

* clean up merged branches

* add to changelog

* rename file

* remove files

* remove archive path logic

* add in currentstate and previousstate defaults

* working version of source fresher

* syntax source_fresher: works

* fix quoting

* working version of target_path default

* None default to sources_current

* updated source selection semantics

* remove todo

* move to test_sources folder

* copy over baseline source freshness tests

* clean up

* remove test file

* update state with version checks

* fix flake tests

* add changelog

* fix name

* add base test template

* delegate tests

* add basic test to ensure nothing runs

* add another basic test

* fix test with copy state

* run error test

* run warn test

* run pass test

* error handling for runtime error in source freshness

* error handling for runtime error in source freshness

* add back fresher selector condition

* top level selector condition

* add runtime error test

* testing source fresher test selection methods

* fix formatting issues

* fix broken tests

* remove old comments

* fix regressions in other tests

* add Anais test cases

* result selector test case

Co-authored-by: Matt Winkler <matt.winkler@fishtownanalytics.com>
2022-04-14 00:59:40 -07:00
Emily Rockman
627bf059c7 cache after retrying instead of while retrying (#5028) 2022-04-14 00:59:40 -07:00
Leopoldo Araujo
f10c11d71a Added no-print flag (#4854)
* Added no-print flag

* Updated changelog

* Updated changelog

* Removed changes from CHANGELOG.md

* Updated CHANGELOG.MD with changie

* Update .changes/unreleased/Features-20220408-114118.yaml

Co-authored-by: Emily Rockman <ebuschang@gmail.com>

Co-authored-by: Emily Rockman <ebuschang@gmail.com>
2022-04-14 00:59:40 -07:00
Emily Rockman
bc25eda5f8 Update index file for docs generation (#4995)
* Update index file for docs generation

* add changelog entries
2022-04-14 00:59:40 -07:00
Stu Kilgore
2b9da54e08 Convert --version tests to pytest (#5026)
Convert --version tests to pytest
2022-04-14 00:59:40 -07:00
Gerda Shank
6af744eb55 Fix hard_delete_snapshot test to do the right thing. (#5020) 2022-04-14 00:59:40 -07:00
dependabot[bot]
eb70a94a61 Bump black from 22.1.0 to 22.3.0 (#4972)
* Bump black from 22.1.0 to 22.3.0
2022-04-14 00:59:40 -07:00
Ian Knox
711de420f4 updated docker readme CT-452 (#5018) 2022-04-14 00:59:40 -07:00
Ian Knox
52a18ffe38 Decouple project creation logic from tasks CT-299 (#4981) 2022-04-14 00:59:40 -07:00
Ian Knox
9b80df5c3b added git-blame-ignore-revs file (#5019) 2022-04-14 00:59:40 -07:00
Chenyu Li
d31d0d4112 make graph_selection tests just checking selection (#5012)
* make graph_selection tests just checking selection

* use util function
2022-04-14 00:59:40 -07:00
Chenyu Li
a6b88d270e adapter_methods (#4939)
* adapter_methods

* fix fixture scope

* update table compare method

* remove unneeded part

* update test name and comment
2022-04-14 00:59:40 -07:00
Ian Knox
f1914cba93 updated event message (#5011) 2022-04-14 00:59:40 -07:00
Mila Page
a0d643246d Fix BOM test for Windows and add changelog entry 2022-04-14 00:58:47 -07:00
Mila Page
f98774145a Complete migration of 005 and remove old files. 2022-04-09 04:00:26 -07:00
Mila Page
096da33da0 Revamp tests to use more of the framework. Fix TODOs 2022-04-09 03:33:04 -07:00
Mila Page
72d9c0a0f3 Get simple seed mostly working with design tweaks needed. 2022-04-08 04:46:39 -07:00
Mila Page
bbac6b3979 (finally) idiomatically rewrite a class of tests into the new framework. 2022-04-07 18:44:50 -07:00
23 changed files with 562 additions and 20561 deletions

View File

@@ -0,0 +1,7 @@
kind: Under the Hood
body: Migrating 005_simple_seed to the new test framework.
time: 2022-04-09T04:05:39.20045-07:00
custom:
Author: versusfacit
Issue: "200"
PR: "5013"

File diff suppressed because it is too large Load Diff

View File

@@ -1,22 +0,0 @@
{% test column_type(model, column_name, type) %}
{% set cols = adapter.get_columns_in_relation(model) %}
{% set col_types = {} %}
{% for col in cols %}
{% do col_types.update({col.name: col.data_type}) %}
{% endfor %}
{% set validation_message = 'Got a column type of ' ~ col_types.get(column_name) ~ ', expected ' ~ type %}
{% set val = 0 if col_types.get(column_name) == type else 1 %}
{% if val == 1 and execute %}
{{ log(validation_message, info=True) }}
{% endif %}
select '{{ validation_message }}' as validation_error
from (select true) as nothing
where {{ val }} = 1
{% endtest %}

View File

@@ -1 +0,0 @@
select * from {{ ref('seed_actual') }}

View File

@@ -1 +0,0 @@
select * from {{ this.schema }}.seed_expected

View File

@@ -1,47 +0,0 @@
version: 2
seeds:
- name: seed_enabled
columns:
- name: birthday
tests:
- column_type:
type: date
- name: id
tests:
- column_type:
type: text
- name: seed_tricky
columns:
- name: id
tests:
- column_type:
type: integer
- name: id_str
tests:
- column_type:
type: text
- name: a_bool
tests:
- column_type:
type: boolean
- name: looks_like_a_bool
tests:
- column_type:
type: text
- name: a_date
tests:
- column_type:
type: timestamp without time zone
- name: looks_like_a_date
tests:
- column_type:
type: text
- name: relative
tests:
- column_type:
type: text
- name: weekday
tests:
- column_type:
type: text

View File

@@ -1,3 +0,0 @@
a,b,c
1,7,23,90,5
2
1 a,b,c
2 1,7,23,90,5
3 2

View File

@@ -1 +0,0 @@
*.csv

View File

@@ -1,21 +0,0 @@
id,first_name,email,ip_address,birthday
1,Larry,lking0@miitbeian.gov.cn,69.135.206.194,2008-09-12 19:08:31
2,Larry,lperkins1@toplist.cz,64.210.133.162,1978-05-09 04:15:14
3,Anna,amontgomery2@miitbeian.gov.cn,168.104.64.114,2011-10-16 04:07:57
4,Sandra,sgeorge3@livejournal.com,229.235.252.98,1973-07-19 10:52:43
5,Fred,fwoods4@google.cn,78.229.170.124,2012-09-30 16:38:29
6,Stephen,shanson5@livejournal.com,182.227.157.105,1995-11-07 21:40:50
7,William,wmartinez6@upenn.edu,135.139.249.50,1982-09-05 03:11:59
8,Jessica,jlong7@hao123.com,203.62.178.210,1991-10-16 11:03:15
9,Douglas,dwhite8@tamu.edu,178.187.247.1,1979-10-01 09:49:48
10,Lisa,lcoleman9@nydailynews.com,168.234.128.249,2011-05-26 07:45:49
11,Ralph,rfieldsa@home.pl,55.152.163.149,1972-11-18 19:06:11
12,Louise,lnicholsb@samsung.com,141.116.153.154,2014-11-25 20:56:14
13,Clarence,cduncanc@sfgate.com,81.171.31.133,2011-11-17 07:02:36
14,Daniel,dfranklind@omniture.com,8.204.211.37,1980-09-13 00:09:04
15,Katherine,klanee@auda.org.au,176.96.134.59,1997-08-22 19:36:56
16,Billy,bwardf@wikia.com,214.108.78.85,2003-10-19 02:14:47
17,Annie,agarzag@ocn.ne.jp,190.108.42.70,1988-10-28 15:12:35
18,Shirley,scolemanh@fastcompany.com,109.251.164.84,1988-08-24 10:50:57
19,Roger,rfrazieri@scribd.com,38.145.218.108,1985-12-31 15:17:15
20,Lillian,lstanleyj@goodreads.com,47.57.236.17,1970-06-08 02:09:05
1 id first_name email ip_address birthday
2 1 Larry lking0@miitbeian.gov.cn 69.135.206.194 2008-09-12 19:08:31
3 2 Larry lperkins1@toplist.cz 64.210.133.162 1978-05-09 04:15:14
4 3 Anna amontgomery2@miitbeian.gov.cn 168.104.64.114 2011-10-16 04:07:57
5 4 Sandra sgeorge3@livejournal.com 229.235.252.98 1973-07-19 10:52:43
6 5 Fred fwoods4@google.cn 78.229.170.124 2012-09-30 16:38:29
7 6 Stephen shanson5@livejournal.com 182.227.157.105 1995-11-07 21:40:50
8 7 William wmartinez6@upenn.edu 135.139.249.50 1982-09-05 03:11:59
9 8 Jessica jlong7@hao123.com 203.62.178.210 1991-10-16 11:03:15
10 9 Douglas dwhite8@tamu.edu 178.187.247.1 1979-10-01 09:49:48
11 10 Lisa lcoleman9@nydailynews.com 168.234.128.249 2011-05-26 07:45:49
12 11 Ralph rfieldsa@home.pl 55.152.163.149 1972-11-18 19:06:11
13 12 Louise lnicholsb@samsung.com 141.116.153.154 2014-11-25 20:56:14
14 13 Clarence cduncanc@sfgate.com 81.171.31.133 2011-11-17 07:02:36
15 14 Daniel dfranklind@omniture.com 8.204.211.37 1980-09-13 00:09:04
16 15 Katherine klanee@auda.org.au 176.96.134.59 1997-08-22 19:36:56
17 16 Billy bwardf@wikia.com 214.108.78.85 2003-10-19 02:14:47
18 17 Annie agarzag@ocn.ne.jp 190.108.42.70 1988-10-28 15:12:35
19 18 Shirley scolemanh@fastcompany.com 109.251.164.84 1988-08-24 10:50:57
20 19 Roger rfrazieri@scribd.com 38.145.218.108 1985-12-31 15:17:15
21 20 Lillian lstanleyj@goodreads.com 47.57.236.17 1970-06-08 02:09:05

View File

@@ -1,21 +0,0 @@
id,first_name,email,ip_address,birthday
1,Larry,lking0@miitbeian.gov.cn,69.135.206.194,2008-09-12 19:08:31
2,Larry,lperkins1@toplist.cz,64.210.133.162,1978-05-09 04:15:14
3,Anna,amontgomery2@miitbeian.gov.cn,168.104.64.114,2011-10-16 04:07:57
4,Sandra,sgeorge3@livejournal.com,229.235.252.98,1973-07-19 10:52:43
5,Fred,fwoods4@google.cn,78.229.170.124,2012-09-30 16:38:29
6,Stephen,shanson5@livejournal.com,182.227.157.105,1995-11-07 21:40:50
7,William,wmartinez6@upenn.edu,135.139.249.50,1982-09-05 03:11:59
8,Jessica,jlong7@hao123.com,203.62.178.210,1991-10-16 11:03:15
9,Douglas,dwhite8@tamu.edu,178.187.247.1,1979-10-01 09:49:48
10,Lisa,lcoleman9@nydailynews.com,168.234.128.249,2011-05-26 07:45:49
11,Ralph,rfieldsa@home.pl,55.152.163.149,1972-11-18 19:06:11
12,Louise,lnicholsb@samsung.com,141.116.153.154,2014-11-25 20:56:14
13,Clarence,cduncanc@sfgate.com,81.171.31.133,2011-11-17 07:02:36
14,Daniel,dfranklind@omniture.com,8.204.211.37,1980-09-13 00:09:04
15,Katherine,klanee@auda.org.au,176.96.134.59,1997-08-22 19:36:56
16,Billy,bwardf@wikia.com,214.108.78.85,2003-10-19 02:14:47
17,Annie,agarzag@ocn.ne.jp,190.108.42.70,1988-10-28 15:12:35
18,Shirley,scolemanh@fastcompany.com,109.251.164.84,1988-08-24 10:50:57
19,Roger,rfrazieri@scribd.com,38.145.218.108,1985-12-31 15:17:15
20,Lillian,lstanleyj@goodreads.com,47.57.236.17,1970-06-08 02:09:05
1 id first_name email ip_address birthday
2 1 Larry lking0@miitbeian.gov.cn 69.135.206.194 2008-09-12 19:08:31
3 2 Larry lperkins1@toplist.cz 64.210.133.162 1978-05-09 04:15:14
4 3 Anna amontgomery2@miitbeian.gov.cn 168.104.64.114 2011-10-16 04:07:57
5 4 Sandra sgeorge3@livejournal.com 229.235.252.98 1973-07-19 10:52:43
6 5 Fred fwoods4@google.cn 78.229.170.124 2012-09-30 16:38:29
7 6 Stephen shanson5@livejournal.com 182.227.157.105 1995-11-07 21:40:50
8 7 William wmartinez6@upenn.edu 135.139.249.50 1982-09-05 03:11:59
9 8 Jessica jlong7@hao123.com 203.62.178.210 1991-10-16 11:03:15
10 9 Douglas dwhite8@tamu.edu 178.187.247.1 1979-10-01 09:49:48
11 10 Lisa lcoleman9@nydailynews.com 168.234.128.249 2011-05-26 07:45:49
12 11 Ralph rfieldsa@home.pl 55.152.163.149 1972-11-18 19:06:11
13 12 Louise lnicholsb@samsung.com 141.116.153.154 2014-11-25 20:56:14
14 13 Clarence cduncanc@sfgate.com 81.171.31.133 2011-11-17 07:02:36
15 14 Daniel dfranklind@omniture.com 8.204.211.37 1980-09-13 00:09:04
16 15 Katherine klanee@auda.org.au 176.96.134.59 1997-08-22 19:36:56
17 16 Billy bwardf@wikia.com 214.108.78.85 2003-10-19 02:14:47
18 17 Annie agarzag@ocn.ne.jp 190.108.42.70 1988-10-28 15:12:35
19 18 Shirley scolemanh@fastcompany.com 109.251.164.84 1988-08-24 10:50:57
20 19 Roger rfrazieri@scribd.com 38.145.218.108 1985-12-31 15:17:15
21 20 Lillian lstanleyj@goodreads.com 47.57.236.17 1970-06-08 02:09:05

View File

@@ -1,7 +0,0 @@
id,id_str,a_bool,looks_like_a_bool,a_date,looks_like_a_date,relative,weekday
1,1,true,true,2019-01-01 12:32:30,2019-01-01 12:32:30,tomorrow,Saturday
2,2,True,True,2019-01-01 12:32:31,2019-01-01 12:32:31,today,Sunday
3,3,TRUE,TRUE,2019-01-01 12:32:32,2019-01-01 12:32:32,yesterday,Monday
4,4,false,false,2019-01-01 01:32:32,2019-01-01 01:32:32,tomorrow,Saturday
5,5,False,False,2019-01-01 01:32:32,2019-01-01 01:32:32,today,Sunday
6,6,FALSE,FALSE,2019-01-01 01:32:32,2019-01-01 01:32:32,yesterday,Monday
1 id id_str a_bool looks_like_a_bool a_date looks_like_a_date relative weekday
2 1 1 true true 2019-01-01 12:32:30 2019-01-01 12:32:30 tomorrow Saturday
3 2 2 True True 2019-01-01 12:32:31 2019-01-01 12:32:31 today Sunday
4 3 3 TRUE TRUE 2019-01-01 12:32:32 2019-01-01 12:32:32 yesterday Monday
5 4 4 false false 2019-01-01 01:32:32 2019-01-01 01:32:32 tomorrow Saturday
6 5 5 False False 2019-01-01 01:32:32 2019-01-01 01:32:32 today Sunday
7 6 6 FALSE FALSE 2019-01-01 01:32:32 2019-01-01 01:32:32 yesterday Monday

View File

@@ -1,61 +0,0 @@
from test.integration.base import DBTIntegrationTest, use_profile
class TestSimpleSeedColumnOverride(DBTIntegrationTest):
@property
def schema(self):
return "simple_seed_005"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds-config'],
'macro-paths': ['macros'],
'seeds': {
'test': {
'enabled': False,
'quote_columns': True,
'seed_enabled': {
'enabled': True,
'+column_types': self.seed_enabled_types()
},
'seed_tricky': {
'enabled': True,
'+column_types': self.seed_tricky_types(),
},
},
},
}
class TestSimpleSeedColumnOverridePostgres(TestSimpleSeedColumnOverride):
@property
def models(self):
return "models-pg"
@property
def profile_config(self):
return self.postgres_profile()
def seed_enabled_types(self):
return {
"id": "text",
"birthday": "date",
}
def seed_tricky_types(self):
return {
'id_str': 'text',
'looks_like_a_bool': 'text',
'looks_like_a_date': 'text',
}
@use_profile('postgres')
def test_postgres_simple_seed_with_column_override_postgres(self):
results = self.run_dbt(["seed", "--show"])
self.assertEqual(len(results), 2)
results = self.run_dbt(["test"])
self.assertEqual(len(results), 10)

View File

@@ -1,349 +0,0 @@
import os
import csv
from test.integration.base import DBTIntegrationTest, use_profile
class TestSimpleSeed(DBTIntegrationTest):
def setUp(self):
DBTIntegrationTest.setUp(self)
self.run_sql_file("seed.sql")
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models-downstream-seed"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds'],
'seeds': {
'quote_columns': False,
}
}
def use_full_refresh_project(self, full_refresh: bool):
overrides = {
'seeds': {
'quote_columns': False,
'full_refresh': full_refresh,
}
}
self.use_default_project(overrides)
def _seed_and_run(self):
assert len(self.run_dbt(['seed'])) == 1
self.assertTablesEqual('seed_actual', 'seed_expected')
assert len(self.run_dbt(['run'])) == 1
self.assertTablesEqual('model', 'seed_expected')
def _after_seed_model_state(self, cmd, exists: bool):
assert len(self.run_dbt(cmd)) == 1
self.assertTablesEqual('seed_actual', 'seed_expected')
if exists:
self.assertTableDoesExist('model')
else:
self.assertTableDoesNotExist('model')
@use_profile('postgres')
def test_postgres_simple_seed(self):
self._seed_and_run()
# this should truncate the seed_actual table, then re-insert.
self._after_seed_model_state(['seed'], exists=True)
@use_profile('postgres')
def test_postgres_simple_seed_full_refresh_flag(self):
self._seed_and_run()
# this should drop the seed_actual table, then re-create it, so the
# model won't exist.
self._after_seed_model_state(['seed', '--full-refresh'], exists=False)
@use_profile('postgres')
def test_postgres_simple_seed_full_refresh_config(self):
self._seed_and_run()
# set the full_refresh config to False
self.use_full_refresh_project(False)
self._after_seed_model_state(['seed'], exists=True)
# make sure we ignore the full-refresh flag (the config is higher
# priority than the flag)
self._after_seed_model_state(['seed', '--full-refresh'], exists=True)
# this should drop the seed_actual table, then re-create it, so the
# model won't exist.
self.use_full_refresh_project(True)
self._after_seed_model_state(['seed'], exists=False)
class TestSimpleSeedCustomSchema(DBTIntegrationTest):
def setUp(self):
super().setUp()
self.run_sql_file("seed.sql")
self._created_schemas.add(
self._get_schema_fqn(self.default_database, self.custom_schema_name())
)
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds'],
'seeds': {
"schema": "custom_schema",
'quote_columns': False,
},
}
def custom_schema_name(self):
return "{}_{}".format(self.unique_schema(), 'custom_schema')
@use_profile('postgres')
def test_postgres_simple_seed_with_schema(self):
schema_name = self.custom_schema_name()
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
self.assertTablesEqual("seed_actual","seed_expected", table_a_schema=schema_name)
# this should truncate the seed_actual table, then re-insert
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
self.assertTablesEqual("seed_actual","seed_expected", table_a_schema=schema_name)
@use_profile('postgres')
def test_postgres_simple_seed_with_drop_and_schema(self):
schema_name = "{}_{}".format(self.unique_schema(), 'custom_schema')
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
self.assertTablesEqual("seed_actual","seed_expected", table_a_schema=schema_name)
# this should drop the seed table, then re-create
results = self.run_dbt(["seed", "--full-refresh"])
self.assertEqual(len(results), 1)
self.assertTablesEqual("seed_actual","seed_expected", table_a_schema=schema_name)
class TestSimpleSeedDisabled(DBTIntegrationTest):
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds-config'],
'seeds': {
"test": {
"seed_enabled": {
"enabled": True
},
"seed_disabled": {
"enabled": False
}
},
'quote_columns': False,
},
}
@use_profile('postgres')
def test_postgres_simple_seed_with_disabled(self):
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 2)
self.assertTableDoesExist('seed_enabled')
self.assertTableDoesNotExist('seed_disabled')
@use_profile('postgres')
def test_postgres_simple_seed_selection(self):
results = self.run_dbt(['seed', '--select', 'seed_enabled'])
self.assertEqual(len(results), 1)
self.assertTableDoesExist('seed_enabled')
self.assertTableDoesNotExist('seed_disabled')
self.assertTableDoesNotExist('seed_tricky')
@use_profile('postgres')
def test_postgres_simple_seed_exclude(self):
results = self.run_dbt(['seed', '--exclude', 'seed_enabled'])
self.assertEqual(len(results), 1)
self.assertTableDoesNotExist('seed_enabled')
self.assertTableDoesNotExist('seed_disabled')
self.assertTableDoesExist('seed_tricky')
class TestSeedParsing(DBTIntegrationTest):
def setUp(self):
super().setUp()
self.run_sql_file("seed.sql")
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models-exist"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds-bad'],
'seeds': {
'quote_columns': False,
},
}
@use_profile('postgres')
def test_postgres_dbt_run_skips_seeds(self):
# run does not try to parse the seed files
self.assertEqual(len(self.run_dbt(['run'])), 1)
# make sure 'dbt seed' fails, otherwise our test is invalid!
self.run_dbt(['seed'], expect_pass=False)
class TestSimpleSeedWithBOM(DBTIntegrationTest):
def setUp(self):
DBTIntegrationTest.setUp(self)
self.run_sql_file("seed.sql")
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds-bom'],
'seeds': {
'quote_columns': False,
},
}
@use_profile('postgres')
def test_postgres_simple_seed(self):
# first make sure nobody "fixed" the file by accident
seed_path = os.path.join(self.config.seed_paths[0], 'seed_bom.csv')
# 'data-bom/seed_bom.csv'
with open(seed_path, encoding='utf-8') as fp:
self.assertEqual(fp.read(1), u'\ufeff')
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
self.assertTablesEqual("seed_bom", "seed_expected")
class TestSimpleSeedWithUnicode(DBTIntegrationTest):
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds-unicode'],
'seeds': {
'quote_columns': False,
}
}
@use_profile('postgres')
def test_postgres_simple_seed(self):
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
class TestSimpleSeedWithDots(DBTIntegrationTest):
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds-dottedseed'],
'seeds': {
'quote_columns': False,
}
}
@use_profile('postgres')
def test_postgres_simple_seed(self):
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
class TestSimpleBigSeedBatched(DBTIntegrationTest):
@property
def schema(self):
return "simple_seed_005"
@property
def models(self):
return "models"
@property
def project_config(self):
return {
'config-version': 2,
'seed-paths': ['seeds-big'],
'seeds': {
'quote_columns': False,
}
}
def test_big_batched_seed(self):
with open('seeds-big/my_seed.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow(['id'])
for i in range(0, 20000):
writer.writerow([i])
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
@use_profile('postgres')
def test_postgres_big_batched_seed(self):
self.test_big_batched_seed()

View File

@@ -0,0 +1,2 @@
seed_id
1
1 seed_id
2 1

View File

@@ -1,4 +1,4 @@
id,first_name,email,ip_address,birthday
seed_id,first_name,email,ip_address,birthday
1,Larry,lking0@miitbeian.gov.cn,69.135.206.194,2008-09-12 19:08:31
2,Larry,lperkins1@toplist.cz,64.210.133.162,1978-05-09 04:15:14
3,Anna,amontgomery2@miitbeian.gov.cn,168.104.64.114,2011-10-16 04:07:57
1 id seed_id first_name email ip_address birthday
2 1 Larry lking0@miitbeian.gov.cn 69.135.206.194 2008-09-12 19:08:31
3 2 Larry lperkins1@toplist.cz 64.210.133.162 1978-05-09 04:15:14
4 3 Anna amontgomery2@miitbeian.gov.cn 168.104.64.114 2011-10-16 04:07:57

View File

@@ -1,4 +1,4 @@
id,first_name,email,ip_address,birthday
seed_id,first_name,email,ip_address,birthday
1,Larry,lking0@miitbeian.gov.cn,69.135.206.194,2008-09-12 19:08:31
2,Larry,lperkins1@toplist.cz,64.210.133.162,1978-05-09 04:15:14
3,Anna,amontgomery2@miitbeian.gov.cn,168.104.64.114,2011-10-16 04:07:57
1 id seed_id first_name email ip_address birthday
2 1 Larry lking0@miitbeian.gov.cn 69.135.206.194 2008-09-12 19:08:31
3 2 Larry lperkins1@toplist.cz 64.210.133.162 1978-05-09 04:15:14
4 3 Anna amontgomery2@miitbeian.gov.cn 168.104.64.114 2011-10-16 04:07:57

View File

@@ -1,5 +1,5 @@
create table {schema}.seed_expected (
id INTEGER,
seed_id INTEGER,
first_name TEXT,
email TEXT,
ip_address TEXT,
@@ -8,7 +8,7 @@ create table {schema}.seed_expected (
INSERT INTO {schema}.seed_expected
("id","first_name","email","ip_address","birthday")
("seed_id","first_name","email","ip_address","birthday")
VALUES
(1,'Larry','lking0@miitbeian.gov.cn','69.135.206.194','2008-09-12 19:08:31'),
(2,'Larry','lperkins1@toplist.cz','64.210.133.162','1978-05-09 04:15:14'),

View File

@@ -0,0 +1,167 @@
#
# Seeds
#
seeds__enabled_in_config = """seed_id,first_name,email,ip_address,birthday
1,Larry,lking0@miitbeian.gov.cn,69.135.206.194,2008-09-12 19:08:31
2,Larry,lperkins1@toplist.cz,64.210.133.162,1978-05-09 04:15:14
3,Anna,amontgomery2@miitbeian.gov.cn,168.104.64.114,2011-10-16 04:07:57
4,Sandra,sgeorge3@livejournal.com,229.235.252.98,1973-07-19 10:52:43
5,Fred,fwoods4@google.cn,78.229.170.124,2012-09-30 16:38:29
6,Stephen,shanson5@livejournal.com,182.227.157.105,1995-11-07 21:40:50
7,William,wmartinez6@upenn.edu,135.139.249.50,1982-09-05 03:11:59
8,Jessica,jlong7@hao123.com,203.62.178.210,1991-10-16 11:03:15
9,Douglas,dwhite8@tamu.edu,178.187.247.1,1979-10-01 09:49:48
10,Lisa,lcoleman9@nydailynews.com,168.234.128.249,2011-05-26 07:45:49
11,Ralph,rfieldsa@home.pl,55.152.163.149,1972-11-18 19:06:11
12,Louise,lnicholsb@samsung.com,141.116.153.154,2014-11-25 20:56:14
13,Clarence,cduncanc@sfgate.com,81.171.31.133,2011-11-17 07:02:36
14,Daniel,dfranklind@omniture.com,8.204.211.37,1980-09-13 00:09:04
15,Katherine,klanee@auda.org.au,176.96.134.59,1997-08-22 19:36:56
16,Billy,bwardf@wikia.com,214.108.78.85,2003-10-19 02:14:47
17,Annie,agarzag@ocn.ne.jp,190.108.42.70,1988-10-28 15:12:35
18,Shirley,scolemanh@fastcompany.com,109.251.164.84,1988-08-24 10:50:57
19,Roger,rfrazieri@scribd.com,38.145.218.108,1985-12-31 15:17:15
20,Lillian,lstanleyj@goodreads.com,47.57.236.17,1970-06-08 02:09:05
"""
seeds__disabled_in_config = """seed_id,first_name,email,ip_address,birthday
1,Larry,lking0@miitbeian.gov.cn,69.135.206.194,2008-09-12 19:08:31
2,Larry,lperkins1@toplist.cz,64.210.133.162,1978-05-09 04:15:14
3,Anna,amontgomery2@miitbeian.gov.cn,168.104.64.114,2011-10-16 04:07:57
4,Sandra,sgeorge3@livejournal.com,229.235.252.98,1973-07-19 10:52:43
5,Fred,fwoods4@google.cn,78.229.170.124,2012-09-30 16:38:29
6,Stephen,shanson5@livejournal.com,182.227.157.105,1995-11-07 21:40:50
7,William,wmartinez6@upenn.edu,135.139.249.50,1982-09-05 03:11:59
8,Jessica,jlong7@hao123.com,203.62.178.210,1991-10-16 11:03:15
9,Douglas,dwhite8@tamu.edu,178.187.247.1,1979-10-01 09:49:48
10,Lisa,lcoleman9@nydailynews.com,168.234.128.249,2011-05-26 07:45:49
11,Ralph,rfieldsa@home.pl,55.152.163.149,1972-11-18 19:06:11
12,Louise,lnicholsb@samsung.com,141.116.153.154,2014-11-25 20:56:14
13,Clarence,cduncanc@sfgate.com,81.171.31.133,2011-11-17 07:02:36
14,Daniel,dfranklind@omniture.com,8.204.211.37,1980-09-13 00:09:04
15,Katherine,klanee@auda.org.au,176.96.134.59,1997-08-22 19:36:56
16,Billy,bwardf@wikia.com,214.108.78.85,2003-10-19 02:14:47
17,Annie,agarzag@ocn.ne.jp,190.108.42.70,1988-10-28 15:12:35
18,Shirley,scolemanh@fastcompany.com,109.251.164.84,1988-08-24 10:50:57
19,Roger,rfrazieri@scribd.com,38.145.218.108,1985-12-31 15:17:15
20,Lillian,lstanleyj@goodreads.com,47.57.236.17,1970-06-08 02:09:05
"""
# used to tease out include/exclude edge case behavior for 'dbt seed'
seeds__tricky = """\
seed_id,seed_id_str,a_bool,looks_like_a_bool,a_date,looks_like_a_date,relative,weekday
1,1,true,true,2019-01-01 12:32:30,2019-01-01 12:32:30,tomorrow,Saturday
2,2,True,True,2019-01-01 12:32:31,2019-01-01 12:32:31,today,Sunday
3,3,TRUE,TRUE,2019-01-01 12:32:32,2019-01-01 12:32:32,yesterday,Monday
4,4,false,false,2019-01-01 01:32:32,2019-01-01 01:32:32,tomorrow,Saturday
5,5,False,False,2019-01-01 01:32:32,2019-01-01 01:32:32,today,Sunday
6,6,FALSE,FALSE,2019-01-01 01:32:32,2019-01-01 01:32:32,yesterday,Monday
"""
seeds__wont_parse = """a,b,c
1,7,23,90,5
2
"""
#
# Macros
#
macros__schema_test = """
{% test column_type(model, column_name, type) %}
{% set cols = adapter.get_columns_in_relation(model) %}
{% set col_types = {} %}
{% for col in cols %}
{% do col_types.update({col.name: col.data_type}) %}
{% endfor %}
{% set validation_message = 'Got a column type of ' ~ col_types.get(column_name) ~ ', expected ' ~ type %}
{% set val = 0 if col_types.get(column_name) == type else 1 %}
{% if val == 1 and execute %}
{{ log(validation_message, info=True) }}
{% endif %}
select '{{ validation_message }}' as validation_error
from (select true) as nothing
where {{ val }} = 1
{% endtest %}
"""
#
# Models
#
models__downstream_from_seed_actual = """
select * from {{ ref('seed_actual') }}
"""
models__from_basic_seed = """
select * from {{ this.schema }}.seed_expected
"""
#
# Properties
#
properties__schema_yml = """
version: 2
seeds:
- name: seed_enabled
columns:
- name: birthday
tests:
- column_type:
type: date
- name: seed_id
tests:
- column_type:
type: text
- name: seed_tricky
columns:
- name: seed_id
tests:
- column_type:
type: integer
- name: seed_id_str
tests:
- column_type:
type: text
- name: a_bool
tests:
- column_type:
type: boolean
- name: looks_like_a_bool
tests:
- column_type:
type: text
- name: a_date
tests:
- column_type:
type: timestamp without time zone
- name: looks_like_a_date
tests:
- column_type:
type: text
- name: relative
tests:
- column_type:
type: text
- name: weekday
tests:
- column_type:
type: text
"""

View File

@@ -0,0 +1,311 @@
import csv
import pytest
import shutil
from codecs import BOM_UTF8
from pathlib import Path
from dbt.tests.util import (
run_dbt,
read_file,
check_relations_equal,
check_table_does_exist,
check_table_does_not_exist,
)
from dbt.tests.adapter.seed.fixtures import (
models__downstream_from_seed_actual,
models__from_basic_seed,
seeds__disabled_in_config,
seeds__enabled_in_config,
seeds__tricky,
seeds__wont_parse,
)
# from `test/integration/test_simple_seed`, test_simple_seed
class SeedConfigBase(object):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {
"quote_columns": False,
},
}
class SeedTestBase(SeedConfigBase):
@pytest.fixture(scope="class", autouse=True)
def setUp(self, project):
"""Create table for ensuring seeds and models used in tests build correctly"""
project.run_sql_file(project.test_data_dir / Path("seed_expected.sql"))
@pytest.fixture(scope="class")
def seeds(self, test_data_dir):
seed_actual_csv = read_file(test_data_dir, "seed_actual.csv")
return {"seed_actual.csv": seed_actual_csv}
@pytest.fixture(scope="class")
def models(self):
return {
"models__downstream_from_seed_actual.sql": models__downstream_from_seed_actual,
}
def _build_relations_for_test(self, project):
"""The testing environment needs seeds and models to interact with"""
seed_result = run_dbt(["seed"])
assert len(seed_result) == 1
check_relations_equal(project.adapter, ["seed_expected", "seed_actual"])
run_result = run_dbt()
assert len(run_result) == 1
check_relations_equal(
project.adapter, ["models__downstream_from_seed_actual", "seed_expected"]
)
def _check_relation_end_state(self, run_result, project, exists: bool):
assert len(run_result) == 1
check_relations_equal(project.adapter, ["seed_actual", "seed_expected"])
if exists:
check_table_does_exist(project.adapter, "models__downstream_from_seed_actual")
else:
check_table_does_not_exist(project.adapter, "models__downstream_from_seed_actual")
class BasicSeedTests(SeedTestBase):
def test_simple_seed(self, project):
"""Build models and observe that run truncates a seed and re-inserts rows"""
self._build_relations_for_test(project)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True)
def test_simple_seed_full_refresh_flag(self, project):
"""Drop the seed_actual table and re-create. Verifies correct behavior by the absence of the
model which depends on seed_actual."""
self._build_relations_for_test(project)
self._check_relation_end_state(
run_result=run_dbt(["seed", "--full-refresh"]), project=project, exists=False
)
class SeedConfigFullRefreshOn(SeedTestBase):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {"quote_columns": False, "full_refresh": True},
}
def test_simple_seed_full_refresh_config(self, project):
"""config option should drop current model and cascade drop to downstream models"""
self._build_relations_for_test(project)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=False)
class SeedConfigFullRefreshOff(SeedTestBase):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {"quote_columns": False, "full_refresh": False},
}
def test_simple_seed_full_refresh_config(self, project):
"""Config options should override full-refresh flag because config is higher priority"""
self._build_relations_for_test(project)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True)
self._check_relation_end_state(
run_result=run_dbt(["seed", "--full-refresh"]), project=project, exists=True
)
class SeedCustomSchema(SeedTestBase):
@pytest.fixture(scope="class", autouse=True)
def setUp(self, project):
"""Create table for ensuring seeds and models used in tests build correctly"""
project.run_sql_file(project.test_data_dir / Path("seed_expected.sql"))
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {
"schema": "custom_schema",
"quote_columns": False,
},
}
def test_simple_seed_with_schema(self, project):
results = run_dbt(["seed"])
assert len(results) == 1
custom_schema = f"{project.test_schema}_custom_schema"
check_relations_equal(project.adapter, [f"{custom_schema}.seed_actual", "seed_expected"])
# this should truncate the seed_actual table, then re-insert
results = run_dbt(["seed"])
assert len(results) == 1
custom_schema = f"{project.test_schema}_custom_schema"
check_relations_equal(project.adapter, [f"{custom_schema}.seed_actual", "seed_expected"])
def test_simple_seed_with_drop_and_schema(self, project):
results = run_dbt(["seed"])
assert len(results) == 1
custom_schema = f"{project.test_schema}_custom_schema"
check_relations_equal(project.adapter, [f"{custom_schema}.seed_actual", "seed_expected"])
# this should drop the seed table, then re-create
results = run_dbt(["seed", "--full-refresh"])
custom_schema = f"{project.test_schema}_custom_schema"
check_relations_equal(project.adapter, [f"{custom_schema}.seed_actual", "seed_expected"])
class SimpleSeedEnabledViaConfig(object):
@pytest.fixture(scope="session")
def seeds(self):
return {
"seed_enabled.csv": seeds__enabled_in_config,
"seed_disabled.csv": seeds__disabled_in_config,
"seed_tricky.csv": seeds__tricky,
}
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {
"test": {"seed_enabled": {"enabled": True}, "seed_disabled": {"enabled": False}},
"quote_columns": False,
},
}
@pytest.fixture(scope="function")
def clear_test_schema(self, project):
yield
project.run_sql(f"drop schema if exists {project.test_schema} cascade")
def test_simple_seed_with_disabled(self, clear_test_schema, project):
results = run_dbt(["seed"])
len(results) == 2
check_table_does_exist(project.adapter, "seed_enabled")
check_table_does_not_exist(project.adapter, "seed_disabled")
check_table_does_exist(project.adapter, "seed_tricky")
def test_simple_seed_selection(self, clear_test_schema, project):
results = run_dbt(["seed", "--select", "seed_enabled"])
len(results) == 1
check_table_does_exist(project.adapter, "seed_enabled")
check_table_does_not_exist(project.adapter, "seed_disabled")
check_table_does_not_exist(project.adapter, "seed_tricky")
def test_simple_seed_exclude(self, clear_test_schema, project):
results = run_dbt(["seed", "--exclude", "seed_enabled"])
len(results) == 1
check_table_does_not_exist(project.adapter, "seed_enabled")
check_table_does_not_exist(project.adapter, "seed_disabled")
check_table_does_exist(project.adapter, "seed_tricky")
class SeedParsing(SeedConfigBase):
@pytest.fixture(scope="class", autouse=True)
def setUp(self, project):
"""Create table for ensuring seeds and models used in tests build correctly"""
project.run_sql_file(project.test_data_dir / Path("seed_expected.sql"))
@pytest.fixture(scope="class")
def seeds(self):
return {"seed.csv": seeds__wont_parse}
@pytest.fixture(scope="class")
def models(self):
return {"model.sql": models__from_basic_seed}
def test_dbt_run_skips_seeds(self, project):
# run does not try to parse the seed files
len(run_dbt()) == 1
# make sure 'dbt seed' fails, otherwise our test is invalid!
run_dbt(["seed"], expect_pass=False)
# BOM = byte order mark; see https://www.ibm.com/docs/en/netezza?topic=formats-byte-order-mark
class SimpleSeedWithBOM(SeedConfigBase):
@pytest.fixture(scope="class", autouse=True)
def setUp(self, project):
"""Create table for ensuring seeds and models used in tests build correctly"""
project.run_sql_file(project.test_data_dir / Path("seed_expected.sql"))
# manual copy because seed has a special and tricky-to-include unicode character at 0
shutil.copyfile(
project.test_data_dir / Path("seed_bom.csv"),
project.project_root / Path("seeds") / Path("seed_bom.csv"),
)
def test_simple_seed(self, project):
results = run_dbt(["seed"])
assert len(results) == 1
# encoding param must be specified in open, so long as Python reads files with a
# default file encoding for character sets beyond extended ASCII.
with open(
project.project_root / Path("seeds") / Path("seed_bom.csv"), encoding="utf-8"
) as fp:
assert fp.read(1) == BOM_UTF8.decode("utf-8")
check_relations_equal(project.adapter, ["seed_expected", "seed_bom"])
class SeedSpecificFormats(SeedConfigBase):
"""Expect all edge cases to build"""
def _make_big_seed(self, test_data_dir):
big_seed_path = test_data_dir / Path("tmp.csv")
with open(big_seed_path, "w") as f:
writer = csv.writer(f)
writer.writerow(["seed_id"])
for i in range(0, 20000):
writer.writerow([i])
return big_seed_path
@pytest.fixture(scope="class")
def seeds(self, test_data_dir):
seed_unicode = read_file(test_data_dir, "seed_unicode.csv")
dotted_seed = read_file(test_data_dir, "seed.with.dots.csv")
big_seed = read_file(self._make_big_seed(test_data_dir))
return {
"big_seed.csv": big_seed,
"seed.with.dots.csv": dotted_seed,
"seed_unicode.csv": seed_unicode,
}
def test_simple_seed(self, project):
results = run_dbt(["seed"])
len(results) == 3
class TestBasicSeedTests(BasicSeedTests):
pass
class TestSeedConfigFullRefreshOn(SeedConfigFullRefreshOn):
pass
class TestSeedConfigFullRefreshOff(SeedConfigFullRefreshOff):
pass
class TestSeedCustomSchema(SeedCustomSchema):
pass
class TestSimpleSeedEnabledViaConfig(SimpleSeedEnabledViaConfig):
pass
class TestSeedParsing(SeedParsing):
pass
class TestSimpleSeedWithBOM(SimpleSeedWithBOM):
pass
class TestSeedSpecificFormats(SeedSpecificFormats):
pass

View File

@@ -0,0 +1,70 @@
import pytest
from dbt.tests.util import run_dbt
from dbt.tests.adapter.seed.fixtures import (
macros__schema_test,
properties__schema_yml,
seeds__disabled_in_config,
seeds__enabled_in_config,
seeds__tricky,
)
class SimpleSeedColumnOverride(object):
@pytest.fixture(scope="class")
def models(self):
return {
"schema.yml": properties__schema_yml,
}
@pytest.fixture(scope="class")
def seeds(self):
return {
"seed_enabled.csv": seeds__enabled_in_config,
"seed_disabled.csv": seeds__disabled_in_config,
"seed_tricky.csv": seeds__tricky,
}
@pytest.fixture(scope="class")
def macros(self):
return {"schema_test.sql": macros__schema_test}
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {
"test": {
"enabled": False,
"quote_columns": True,
"seed_enabled": {"enabled": True, "+column_types": self.seed_enabled_types()},
"seed_tricky": {
"enabled": True,
"+column_types": self.seed_tricky_types(),
},
},
},
}
def seed_enabled_types(self):
return {
"seed_id": "text",
"birthday": "date",
}
def seed_tricky_types(self):
return {
"seed_id_str": "text",
"looks_like_a_bool": "text",
"looks_like_a_date": "text",
}
def test_simple_seed_with_column_override(self, project):
results = run_dbt(["seed", "--show"])
len(results) == 2
results = run_dbt(["test"])
len(results) == 10
class TestSimpleSeedColumnOverride(SimpleSeedColumnOverride):
pass

View File

@@ -1,19 +0,0 @@
import pytest
from dbt.tests.util import run_dbt
# from `test/integration/test_simple_seed`, test_postgres_simple_seed
@pytest.fixture(scope="class")
def project_config_update():
return {"seeds": {"quote_columns": False}}
@pytest.fixture(scope="class")
def seeds():
return {"data.csv": "a,b\n1,hello\n2,goodbye"}
def test_simple_seed(project):
results = run_dbt(["seed"])
assert len(results) == 1