mirror of
https://github.com/dbt-labs/dbt-core
synced 2025-12-20 16:11:27 +00:00
Compare commits
33 Commits
enable-pos
...
CT-355/mig
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbc5d701c7 | ||
|
|
0b6a15502f | ||
|
|
c6457ad635 | ||
|
|
e7619649d1 | ||
|
|
251e1f2b24 | ||
|
|
0b24e68ad5 | ||
|
|
415d86fc55 | ||
|
|
d319ab9313 | ||
|
|
ad8a5612fe | ||
|
|
bf6ad95181 | ||
|
|
43ae71c8ba | ||
|
|
2dd575f555 | ||
|
|
8ab2f9ea18 | ||
|
|
bd3ffe6bb9 | ||
|
|
3fe5977b44 | ||
|
|
1ad89aad64 | ||
|
|
627bf059c7 | ||
|
|
f10c11d71a | ||
|
|
bc25eda5f8 | ||
|
|
2b9da54e08 | ||
|
|
6af744eb55 | ||
|
|
eb70a94a61 | ||
|
|
711de420f4 | ||
|
|
52a18ffe38 | ||
|
|
9b80df5c3b | ||
|
|
d31d0d4112 | ||
|
|
a6b88d270e | ||
|
|
f1914cba93 | ||
|
|
a0d643246d | ||
|
|
f98774145a | ||
|
|
096da33da0 | ||
|
|
72d9c0a0f3 | ||
|
|
bbac6b3979 |
7
.changes/unreleased/Under the Hood-20220409-040539.yaml
Normal file
7
.changes/unreleased/Under the Hood-20220409-040539.yaml
Normal 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
@@ -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 %}
|
||||
@@ -1 +0,0 @@
|
||||
select * from {{ ref('seed_actual') }}
|
||||
@@ -1 +0,0 @@
|
||||
select * from {{ this.schema }}.seed_expected
|
||||
@@ -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
|
||||
@@ -1,3 +0,0 @@
|
||||
a,b,c
|
||||
1,7,23,90,5
|
||||
2
|
||||
|
@@ -1 +0,0 @@
|
||||
*.csv
|
||||
@@ -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,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,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,2 +0,0 @@
|
||||
id
|
||||
1
|
||||
|
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
seed_id
|
||||
1
|
||||
|
@@ -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,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,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'),
|
||||
@@ -1,2 +1,2 @@
|
||||
id
|
||||
seed_id
|
||||
Uh – Oh
|
||||
|
167
tests/adapter/dbt/tests/adapter/seed/fixtures.py
Normal file
167
tests/adapter/dbt/tests/adapter/seed/fixtures.py
Normal 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
|
||||
|
||||
"""
|
||||
311
tests/adapter/dbt/tests/adapter/seed/test_seed.py
Normal file
311
tests/adapter/dbt/tests/adapter/seed/test_seed.py
Normal 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user