Skip to content

Commit d398b9f

Browse files
authored
Merge pull request #365 from dbt-msft/fix-docs-tests-azure
ignore owner when testing docs in azure
2 parents a09ca8b + facff2c commit d398b9f

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def dbt_profile_target(request: FixtureRequest):
3434
raise ValueError(f"Unknown profile: {profile}")
3535

3636

37+
@pytest.fixture(scope="class")
38+
def is_azure(request: FixtureRequest) -> bool:
39+
profile = request.config.getoption("--profile")
40+
return "azure" in profile
41+
42+
3743
def _all_profiles_base():
3844
return {
3945
"type": "sqlserver",

tests/functional/adapter/test_docs.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24
from dbt.tests.adapter.basic.expected_catalog import (
35
base_expected_catalog,
@@ -7,13 +9,44 @@
79
from dbt.tests.adapter.basic.test_docs_generate import (
810
BaseDocsGenerate,
911
BaseDocsGenReferences,
12+
get_artifact,
1013
ref_models__docs_md,
1114
ref_models__ephemeral_copy_sql,
1215
ref_models__schema_yml,
1316
ref_sources__schema_yml,
17+
run_and_generate,
18+
verify_metadata,
1419
)
1520

1621

22+
def verify_catalog(project, expected_catalog, start_time, ignore_owner):
23+
# get the catalog.json
24+
catalog_path = os.path.join(project.project_root, "target", "catalog.json")
25+
assert os.path.exists(catalog_path)
26+
catalog = get_artifact(catalog_path)
27+
28+
# verify the catalog
29+
assert set(catalog) == {"errors", "metadata", "nodes", "sources"}
30+
verify_metadata(
31+
catalog["metadata"],
32+
"https://schemas.getdbt.com/dbt/catalog/v1.json",
33+
start_time,
34+
)
35+
assert not catalog["errors"]
36+
for key in "nodes", "sources":
37+
for unique_id, expected_node in expected_catalog[key].items():
38+
found_node = catalog[key][unique_id]
39+
for node_key in expected_node:
40+
assert node_key in found_node
41+
42+
if node_key == "metadata" and ignore_owner:
43+
expected_node[node_key]["owner"] = found_node[node_key]["owner"]
44+
45+
assert (
46+
found_node[node_key] == expected_node[node_key]
47+
), f"Key '{node_key}' in '{unique_id}' did not match"
48+
49+
1750
class TestDocsGenerateSQLServer(BaseDocsGenerate):
1851
@pytest.fixture(scope="class")
1952
def expected_catalog(self, project):
@@ -28,6 +61,22 @@ def expected_catalog(self, project):
2861
model_stats=no_stats(),
2962
)
3063

64+
# Test "--no-compile" flag works and produces no manifest.json
65+
def test_run_and_generate_no_compile(self, project, expected_catalog, is_azure: bool):
66+
start_time = run_and_generate(project, ["--no-compile"])
67+
assert not os.path.exists(os.path.join(project.project_root, "target", "manifest.json"))
68+
verify_catalog(project, expected_catalog, start_time, is_azure)
69+
70+
# Test generic "docs generate" command
71+
def test_run_and_generate(self, project, expected_catalog, is_azure: bool):
72+
start_time = run_and_generate(project)
73+
verify_catalog(project, expected_catalog, start_time, is_azure)
74+
75+
# Check that assets have been copied to the target directory for use in the docs html page
76+
assert os.path.exists(os.path.join(".", "target", "assets"))
77+
assert os.path.exists(os.path.join(".", "target", "assets", "lorem-ipsum.txt"))
78+
assert not os.path.exists(os.path.join(".", "target", "non-existent-assets"))
79+
3180

3281
class TestDocsGenReferencesSQLServer(BaseDocsGenReferences):
3382
@pytest.fixture(scope="class")
@@ -77,3 +126,7 @@ def models(self):
77126
"ephemeral_copy.sql": ref_models__ephemeral_copy_sql,
78127
"docs.md": ref_models__docs_md,
79128
}
129+
130+
def test_references(self, project, expected_catalog, is_azure: bool):
131+
start_time = run_and_generate(project)
132+
verify_catalog(project, expected_catalog, start_time, is_azure)

0 commit comments

Comments
 (0)