Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Conversion for Query Tag Tests #235

Merged
merged 8 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions tests/functional/query_tag/test_query_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import pytest
from dbt.tests.util import run_dbt
import os

snapshots__snapshot_query_tag_sql = """
{% snapshot snapshot_query_tag %}
{{
config(
target_database=database,
target_schema=schema,
unique_key='id',
strategy='check',
check_cols=['color'],
)
}}
select 1 as id, 'blue' as color
{% endsnapshot %}

"""

models__table_model_query_tag_sql = """
{{ config(materialized = 'table') }}

select 1 as id

"""

models__models_config_yml = """
version: 2

models:
- name: view_model_query_tag
columns:
- name: id
tests:
- unique

"""

models__view_model_query_tag_sql = """
{{ config(materialized = 'view') }}

select 1 as id

"""

models__incremental_model_query_tag_sql = """
{{ config(materialized = 'incremental', unique_key = 'id') }}

select 1 as id

"""

macros__check_tag_sql = """
{% macro check_query_tag() %}

{% if execute %}
{% set query_tag = get_current_query_tag() %}
{% if query_tag != var("query_tag") %}
{{ exceptions.raise_compiler_error("Query tag not used!") }}
{% endif %}
{% endif %}

{% endmacro %}

"""

seeds__seed_query_tag_csv = """id
1
"""

class TestQueryTag:
@pytest.fixture(scope="class")
def models(self):
return {
"table_model_query_tag.sql": models__table_model_query_tag_sql,
"view_model_query_tag.sql": models__view_model_query_tag_sql,
"incremental_model_query_tag.sql": models__incremental_model_query_tag_sql,
"models_config.yml": models__models_config_yml,
}

@pytest.fixture(scope="class")
def snapshots(self):
return {
"snapshot_query_tag.sql": snapshots__snapshot_query_tag_sql
}

@pytest.fixture(scope="class")
def macros(self):
return {
"check_tag.sql": macros__check_tag_sql
}

@pytest.fixture(scope="class")
def seeds(self):
return {
"seed_query_tag.csv": seeds__seed_query_tag_csv
}

@pytest.fixture(scope="class")
def project_config_update(self, prefix):
return {
'config-version': 2,
'models': {
'tests': {
'query_tag': prefix,
'post-hook': '{{ check_tag() }}'
},
},
'seeds': {
'tests': {
'query_tag': prefix,
'post-hook': '{{ check_tag() }}'
},
},
'snapshots': {
'tests': {
'query_tag': prefix,
'post-hook': '{{ check_tag() }}'
},
},
'tests': {
'test': {
'query_tag': prefix,
'post-hook': '{{ check_query_tag() }}'
}
},
}

def build_all_with_query_tags(self, project, prefix):
run_dbt(['build', '--vars', '{{"check_tag": "{}"}}'.format(prefix)])

def test_snowflake_query_tag(self, project, prefix):
self.build_all_with_query_tags(project, prefix)
self.build_all_with_query_tags(project, prefix)
10 changes: 0 additions & 10 deletions tests/integration/query_tag_tests/macros/check_tag.sql

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions tests/integration/query_tag_tests/models/models.yml

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions tests/integration/query_tag_tests/seeds/seed_query_tag.csv

This file was deleted.

This file was deleted.

52 changes: 0 additions & 52 deletions tests/integration/query_tag_tests/test_query_tags.py

This file was deleted.