Skip to content

Commit

Permalink
migrate ref override (#6600)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenyuLInx authored Jan 13, 2023
1 parent 7077c47 commit 585e7c5
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 46 deletions.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions test/integration/055_ref_override_tests/seeds/seed_1.csv

This file was deleted.

4 changes: 0 additions & 4 deletions test/integration/055_ref_override_tests/seeds/seed_2.csv

This file was deleted.

30 changes: 0 additions & 30 deletions test/integration/055_ref_override_tests/test_ref_override.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def models(self):
return {'materialized.sql': model_sql}

def test_table_materialization_sort_dist_no_op(self, project):
# basic table mat test, sort and dist is not supported by postgres so the result table would still be same as input
# basic table materialization test, sort and dist is not supported by postgres so the result table would still be same as input

# check seed
results = run_dbt(["seed"])
Expand Down
79 changes: 79 additions & 0 deletions tests/functional/ref_override/test_ref_override.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import pytest

from dbt.tests.util import run_dbt, check_relations_equal
from dbt.tests.fixtures.project import write_project_files


models__ref_override_sql = """
select
*
from {{ ref('seed_1') }}
"""

macros__ref_override_macro_sql = """
-- Macro to override ref and always return the same result
{% macro ref(modelname) %}
{% do return(builtins.ref(modelname).replace_path(identifier='seed_2')) %}
{% endmacro %}
"""

seeds__seed_2_csv = """a,b
6,2
12,4
18,6"""

seeds__seed_1_csv = """a,b
1,2
2,4
3,6"""


@pytest.fixture(scope="class")
def models():
return {"ref_override.sql": models__ref_override_sql}


@pytest.fixture(scope="class")
def macros():
return {"ref_override_macro.sql": macros__ref_override_macro_sql}


@pytest.fixture(scope="class")
def seeds():
return {"seed_2.csv": seeds__seed_2_csv, "seed_1.csv": seeds__seed_1_csv}


@pytest.fixture(scope="class")
def project_files(
project_root,
models,
macros,
seeds,
):
write_project_files(project_root, "models", models)
write_project_files(project_root, "macros", macros)
write_project_files(project_root, "seeds", seeds)


class TestRefOverride:
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"config-version": 2,
"seed-paths": ["seeds"],
"macro-paths": ["macros"],
"seeds": {
"quote_columns": False,
},
}

def test_ref_override(
self,
project,
):
run_dbt(["seed"])
run_dbt(["run"])

# We want it to equal seed_2 and not seed_1. If it's
# still pointing at seed_1 then the override hasn't worked.
check_relations_equal(project.adapter, ["ref_override", "seed_2"])

0 comments on commit 585e7c5

Please sign in to comment.