Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore owner when testing docs in azure #365

Merged
merged 2 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def dbt_profile_target(request: FixtureRequest):
raise ValueError(f"Unknown profile: {profile}")


@pytest.fixture(scope="class")
def is_azure(request: FixtureRequest) -> bool:
profile = request.config.getoption("--profile")
return "azure" in profile


def _all_profiles_base():
return {
"type": "sqlserver",
Expand Down
53 changes: 53 additions & 0 deletions tests/functional/adapter/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pytest
from dbt.tests.adapter.basic.expected_catalog import (
base_expected_catalog,
Expand All @@ -7,13 +9,44 @@
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):
@pytest.fixture(scope="class")
def expected_catalog(self, project):
Expand All @@ -28,6 +61,22 @@ 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):
@pytest.fixture(scope="class")
Expand Down Expand Up @@ -77,3 +126,7 @@ 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)