Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prdpsvs committed Apr 24, 2024
1 parent dc6f018 commit 8a4dd41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 114 deletions.
112 changes: 1 addition & 111 deletions tests/functional/adapter/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
from dbt.tests.adapter.basic import files
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod

# from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_empty import BaseEmpty
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
Expand All @@ -15,114 +13,6 @@
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp
from dbt.tests.adapter.basic.test_validate_connection import BaseValidateConnection
from dbt.tests.util import (
check_relation_types,
check_relations_equal,
check_result_nodes_by_name,
relation_from_name,
run_dbt,
)


class BaseSimpleMaterializations:
@pytest.fixture(scope="class")
def models(self):
return {
"view_model.sql": files.base_view_sql,
"table_model.sql": files.base_table_sql,
"swappable.sql": files.base_materialized_var_sql,
"schema.yml": files.schema_base_yml,
}

@pytest.fixture(scope="class")
def seeds(self):
return {
"base.csv": files.seeds_base_csv,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"name": "base",
}

@pytest.fixture(autouse=True)
def clean_up(self, project):
yield
with project.adapter.connection_named("__test"):
relation = project.adapter.Relation.create(
database=project.database, schema=project.test_schema
)
project.adapter.drop_schema(relation)

pass

def test_base(self, project):
# seed command
results = run_dbt(["seed"])
# seed result length
assert len(results) == 1

# run command
results = run_dbt()
# run result length
assert len(results) == 3

# names exist in result nodes
check_result_nodes_by_name(results, ["view_model", "table_model", "swappable"])

# check relation types
expected = {
"base": "table",
"view_model": "view",
"table_model": "table",
"swappable": "table",
}
check_relation_types(project.adapter, expected)

# base table rowcount
relation = relation_from_name(project.adapter, "base")
result = project.run_sql(f"select count(*) as num_rows from {relation}", fetch="one")
assert result[0] == 10

# relations_equal
check_relations_equal(project.adapter, ["base", "view_model", "table_model", "swappable"])

# check relations in catalog
catalog = run_dbt(["docs", "generate"])
assert len(catalog.nodes) == 4
assert len(catalog.sources) == 1

# run_dbt changing materialized_var to view
if project.test_config.get("require_full_refresh", False): # required for BigQuery
results = run_dbt(
["run", "--full-refresh", "-m", "swappable", "--vars", "materialized_var: view"]
)
else:
results = run_dbt(["run", "-m", "swappable", "--vars", "materialized_var: view"])
assert len(results) == 1

# check relation types, swappable is view
expected = {
"base": "table",
"view_model": "view",
"table_model": "table",
"swappable": "view",
}
check_relation_types(project.adapter, expected)

# run_dbt changing materialized_var to incremental
results = run_dbt(["run", "-m", "swappable", "--vars", "materialized_var: incremental"])
assert len(results) == 1

# check relation types, swappable is table
expected = {
"base": "table",
"view_model": "view",
"table_model": "table",
"swappable": "table",
}
check_relation_types(project.adapter, expected)


class TestSimpleMaterializations(BaseSimpleMaterializations):
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/adapter/test_empty.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dbt.tests.adapter.empty.test_empty import BaseTestEmpty
# from dbt.tests.adapter.empty.test_empty import BaseTestEmpty


class TestEmpty(BaseTestEmpty):
pass
# class TestEmpty(BaseTestEmpty):
# pass

0 comments on commit 8a4dd41

Please sign in to comment.