Skip to content

Commit

Permalink
Refactor query tag tests (#57)
Browse files Browse the repository at this point in the history
* Refactor query tag tests

* Try this

* Try storing failures, too

* Keep trying

* Try it this way
  • Loading branch information
jtcohen6 authored Nov 23, 2021
1 parent 55f478b commit 5acc314
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 93 deletions.
10 changes: 10 additions & 0 deletions tests/integration/query_tag_tests/macros/check_tag.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% 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 %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ config(materialized = 'incremental', unique_key = 'id') }}

select 1 as id
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ config(materialized = 'table') }}

select 1 as id
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ config(materialized = 'view') }}

select 1 as id
2 changes: 2 additions & 0 deletions tests/integration/query_tag_tests/seeds/seed_query_tag.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id
1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
unique_key='id',
strategy='check',
check_cols=['color'],
query_tag=var('query_tag')
)
}}
select * from {{target.database}}.{{schema}}.seed
select 1 as id, 'blue' as color
{% endsnapshot %}
46 changes: 46 additions & 0 deletions tests/integration/query_tag_tests/test_query_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
import csv
from tests.integration.base import DBTIntegrationTest, use_profile

class TestSeedWithQueryTag(DBTIntegrationTest):
@property
def schema(self):
return "query_tag"

@property
def models(self):
return "models"

@property
def project_config(self):
return {
'config-version': 2,
'models': {
'test': {
'query_tag': self.prefix,
'post-hook': '{{ check_query_tag() }}'
},
},
'seeds': {
'test': {
'query_tag': self.prefix,
'post-hook': '{{ check_query_tag() }}'
},
},
'snapshots': {
'test': {
'query_tag': self.prefix,
'post-hook': '{{ check_query_tag() }}'
},
},
}

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

@use_profile('snowflake')
def test__snowflake__build_tagged_twice(self):
self.build_all_with_query_tags()
self.build_all_with_query_tags()


This file was deleted.

41 changes: 0 additions & 41 deletions tests/integration/simple_seed_test/test_seed_with_query_tag.py

This file was deleted.

34 changes: 0 additions & 34 deletions tests/integration/simple_snapshot_test/test_snapshot_query_tag.py

This file was deleted.

0 comments on commit 5acc314

Please sign in to comment.