Skip to content

Commit

Permalink
Add tests for tags in saved queries
Browse files Browse the repository at this point in the history
  • Loading branch information
theyostalservice committed Dec 16, 2024
1 parent 4343cfa commit 73d7648
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/functional/saved_queries/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,27 @@
export_as: table
schema: my_export_schema_name
"""

saved_query_with_tags_defined_yml = """
saved_queries:
- name: test_saved_query
description: "{{ doc('saved_query_description') }}"
label: Test Saved Query
tags:
- tag_a
- tag_c
query_params:
metrics:
- simple_metric
group_by:
- "Dimension('id__ds')"
where:
- "{{ TimeDimension('id__ds', 'DAY') }} <= now()"
- "{{ TimeDimension('id__ds', 'DAY') }} >= '2023-01-01'"
exports:
- name: my_export
config:
alias: my_export_alias
export_as: table
schema: my_export_schema_name
"""
34 changes: 34 additions & 0 deletions tests/functional/saved_queries/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
saved_query_with_cache_configs_defined_yml,
saved_query_with_export_configs_defined_at_saved_query_level_yml,
saved_query_with_extra_config_attributes_yml,
saved_query_with_tags_defined_yml,
saved_query_without_export_configs_defined_yml,
)
from tests.functional.semantic_models.fixtures import (
Expand Down Expand Up @@ -322,3 +323,36 @@ def test_override_saved_query_config(
result = runner.invoke(["parse"])
assert result.success
assert saved_query.config.cache.enabled is True


# the tags defined in project yaml for the SavedQuery is additive to the query's
class TestSavedQueryTagsAdditiveWithConfig(BaseConfigProject):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"saved-queries": {"+tags": ["tag_b", "tag_c"]},
}

@pytest.fixture(scope="class")
def models(self):
return {
"saved_queries.yml": saved_query_with_tags_defined_yml,
"schema.yml": schema_yml,
"fct_revenue.sql": fct_revenue_sql,
"metricflow_time_spine.sql": metricflow_time_spine_sql,
"docs.md": saved_query_description,
}

def test_saved_query_tags_are_additive_unique_and_sorted(
self,
project,
):
runner = dbtTestRunner()

# parse with default fixture project config
result = runner.invoke(["parse"])
assert result.success
assert isinstance(result.result, Manifest)
assert len(result.result.saved_queries) == 1
saved_query = result.result.saved_queries["saved_query.test.test_saved_query"]
assert saved_query.tags == ["tag_a", "tag_b", "tag_c"]

0 comments on commit 73d7648

Please sign in to comment.