Skip to content

Commit

Permalink
Add results tests for exposures and saved queries
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Dec 3, 2024
1 parent 38358b1 commit d3eda93
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
36 changes: 32 additions & 4 deletions tests/functional/exposures/test_exposures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from dbt.artifacts.schemas.results import RunStatus
from dbt.contracts.graph.nodes import Exposure
from dbt.tests.util import get_manifest, run_dbt
from tests.functional.exposures.fixtures import (
metricflow_time_spine_sql,
Expand All @@ -25,8 +27,8 @@ def models(self):
"metrics.yml": metrics_schema_yml,
}

def test_names_with_spaces(self, project):
run_dbt(["run"])
def test_compilation_names_with_spaces(self, project):
run_dbt(["compile"])
manifest = get_manifest(project.project_root)
exposure_ids = list(manifest.exposures.keys())
expected_exposure_ids = [
Expand All @@ -36,8 +38,8 @@ def test_names_with_spaces(self, project):
assert exposure_ids == expected_exposure_ids
assert manifest.exposures["exposure.test.simple_exposure"].label == "simple exposure label"

def test_depends_on(self, project):
run_dbt(["run"])
def test_compilation_depends_on(self, project):
run_dbt(["compile"])
manifest = get_manifest(project.project_root)
exposure_depends_on = manifest.exposures["exposure.test.simple_exposure"].depends_on.nodes
expected_exposure_depends_on = [
Expand All @@ -46,3 +48,29 @@ def test_depends_on(self, project):
"metric.test.metric",
]
assert sorted(exposure_depends_on) == sorted(expected_exposure_depends_on)

def test_execution_default(self, project):
results = run_dbt(["build"])
exposure_results = (
result for result in results.results if isinstance(result.node, Exposure)
)
assert {result.node.name for result in exposure_results} == {
"simple_exposure",
"notebook_exposure",
}
assert all(result.status == RunStatus.NoOp for result in exposure_results)
assert all("NO-OP" in result.message for result in exposure_results)

def test_execution_exclude(self, project):
results = run_dbt(["build", "--exclude", "simple_exposure"])
exposure_results = (
result for result in results.results if isinstance(result.node, Exposure)
)
assert {result.node.name for result in exposure_results} == {"notebook_exposure"}

def test_execution_select(self, project):
results = run_dbt(["build", "--select", "simple_exposure"])
exposure_results = (
result for result in results.results if isinstance(result.node, Exposure)
)
assert {result.node.name for result in exposure_results} == {"simple_exposure"}
10 changes: 9 additions & 1 deletion tests/functional/saved_queries/test_saved_query_build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from dbt.artifacts.schemas.results import RunStatus
from dbt.contracts.graph.nodes import SavedQuery
from dbt.tests.util import run_dbt
from tests.functional.saved_queries.fixtures import (
saved_queries_yml,
Expand Down Expand Up @@ -36,4 +38,10 @@ def test_build_saved_queries_no_op(self, project) -> None:
run_dbt(["deps"])
result = run_dbt(["build"])
assert len(result.results) == 3
assert "NO-OP" in [r.message for r in result.results]

saved_query_results = (
result for result in result.results if isinstance(result.node, SavedQuery)
)
assert {result.node.name for result in saved_query_results} == {"test_saved_query"}
assert all("NO-OP" in result.message for result in saved_query_results)
assert all(result.status == RunStatus.NoOp for result in saved_query_results)

0 comments on commit d3eda93

Please sign in to comment.