From 25a7d22d16377a115b062cb0cd6354fceb48472e Mon Sep 17 00:00:00 2001 From: matt-winkler <75497565+matt-winkler@users.noreply.github.com> Date: Mon, 22 Aug 2022 12:11:14 -0500 Subject: [PATCH] Feature/support query tags in tests (#210) * initial test materialization with query tagging * set adapter to snowflake * move over core materialization code for testing * add query tagging macros * revise with jtcohen's version * add validation on query tags for tests * add changelog entry * update changelog again * fix linting issue & update changelog with PR * update changelog using changie --- .changes/unreleased/Features-20220815-233505.yaml | 7 +++++++ dbt/include/snowflake/macros/materializations/test.sql | 8 ++++++++ tests/integration/query_tag_tests/models/models.yml | 8 ++++++++ tests/integration/query_tag_tests/test_query_tags.py | 6 ++++++ 4 files changed, 29 insertions(+) create mode 100644 .changes/unreleased/Features-20220815-233505.yaml create mode 100644 dbt/include/snowflake/macros/materializations/test.sql create mode 100644 tests/integration/query_tag_tests/models/models.yml diff --git a/.changes/unreleased/Features-20220815-233505.yaml b/.changes/unreleased/Features-20220815-233505.yaml new file mode 100644 index 000000000..cc29f7444 --- /dev/null +++ b/.changes/unreleased/Features-20220815-233505.yaml @@ -0,0 +1,7 @@ +kind: Features +body: Support query tags in dbt tests using the `+query_tag` config in `dbt_project.yml` +time: 2022-08-15T23:35:05.967484-06:00 +custom: + Author: matt-winkler + Issue: "211" + PR: "210" diff --git a/dbt/include/snowflake/macros/materializations/test.sql b/dbt/include/snowflake/macros/materializations/test.sql new file mode 100644 index 000000000..816a74893 --- /dev/null +++ b/dbt/include/snowflake/macros/materializations/test.sql @@ -0,0 +1,8 @@ +{%- materialization test, adapter='snowflake' -%} + + {% set original_query_tag = set_query_tag() %} + {% set relations = materialization_test_default() %} + {% do unset_query_tag(original_query_tag) %} + {{ return(relations) }} + +{%- endmaterialization -%} diff --git a/tests/integration/query_tag_tests/models/models.yml b/tests/integration/query_tag_tests/models/models.yml new file mode 100644 index 000000000..49ab57765 --- /dev/null +++ b/tests/integration/query_tag_tests/models/models.yml @@ -0,0 +1,8 @@ +version: 2 + +models: + - name: view_model_query_tag + columns: + - name: id + tests: + - unique \ No newline at end of file diff --git a/tests/integration/query_tag_tests/test_query_tags.py b/tests/integration/query_tag_tests/test_query_tags.py index 24cc7c52a..f81d64a89 100644 --- a/tests/integration/query_tag_tests/test_query_tags.py +++ b/tests/integration/query_tag_tests/test_query_tags.py @@ -33,6 +33,12 @@ def project_config(self): 'post-hook': '{{ check_query_tag() }}' }, }, + 'tests': { + 'test': { + 'query_tag': self.prefix, + 'post-hook': '{{ check_query_tag() }}' + } + }, } def build_all_with_query_tags(self):