|
| 1 | +import pytest |
| 2 | +from dbt.tests.adapter.basic.files import config_materialized_table, config_materialized_view |
| 3 | +from dbt.tests.util import run_dbt |
| 4 | + |
| 5 | +source_regular = """ |
| 6 | +version: 2 |
| 7 | +sources: |
| 8 | +- name: regular |
| 9 | + schema: INFORMATION_SCHEMA |
| 10 | + tables: |
| 11 | + - name: VIEWS |
| 12 | + columns: |
| 13 | + - name: TABLE_NAME |
| 14 | + tests: |
| 15 | + - not_null |
| 16 | +""" |
| 17 | + |
| 18 | +source_space_in_name = """ |
| 19 | +version: 2 |
| 20 | +sources: |
| 21 | +- name: 'space in name' |
| 22 | + schema: INFORMATION_SCHEMA |
| 23 | + tables: |
| 24 | + - name: VIEWS |
| 25 | + columns: |
| 26 | + - name: TABLE_NAME |
| 27 | + tests: |
| 28 | + - not_null |
| 29 | +""" |
| 30 | + |
| 31 | +select_from_source_regular = """ |
| 32 | +select * from {{ source("regular", "VIEWS") }} |
| 33 | +""" |
| 34 | + |
| 35 | +select_from_source_space_in_name = """ |
| 36 | +select * from {{ source("space in name", "VIEWS") }} |
| 37 | +""" |
| 38 | + |
| 39 | + |
| 40 | +class TestSourcesSQLServer: |
| 41 | + @pytest.fixture(scope="class") |
| 42 | + def models(self): |
| 43 | + return { |
| 44 | + "source_regular.yml": source_regular, |
| 45 | + "source_space_in_name.yml": source_space_in_name, |
| 46 | + "v_select_from_source_regular.sql": config_materialized_view |
| 47 | + + select_from_source_regular, |
| 48 | + "v_select_from_source_space_in_name.sql": config_materialized_view |
| 49 | + + select_from_source_space_in_name, |
| 50 | + "t_select_from_source_regular.sql": config_materialized_table |
| 51 | + + select_from_source_regular, |
| 52 | + "t_select_from_source_space_in_name.sql": config_materialized_table |
| 53 | + + select_from_source_space_in_name, |
| 54 | + } |
| 55 | + |
| 56 | + @pytest.fixture(scope="class") |
| 57 | + def project_config_update(self): |
| 58 | + return { |
| 59 | + "name": "test_sources", |
| 60 | + } |
| 61 | + |
| 62 | + def test_dbt_run(self, project): |
| 63 | + run_dbt(["compile"]) |
| 64 | + |
| 65 | + ls = run_dbt(["list"]) |
| 66 | + assert len(ls) == 8 |
| 67 | + ls_sources = [src for src in ls if src.startswith("source:")] |
| 68 | + assert len(ls_sources) == 2 |
| 69 | + |
| 70 | + run_dbt(["run"]) |
| 71 | + run_dbt(["test"]) |
0 commit comments