|
| 1 | +import pytest |
| 2 | +from dbt.tests.util import run_dbt |
| 3 | + |
| 4 | +schema_yml = """ |
| 5 | +
|
| 6 | +version: 2 |
| 7 | +
|
| 8 | +models: |
| 9 | + - name: my_first_dbt_model |
| 10 | + description: "A starter dbt model" |
| 11 | + columns: |
| 12 | + - name: id |
| 13 | + description: "The primary key for this table" |
| 14 | + tests: |
| 15 | + - unique |
| 16 | + - not_null |
| 17 | +
|
| 18 | + - name: my_second_dbt_model |
| 19 | + description: "A starter dbt model" |
| 20 | + columns: |
| 21 | + - name: id |
| 22 | + description: "The primary key for this table" |
| 23 | + tests: |
| 24 | + - unique |
| 25 | + - not_null |
| 26 | +""" |
| 27 | + |
| 28 | +my_first_dbt_model_sql = """ |
| 29 | +/* |
| 30 | + Welcome to your first dbt model! |
| 31 | + Did you know that you can also configure models directly within SQL files? |
| 32 | + This will override configurations stated in dbt_project.yml |
| 33 | +
|
| 34 | + Try changing "table" to "view" below |
| 35 | +*/ |
| 36 | +
|
| 37 | +{{ config(materialized='table') }} |
| 38 | +
|
| 39 | +with source_data as ( |
| 40 | +
|
| 41 | + select 1 as id |
| 42 | + union all |
| 43 | + select null as id |
| 44 | +
|
| 45 | +) |
| 46 | +
|
| 47 | +select * |
| 48 | +from source_data |
| 49 | +
|
| 50 | +/* |
| 51 | + Uncomment the line below to remove records with null `id` values |
| 52 | +*/ |
| 53 | +
|
| 54 | +-- where id is not null |
| 55 | +""" |
| 56 | + |
| 57 | +my_second_dbt_model_sql = """ |
| 58 | +-- Use the `ref` function to select from other models |
| 59 | +
|
| 60 | +select * |
| 61 | +from {{ ref('my_first_dbt_model') }} |
| 62 | +where id = 1 |
| 63 | +""" |
| 64 | + |
| 65 | + |
| 66 | +class TestNewProjectSQLServer: |
| 67 | + @pytest.fixture(scope="class") |
| 68 | + def project_config_update(self): |
| 69 | + return {"name": "my_new_project"} |
| 70 | + |
| 71 | + @pytest.fixture(scope="class") |
| 72 | + def models(self): |
| 73 | + return { |
| 74 | + "my_first_dbt_model.sql": my_first_dbt_model_sql, |
| 75 | + "my_second_dbt_model.sql": my_second_dbt_model_sql, |
| 76 | + "schema.yml": schema_yml, |
| 77 | + } |
| 78 | + |
| 79 | + def test_new_project(self, project): |
| 80 | + results = run_dbt(["build"]) |
| 81 | + assert len(results) > 0 |
0 commit comments