Skip to content

Commit

Permalink
convert used_schemas to manifest for 1.7 testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Feb 26, 2024
1 parent 12eb348 commit 01266fc
Showing 1 changed file with 37 additions and 58 deletions.
95 changes: 37 additions & 58 deletions tests/functional/adapter/catalog_tests/test_get_catalog.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,71 @@
from dbt.contracts.relation import RelationType
from dbt.tests.util import get_connection
from dbt.tests.util import get_connection, get_manifest, run_dbt
import pytest

from tests.functional.adapter.catalog_tests import files


class TestGetCatalog:
@pytest.fixture(scope="class", autouse=True)
def seeds(self):
return {"my_seed.csv": files.MY_SEED}

@pytest.fixture(scope="class", autouse=True)
def models(self):
yield {
"my_table.sql": files.MY_TABLE,
"my_view.sql": files.MY_VIEW,
"my_materialized_view.sql": files.MY_MATERIALIZED_VIEW,
}

@pytest.fixture(scope="class", autouse=True)
def setup(self, project):
run_dbt(["seed"])
run_dbt(["run"])

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

@pytest.fixture(scope="class")
def my_seed(self, adapter, my_schema):
relation = adapter.Relation.create(
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_seed",
type=RelationType.Table,
)
with get_connection(adapter):
sql = f"""
create table {relation.database}.{relation.schema}.{relation.identifier} (
id integer,
value integer,
record_valid_date timestamp
);
insert into {relation.database}.{relation.schema}.{relation.identifier}
(id, value, record_valid_date) values
(1,100,'2023-01-01 00:00:00'),
(2,200,'2023-01-02 00:00:00'),
(3,300,'2023-01-02 00:00:00')
;
"""
adapter.execute(sql)
yield relation

@pytest.fixture(scope="class")
def my_table(self, adapter, my_schema, my_seed):
relation = adapter.Relation.create(
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_table",
type=RelationType.Table,
)
with get_connection(adapter):
sql = f"""
create table {relation.database}.{relation.schema}.{relation.identifier} as
select * from {my_seed.database}.{my_seed.schema}.{my_seed.identifier}
;
"""
adapter.execute(sql)
yield relation

@pytest.fixture(scope="class")
def my_view(self, adapter, my_schema, my_seed):
relation = adapter.Relation.create(
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_view",
type=RelationType.View,
)
with get_connection(adapter):
sql = f"""
create view {relation.database}.{relation.schema}.{relation.identifier} as
select * from {my_seed.database}.{my_seed.schema}.{my_seed.identifier}
;
"""
adapter.execute(sql)
yield relation

@pytest.fixture(scope="class")
def my_materialized_view(self, adapter, my_schema, my_seed):
relation = adapter.Relation.create(
yield adapter.Relation.create(
database=my_schema.database,
schema=my_schema.schema,
identifier="my_materialized_view",
type=RelationType.MaterializedView,
)
with get_connection(adapter):
sql = f"""
create materialized view {relation.database}.{relation.schema}.{relation.identifier} as
select * from {my_seed.database}.{my_seed.schema}.{my_seed.identifier}
;
"""
adapter.execute(sql)
yield relation

@pytest.fixture(scope="class")
def my_information_schema(self, adapter, my_schema):
Expand All @@ -97,23 +75,27 @@ def my_information_schema(self, adapter, my_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,
my_schema,
setup,
my_information_schema,
my_seed,
my_table,
my_view,
my_materialized_view,
my_information_schema,
my_manifest,
):
my_schemas = frozenset({(my_schema.database, my_schema.schema)})
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,
used_schemas=my_schemas,
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
Expand All @@ -123,19 +105,16 @@ def test_get_one_catalog_by_relations(
def test_get_one_catalog_by_schemas(
self,
adapter,
my_schema,
my_seed,
my_table,
my_view,
my_materialized_view,
setup,
my_information_schema,
my_schema,
my_manifest,
):
my_schemas = frozenset({(my_schema.database, my_schema.schema)})
with get_connection(adapter):
catalog = adapter._get_one_catalog(
information_schema=my_information_schema,
schemas={my_schema.schema},
used_schemas=my_schemas,
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
Expand Down

0 comments on commit 01266fc

Please sign in to comment.