Skip to content

Commit

Permalink
update feature capability to test both get catalog macros
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Feb 28, 2024
1 parent 3328bf0 commit baa8499
Showing 1 changed file with 21 additions and 94 deletions.
115 changes: 21 additions & 94 deletions tests/functional/adapter/catalog_tests/test_get_catalog.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dbt.contracts.relation import RelationType
from dbt.tests.util import get_connection, get_manifest, run_dbt
from dbt.adapters.capability import Capability, CapabilitySupport, Support
from dbt.tests.util import run_dbt
import pytest

from tests.functional.adapter.catalog_tests import files


class TestGetCatalog:
class BaseGetCatalog:
@pytest.fixture(scope="class", autouse=True)
def seeds(self):
return {"my_seed.csv": files.MY_SEED}
Expand All @@ -23,99 +23,26 @@ def setup(self, project):
run_dbt(["seed"])
run_dbt(["run"])

@pytest.fixture(scope="class")
def my_schema(self, project, adapter):
yield adapter.Relation.create(
database=project.database,
schema=project.test_schema,
identifier="",
)

@pytest.fixture(scope="class")
def my_seed(self, adapter, my_schema):
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_seed",
type=RelationType.Table,
class TestGetCatalogByRelations(BaseGetCatalog):
def test_get_one_catalog_by_relations(self, project, adapter):
project.adapter._capabilities[Capability.SchemaMetadataByRelations] = CapabilitySupport(
support=Support.Full
)
results = run_dbt(["docs", "generate"])
assert len(results.nodes) == 4
assert project.adapter._capabilities[
Capability.SchemaMetadataByRelations
] == CapabilitySupport(support=Support.Full)

@pytest.fixture(scope="class")
def my_table(self, adapter, my_schema, my_seed):
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_table",
type=RelationType.Table,
)

@pytest.fixture(scope="class")
def my_view(self, adapter, my_schema, my_seed):
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_view",
type=RelationType.View,
class TestGetCatalogBySchemas(BaseGetCatalog):
def test_get_one_catalog_by_schemas(self, project, adapter):
project.adapter._capabilities[Capability.SchemaMetadataByRelations] = CapabilitySupport(
support=Support.NotImplemented
)

@pytest.fixture(scope="class")
def my_materialized_view(self, adapter, my_schema, my_seed):
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_materialized_view",
type=RelationType.MaterializedView,
)

@pytest.fixture(scope="class")
def my_information_schema(self, adapter, my_schema):
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="INFORMATION_SCHEMA",
).information_schema()

@pytest.fixture(scope="class", autouse=True)
def my_manifest(self, project, setup):
yield get_manifest(project.project_root)

def test_get_one_catalog_by_relations(
self,
adapter,
setup,
my_information_schema,
my_seed,
my_table,
my_view,
my_materialized_view,
my_manifest,
):
my_relations = [my_seed, my_table, my_view, my_materialized_view]
with get_connection(adapter):
catalog = adapter._get_one_catalog_by_relations(
information_schema=my_information_schema,
relations=my_relations,
manifest=my_manifest,
)
# my_seed, my_table, my_view, my_materialized_view each have 3 cols = 12 cols
# my_materialized_view creates an underlying table with 2 additional = 5 cols
# note the underlying table is missing as it's not in `my_relations`
assert len(catalog) == 12

def test_get_one_catalog_by_schemas(
self,
adapter,
setup,
my_information_schema,
my_schema,
my_manifest,
):
with get_connection(adapter):
catalog = adapter._get_one_catalog(
information_schema=my_information_schema,
schemas={my_schema.schema},
manifest=my_manifest,
)
# my_seed, my_table, my_view, my_materialized_view each have 3 cols = 12 cols
# my_materialized_view creates an underlying table with 2 additional = 5 cols
assert len(catalog) == 17
results = run_dbt(["docs", "generate"])
assert len(results.nodes) == 4
assert project.adapter._capabilities[
Capability.SchemaMetadataByRelations
] == CapabilitySupport(support=Support.NotImplemented)

0 comments on commit baa8499

Please sign in to comment.