Skip to content

Commit

Permalink
move dynamic table tests down into the relation tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Sep 20, 2024
1 parent 7580e8a commit ec9246b
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/functional/relation_tests/test_relation_type_change.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from dataclasses import dataclass
from itertools import product

from dbt.tests.util import run_dbt
import pytest

from tests.functional.relation_tests import models
from tests.functional.utils import query_relation_type, update_model


@dataclass
class Model:
model: str
relation_type: str

@property
def name(self) -> str:
return f"{self.relation_type}"


@dataclass
class Scenario:
initial: Model
final: Model

@property
def name(self) -> str:
return f"REPLACE_{self.initial.name}__WITH_{self.final.name}"

@property
def error_message(self) -> str:
return f"Failed when migrating from: {self.initial.name} to: {self.final.name}"


relations = [
Model(models.VIEW, "view"),
Model(models.TABLE, "table"),
Model(models.DYNAMIC_TABLE, "dynamic_table"),
]
scenarios = [Scenario(*scenario) for scenario in product(relations, relations)]


class TestRelationTypeChange:

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

@pytest.fixture(scope="class", autouse=True)
def models(self):
yield {f"{scenario.name}.sql": scenario.initial.model for scenario in scenarios}

@pytest.fixture(scope="class", autouse=True)
def setup(self, project):
run_dbt(["seed"])
run_dbt(["run"])
for scenario in scenarios:
update_model(project, scenario.name, scenario.final.model)
run_dbt(["run"])

@pytest.mark.parametrize("scenario", scenarios, ids=[scenario.name for scenario in scenarios])
def test_replace(self, project, scenario):
relation_type = query_relation_type(project, scenario.name)
assert relation_type == scenario.final.relation_type, scenario.error_message

0 comments on commit ec9246b

Please sign in to comment.