|
| 1 | +import pytest |
| 2 | +from dbt.tests.adapter.simple_seed.seeds import seeds__expected_sql |
| 3 | +from dbt.tests.adapter.simple_seed.test_seed import TestBasicSeedTests as BaseBasicSeedTests |
| 4 | +from dbt.tests.adapter.simple_seed.test_seed import ( |
| 5 | + TestSeedConfigFullRefreshOff as BaseSeedConfigFullRefreshOff, |
| 6 | +) |
| 7 | +from dbt.tests.adapter.simple_seed.test_seed import ( |
| 8 | + TestSeedConfigFullRefreshOn as BaseSeedConfigFullRefreshOn, |
| 9 | +) |
| 10 | +from dbt.tests.adapter.simple_seed.test_seed import TestSeedCustomSchema as BaseSeedCustomSchema |
| 11 | +from dbt.tests.adapter.simple_seed.test_seed import TestSeedParsing as BaseSeedParsing |
| 12 | +from dbt.tests.adapter.simple_seed.test_seed import ( |
| 13 | + TestSeedSpecificFormats as BaseSeedSpecificFormats, |
| 14 | +) |
| 15 | +from dbt.tests.adapter.simple_seed.test_seed import ( |
| 16 | + TestSimpleSeedEnabledViaConfig as BaseSimpleSeedEnabledViaConfig, |
| 17 | +) |
| 18 | +from dbt.tests.adapter.simple_seed.test_seed_type_override import ( |
| 19 | + BaseSimpleSeedColumnOverride, |
| 20 | + seeds__disabled_in_config_csv, |
| 21 | + seeds__enabled_in_config_csv, |
| 22 | +) |
| 23 | +from dbt.tests.util import get_connection |
| 24 | + |
| 25 | +from dbt.adapters.sqlserver import SQLServerAdapter |
| 26 | + |
| 27 | +fixed_setup_sql = seeds__expected_sql.replace("TIMESTAMP WITHOUT TIME ZONE", "DATETIME").replace( |
| 28 | + "TEXT", "VARCHAR(255)" |
| 29 | +) |
| 30 | + |
| 31 | +seeds__tricky_csv = """ |
| 32 | +seed_id,seed_id_str,a_bool,looks_like_a_bool,a_date,looks_like_a_date,relative,weekday |
| 33 | +1,1,1,1,2019-01-01 12:32:30,2019-01-01 12:32:30,tomorrow,Saturday |
| 34 | +2,2,1,1,2019-01-01 12:32:31,2019-01-01 12:32:31,today,Sunday |
| 35 | +3,3,1,1,2019-01-01 12:32:32,2019-01-01 12:32:32,yesterday,Monday |
| 36 | +4,4,0,0,2019-01-01 01:32:32,2019-01-01 01:32:32,tomorrow,Saturday |
| 37 | +5,5,0,0,2019-01-01 01:32:32,2019-01-01 01:32:32,today,Sunday |
| 38 | +6,6,0,0,2019-01-01 01:32:32,2019-01-01 01:32:32,yesterday,Monday |
| 39 | +""".lstrip() |
| 40 | + |
| 41 | +macros__schema_test = """ |
| 42 | +{% test column_type(model, column_name, type) %} |
| 43 | +
|
| 44 | + {% set cols = adapter.get_columns_in_relation(model) %} |
| 45 | +
|
| 46 | + {% set col_types = {} %} |
| 47 | + {% for col in cols %} |
| 48 | + {% do col_types.update({col.name: col.data_type}) %} |
| 49 | + {% endfor %} |
| 50 | +
|
| 51 | + {% set col_type = col_types.get(column_name) %} |
| 52 | + {% set col_type = 'text' if col_type and 'character varying' in col_type else col_type %} |
| 53 | +
|
| 54 | + {% set validation_message = 'Got a column type of ' ~ col_type ~ ', expected ' ~ type %} |
| 55 | +
|
| 56 | + {% set val = 0 if col_type == type else 1 %} |
| 57 | + {% if val == 1 and execute %} |
| 58 | + {{ log(validation_message, info=True) }} |
| 59 | + {% endif %} |
| 60 | +
|
| 61 | + select '{{ validation_message }}' as validation_error |
| 62 | + from (select 1 as empty) as nothing |
| 63 | + where {{ val }} = 1 |
| 64 | +
|
| 65 | +{% endtest %} |
| 66 | +
|
| 67 | +""" |
| 68 | + |
| 69 | +properties__schema_yml = """ |
| 70 | +version: 2 |
| 71 | +seeds: |
| 72 | +- name: seed_enabled |
| 73 | + columns: |
| 74 | + - name: birthday |
| 75 | + tests: |
| 76 | + - column_type: |
| 77 | + type: date |
| 78 | + - name: seed_id |
| 79 | + tests: |
| 80 | + - column_type: |
| 81 | + type: text |
| 82 | +
|
| 83 | +- name: seed_tricky |
| 84 | + columns: |
| 85 | + - name: seed_id |
| 86 | + tests: |
| 87 | + - column_type: |
| 88 | + type: int |
| 89 | + - name: seed_id_str |
| 90 | + tests: |
| 91 | + - column_type: |
| 92 | + type: text |
| 93 | + - name: a_bool |
| 94 | + tests: |
| 95 | + - column_type: |
| 96 | + type: int |
| 97 | + - name: looks_like_a_bool |
| 98 | + tests: |
| 99 | + - column_type: |
| 100 | + type: text |
| 101 | + - name: a_date |
| 102 | + tests: |
| 103 | + - column_type: |
| 104 | + type: datetime |
| 105 | + - name: looks_like_a_date |
| 106 | + tests: |
| 107 | + - column_type: |
| 108 | + type: text |
| 109 | + - name: relative |
| 110 | + tests: |
| 111 | + - column_type: |
| 112 | + type: text |
| 113 | + - name: weekday |
| 114 | + tests: |
| 115 | + - column_type: |
| 116 | + type: text |
| 117 | +""" |
| 118 | + |
| 119 | + |
| 120 | +class TestSimpleSeedColumnOverrideSQLServer(BaseSimpleSeedColumnOverride): |
| 121 | + @pytest.fixture(scope="class") |
| 122 | + def seeds(self): |
| 123 | + return { |
| 124 | + "seed_enabled.csv": seeds__enabled_in_config_csv, |
| 125 | + "seed_disabled.csv": seeds__disabled_in_config_csv, |
| 126 | + "seed_tricky.csv": seeds__tricky_csv, |
| 127 | + } |
| 128 | + |
| 129 | + @pytest.fixture(scope="class") |
| 130 | + def macros(self): |
| 131 | + return {"schema_test.sql": macros__schema_test} |
| 132 | + |
| 133 | + @pytest.fixture(scope="class") |
| 134 | + def models(self): |
| 135 | + return { |
| 136 | + "schema.yml": properties__schema_yml, |
| 137 | + } |
| 138 | + |
| 139 | + |
| 140 | +class TestBasicSeedTestsSQLServer(BaseBasicSeedTests): |
| 141 | + @pytest.fixture(scope="class", autouse=True) |
| 142 | + def setUp(self, project): |
| 143 | + project.run_sql(fixed_setup_sql) |
| 144 | + |
| 145 | + |
| 146 | +class TestSeedConfigFullRefreshOnSQLServer(BaseSeedConfigFullRefreshOn): |
| 147 | + @pytest.fixture(scope="class", autouse=True) |
| 148 | + def setUp(self, project): |
| 149 | + project.run_sql(fixed_setup_sql) |
| 150 | + |
| 151 | + |
| 152 | +class TestSeedConfigFullRefreshOffSQLServer(BaseSeedConfigFullRefreshOff): |
| 153 | + @pytest.fixture(scope="class", autouse=True) |
| 154 | + def setUp(self, project): |
| 155 | + project.run_sql(fixed_setup_sql) |
| 156 | + |
| 157 | + |
| 158 | +class TestSeedCustomSchemaSQLServer(BaseSeedCustomSchema): |
| 159 | + @pytest.fixture(scope="class", autouse=True) |
| 160 | + def setUp(self, project): |
| 161 | + project.run_sql(fixed_setup_sql) |
| 162 | + |
| 163 | + |
| 164 | +class TestSimpleSeedEnabledViaConfigSQLServer(BaseSimpleSeedEnabledViaConfig): |
| 165 | + @pytest.fixture(scope="function") |
| 166 | + def clear_test_schema(self, project): |
| 167 | + yield |
| 168 | + adapter = project.adapter |
| 169 | + assert isinstance(project.adapter, SQLServerAdapter) |
| 170 | + with get_connection(project.adapter): |
| 171 | + rel = adapter.Relation.create(database=project.database, schema=project.test_schema) |
| 172 | + adapter.drop_schema(rel) |
| 173 | + |
| 174 | + |
| 175 | +class TestSeedParsingSQLServer(BaseSeedParsing): |
| 176 | + @pytest.fixture(scope="class", autouse=True) |
| 177 | + def setUp(self, project): |
| 178 | + project.run_sql(fixed_setup_sql) |
| 179 | + |
| 180 | + |
| 181 | +class TestSeedSpecificFormatsSQLServer(BaseSeedSpecificFormats): |
| 182 | + pass |
0 commit comments