Skip to content

Commit f201af8

Browse files
committed
move docs to basic
1 parent 4fee40a commit f201af8

File tree

2 files changed

+131
-132
lines changed

2 files changed

+131
-132
lines changed

tests/functional/adapter/test_basic.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
import os
2+
13
import pytest
4+
from dbt.tests.adapter.basic.expected_catalog import (
5+
base_expected_catalog,
6+
expected_references_catalog,
7+
no_stats,
8+
)
29
from dbt.tests.adapter.basic.files import incremental_not_schema_change_sql
310
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod
411
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
12+
from dbt.tests.adapter.basic.test_docs_generate import (
13+
BaseDocsGenerate,
14+
BaseDocsGenReferences,
15+
get_artifact,
16+
ref_models__docs_md,
17+
ref_models__ephemeral_copy_sql,
18+
ref_models__schema_yml,
19+
ref_sources__schema_yml,
20+
run_and_generate,
21+
verify_metadata,
22+
)
523
from dbt.tests.adapter.basic.test_empty import BaseEmpty
624
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral
725
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
@@ -74,3 +92,116 @@ class TestValidateConnectionSQLServer(BaseValidateConnection):
7492

7593
class TestTableMatSQLServer(BaseTableMaterialization):
7694
pass
95+
96+
97+
def verify_catalog(project, expected_catalog, start_time, ignore_owner):
98+
# get the catalog.json
99+
catalog_path = os.path.join(project.project_root, "target", "catalog.json")
100+
assert os.path.exists(catalog_path)
101+
catalog = get_artifact(catalog_path)
102+
103+
# verify the catalog
104+
assert set(catalog) == {"errors", "metadata", "nodes", "sources"}
105+
verify_metadata(
106+
catalog["metadata"],
107+
"https://schemas.getdbt.com/dbt/catalog/v1.json",
108+
start_time,
109+
)
110+
assert not catalog["errors"]
111+
for key in "nodes", "sources":
112+
for unique_id, expected_node in expected_catalog[key].items():
113+
found_node = catalog[key][unique_id]
114+
for node_key in expected_node:
115+
assert node_key in found_node
116+
117+
if node_key == "metadata" and ignore_owner:
118+
expected_node[node_key]["owner"] = found_node[node_key]["owner"]
119+
120+
assert (
121+
found_node[node_key] == expected_node[node_key]
122+
), f"Key '{node_key}' in '{unique_id}' did not match"
123+
124+
125+
class TestDocsGenerateSQLServer(BaseDocsGenerate):
126+
@pytest.fixture(scope="class")
127+
def expected_catalog(self, project):
128+
return base_expected_catalog(
129+
project,
130+
role="dbo",
131+
id_type="int",
132+
text_type="varchar",
133+
time_type="datetime",
134+
view_type="VIEW",
135+
table_type="BASE TABLE",
136+
model_stats=no_stats(),
137+
)
138+
139+
# Test "--no-compile" flag works and produces no manifest.json
140+
def test_run_and_generate_no_compile(self, project, expected_catalog, is_azure: bool):
141+
start_time = run_and_generate(project, ["--no-compile"])
142+
assert not os.path.exists(os.path.join(project.project_root, "target", "manifest.json"))
143+
verify_catalog(project, expected_catalog, start_time, is_azure)
144+
145+
# Test generic "docs generate" command
146+
def test_run_and_generate(self, project, expected_catalog, is_azure: bool):
147+
start_time = run_and_generate(project)
148+
verify_catalog(project, expected_catalog, start_time, is_azure)
149+
150+
# Check that assets have been copied to the target directory for use in the docs html page
151+
assert os.path.exists(os.path.join(".", "target", "assets"))
152+
assert os.path.exists(os.path.join(".", "target", "assets", "lorem-ipsum.txt"))
153+
assert not os.path.exists(os.path.join(".", "target", "non-existent-assets"))
154+
155+
156+
class TestDocsGenReferencesSQLServer(BaseDocsGenReferences):
157+
@pytest.fixture(scope="class")
158+
def expected_catalog(self, project):
159+
return expected_references_catalog(
160+
project,
161+
role="dbo",
162+
id_type="int",
163+
text_type="varchar",
164+
time_type="datetime",
165+
bigint_type="int",
166+
view_type="VIEW",
167+
table_type="BASE TABLE",
168+
model_stats=no_stats(),
169+
)
170+
171+
@pytest.fixture(scope="class")
172+
def models(self):
173+
ref_models__ephemeral_summary_sql_no_order_by = """
174+
{{
175+
config(
176+
materialized = "table"
177+
)
178+
}}
179+
180+
select first_name, count(*) as ct from {{ref('ephemeral_copy')}}
181+
group by first_name
182+
"""
183+
184+
ref_models__view_summary_sql_no_order_by = """
185+
{{
186+
config(
187+
materialized = "view"
188+
)
189+
}}
190+
191+
select first_name, ct from {{ref('ephemeral_summary')}}
192+
"""
193+
194+
return {
195+
"schema.yml": ref_models__schema_yml,
196+
"sources.yml": ref_sources__schema_yml,
197+
# order by not allowed in VIEWS
198+
"view_summary.sql": ref_models__view_summary_sql_no_order_by,
199+
# order by not allowed in CTEs
200+
"ephemeral_summary.sql": ref_models__ephemeral_summary_sql_no_order_by,
201+
"ephemeral_copy.sql": ref_models__ephemeral_copy_sql,
202+
"docs.md": ref_models__docs_md,
203+
}
204+
205+
def test_references(self, project, expected_catalog, is_azure: bool):
206+
start_time = run_and_generate(project)
207+
verify_catalog(project, expected_catalog, start_time, is_azure)

tests/functional/adapter/test_docs.py

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)