Skip to content

Commit 47fbbfb

Browse files
committed
ignore owner when testing docs in azure
1 parent a09ca8b commit 47fbbfb

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

tests/conftest.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from typing import Any
23

34
import pytest
45
from _pytest.fixtures import FixtureRequest
@@ -13,7 +14,7 @@ def pytest_addoption(parser):
1314

1415

1516
@pytest.fixture(scope="class")
16-
def dbt_profile_target(request: FixtureRequest):
17+
def dbt_profile_target(request: FixtureRequest) -> dict[str, Any]:
1718
profile = request.config.getoption("--profile")
1819

1920
if profile == "ci_sql_server":
@@ -34,7 +35,13 @@ def dbt_profile_target(request: FixtureRequest):
3435
raise ValueError(f"Unknown profile: {profile}")
3536

3637

37-
def _all_profiles_base():
38+
@pytest.fixture(scope="class")
39+
def is_azure(request: FixtureRequest) -> bool:
40+
profile = request.config.getoption("--profile")
41+
return "azure" in profile
42+
43+
44+
def _all_profiles_base() -> dict[str, Any]:
3845
return {
3946
"type": "sqlserver",
4047
"driver": os.getenv("SQLSERVER_TEST_DRIVER", "ODBC Driver 18 for SQL Server"),
@@ -43,7 +50,7 @@ def _all_profiles_base():
4350
}
4451

4552

46-
def _profile_ci_azure_base():
53+
def _profile_ci_azure_base() -> dict[str, Any]:
4754
return {
4855
**_all_profiles_base(),
4956
**{
@@ -55,7 +62,7 @@ def _profile_ci_azure_base():
5562
}
5663

5764

58-
def _profile_ci_azure_basic():
65+
def _profile_ci_azure_basic() -> dict[str, Any]:
5966
return {
6067
**_profile_ci_azure_base(),
6168
**{
@@ -65,7 +72,7 @@ def _profile_ci_azure_basic():
6572
}
6673

6774

68-
def _profile_ci_azure_cli():
75+
def _profile_ci_azure_cli() -> dict[str, Any]:
6976
return {
7077
**_profile_ci_azure_base(),
7178
**{
@@ -74,7 +81,7 @@ def _profile_ci_azure_cli():
7481
}
7582

7683

77-
def _profile_ci_azure_auto():
84+
def _profile_ci_azure_auto() -> dict[str, Any]:
7885
return {
7986
**_profile_ci_azure_base(),
8087
**{
@@ -83,7 +90,7 @@ def _profile_ci_azure_auto():
8390
}
8491

8592

86-
def _profile_ci_azure_environment():
93+
def _profile_ci_azure_environment() -> dict[str, Any]:
8794
return {
8895
**_profile_ci_azure_base(),
8996
**{
@@ -92,7 +99,7 @@ def _profile_ci_azure_environment():
9299
}
93100

94101

95-
def _profile_ci_sql_server():
102+
def _profile_ci_sql_server() -> dict[str, Any]:
96103
return {
97104
**_all_profiles_base(),
98105
**{
@@ -106,7 +113,7 @@ def _profile_ci_sql_server():
106113
}
107114

108115

109-
def _profile_user():
116+
def _profile_user() -> dict[str, Any]:
110117
profile = {
111118
**_all_profiles_base(),
112119
**{
@@ -121,7 +128,7 @@ def _profile_user():
121128
return profile
122129

123130

124-
def _profile_user_azure():
131+
def _profile_user_azure() -> dict[str, Any]:
125132
profile = {
126133
**_all_profiles_base(),
127134
**{

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)