Skip to content

Commit

Permalink
remove docs testing complexity now we have schema auth
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebruyn committed May 21, 2023
1 parent cc9dbae commit 20b39de
Showing 1 changed file with 12 additions and 53 deletions.
65 changes: 12 additions & 53 deletions tests/functional/adapter/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,24 @@
from dbt.tests.adapter.basic.test_docs_generate import (
BaseDocsGenerate,
BaseDocsGenReferences,
get_artifact,
ref_models__docs_md,
ref_models__ephemeral_copy_sql,
ref_models__schema_yml,
ref_sources__schema_yml,
run_and_generate,
verify_metadata,
)


def verify_catalog(project, expected_catalog, start_time, ignore_owner):
# get the catalog.json
catalog_path = os.path.join(project.project_root, "target", "catalog.json")
assert os.path.exists(catalog_path)
catalog = get_artifact(catalog_path)

# verify the catalog
assert set(catalog) == {"errors", "metadata", "nodes", "sources"}
verify_metadata(
catalog["metadata"],
"https://schemas.getdbt.com/dbt/catalog/v1.json",
start_time,
)
assert not catalog["errors"]
for key in "nodes", "sources":
for unique_id, expected_node in expected_catalog[key].items():
found_node = catalog[key][unique_id]
for node_key in expected_node:
assert node_key in found_node

if node_key == "metadata" and ignore_owner:
expected_node[node_key]["owner"] = found_node[node_key]["owner"]

assert (
found_node[node_key] == expected_node[node_key]
), f"Key '{node_key}' in '{unique_id}' did not match"


class TestDocsGenerateSQLServer(BaseDocsGenerate):
@staticmethod
@pytest.fixture(scope="class")
def dbt_profile_target_update():
return {"schema_authorization": "{{ env_var('DBT_TEST_USER_1') }}"}

@pytest.fixture(scope="class")
def expected_catalog(self, project):
return base_expected_catalog(
project,
role="dbo",
role=os.getenv("DBT_TEST_USER_1"),
id_type="int",
text_type="varchar",
time_type="datetime",
Expand All @@ -61,29 +35,18 @@ def expected_catalog(self, project):
model_stats=no_stats(),
)

# Test "--no-compile" flag works and produces no manifest.json
def test_run_and_generate_no_compile(self, project, expected_catalog, is_azure: bool):
start_time = run_and_generate(project, ["--no-compile"])
assert not os.path.exists(os.path.join(project.project_root, "target", "manifest.json"))
verify_catalog(project, expected_catalog, start_time, is_azure)

# Test generic "docs generate" command
def test_run_and_generate(self, project, expected_catalog, is_azure: bool):
start_time = run_and_generate(project)
verify_catalog(project, expected_catalog, start_time, is_azure)

# Check that assets have been copied to the target directory for use in the docs html page
assert os.path.exists(os.path.join(".", "target", "assets"))
assert os.path.exists(os.path.join(".", "target", "assets", "lorem-ipsum.txt"))
assert not os.path.exists(os.path.join(".", "target", "non-existent-assets"))


class TestDocsGenReferencesSQLServer(BaseDocsGenReferences):
@staticmethod
@pytest.fixture(scope="class")
def dbt_profile_target_update():
return {"schema_authorization": "{{ env_var('DBT_TEST_USER_1') }}"}

@pytest.fixture(scope="class")
def expected_catalog(self, project):
return expected_references_catalog(
project,
role="dbo",
role=os.getenv("DBT_TEST_USER_1"),
id_type="int",
text_type="varchar",
time_type="datetime",
Expand Down Expand Up @@ -126,7 +89,3 @@ def models(self):
"ephemeral_copy.sql": ref_models__ephemeral_copy_sql,
"docs.md": ref_models__docs_md,
}

def test_references(self, project, expected_catalog, is_azure: bool):
start_time = run_and_generate(project)
verify_catalog(project, expected_catalog, start_time, is_azure)

0 comments on commit 20b39de

Please sign in to comment.