Skip to content

Commit

Permalink
adding
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin-Thakur committed Nov 2, 2023
1 parent 8bdf4f6 commit f0fddab
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/vertica-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
run: python -m pytest tests/functional/adapter/test_basic.py
- name: Test Constraints
run: python -m pytest tests/functional/adapter/test_constraints.py
- name: Test Dbt clone
run: python -m pytest tests/functional/adapter/dbt_clone/test_dbt_clone.py
- name: Test Constraints1
run: python -m pytest tests/functional/adapter/constraints/test_constraints.py
- name: Test Incremental
Expand Down
124 changes: 124 additions & 0 deletions tests/functional/adapter/dbt_clone/test_dbt_clone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from copy import deepcopy
from collections import Counter
from dbt.tests.util import run_dbt
from dbt.tests.adapter.dbt_clone.test_dbt_clone import BaseClonePossible

import pytest
import shutil
import os


class TestSnowflakeClonePossible(BaseClonePossible):

def test_can_clone_true(self, project, unique_schema, other_schema):
project.create_test_schema(other_schema)
self.run_and_save_state(project.project_root, with_snapshot=True)

clone_args = [
"clone",
"--state",
"state",
"--target",
"otherschema",
]

results = run_dbt(clone_args)
assert len(results) == 4
print(results)

schema_relations = project.adapter.list_relations(
database=project.database, schema=other_schema
)
types = [r.type for r in schema_relations]
count_types = Counter(types)
assert count_types == Counter({"table": 3, "view": 1})

# objects already exist, so this is a no-op
results = run_dbt(clone_args)
assert len(results) == 4
assert all("no-op" in r.message.lower() for r in results)

# recreate all objects
assert len(results) == 4

# select only models this time
results = run_dbt([*clone_args, "--resource-type", "model"])
assert len(results) == 2
assert all("no-op" in r.message.lower() for r in results)

# @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=f"{project.test_schema}_SEEDS"
# )
# project.adapter.drop_schema(relation)

# relation = project.adapter.Relation.create(
# database=project.database, schema=project.test_schema
# )
# project.adapter.drop_schema(relation)

# pass


table_model_1_sql = """
{{ config(
materialized='table',
transient=true,
) }}
select 1 as fun
"""





class TestSnowflakeCloneTrainsentTable:
@pytest.fixture(scope="class")
def models(self):
return {
"table_model.sql": table_model_1_sql,
}

@pytest.fixture(scope="class")
def other_schema(self, unique_schema):
return unique_schema + "_other"

@pytest.fixture(scope="class")
def profiles_config_update(self, dbt_profile_target, unique_schema, other_schema):
outputs = {"default": dbt_profile_target, "otherschema": deepcopy(dbt_profile_target)}
outputs["default"]["schema"] = unique_schema
outputs["otherschema"]["schema"] = other_schema
return {"test": {"outputs": outputs, "target": "default"}}

def copy_state(self, project_root):
state_path = os.path.join(project_root, "state")
if not os.path.exists(state_path):
os.makedirs(state_path)
shutil.copyfile(
f"{project_root}/target/manifest.json", f"{project_root}/state/manifest.json"
)

def run_and_save_state(self, project_root, with_snapshot=False):
results = run_dbt(["run"])
assert len(results) == 1
assert not any(r.node.deferred for r in results)

self.copy_state(project_root)

def test_can_clone_transient_table(self, project, other_schema):
project.create_test_schema(other_schema)
self.run_and_save_state(project.project_root)

clone_args = [
"clone",
"--state",
"state",
"--target",
"otherschema",
]

results = run_dbt(clone_args)
assert len(results) == 1

0 comments on commit f0fddab

Please sign in to comment.