Skip to content

Commit

Permalink
Move test for ephemeral model with alias to dedicated test in test_co…
Browse files Browse the repository at this point in the history
…mpile.py
  • Loading branch information
jeancochrane committed Jul 17, 2024
1 parent 582f972 commit 5da895c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
9 changes: 9 additions & 0 deletions tests/functional/compile/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
select sum(n) from t;
"""

first_ephemeral_model_with_alias_sql = """
{{ config(materialized = 'ephemeral', alias = 'first_alias') }}
select 1 as fun
"""

second_ephemeral_model_with_alias_sql = """
select * from {{ ref('first_ephemeral_model_with_alias') }}
"""

schema_yml = """
version: 2
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/compile/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
from tests.functional.assertions.test_runner import dbtTestRunner
from tests.functional.compile.fixtures import (
first_ephemeral_model_sql,
first_ephemeral_model_with_alias_sql,
first_model_sql,
model_multiline_jinja,
schema_yml,
second_ephemeral_model_sql,
second_ephemeral_model_with_alias_sql,
second_model_sql,
third_ephemeral_model_sql,
with_recursive_model_sql,
Expand Down Expand Up @@ -128,6 +130,24 @@ def test_with_recursive_cte(self, project):
]


class TestEphemeralModelWithAlias:
@pytest.fixture(scope="class")
def models(self):
return {
"first_ephemeral_model_with_alias.sql": first_ephemeral_model_with_alias_sql,
"second_ephemeral_model_with_alias.sql": second_ephemeral_model_with_alias_sql,
}

def test_compile(self, project):
run_dbt(["compile"])

assert get_lines("second_ephemeral_model_with_alias") == [
"with __dbt__cte__first_alias as (",
"select 1 as fun",
") select * from __dbt__cte__first_alias",
]


class TestCompile:
@pytest.fixture(scope="class")
def models(self):
Expand Down
10 changes: 1 addition & 9 deletions tests/functional/schema/fixtures/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@
)
_TABLE_TWO_DOT_MODEL_SCHEMA = "second_schema"
_TABLE_TWO_DOT_MODEL_NAME = f"{_TABLE_TWO_DOT_MODEL_SCHEMA}.view_2"
_TABLE_TWO_DOT_MODEL = (
"""
{{ config(materialized='ephemeral') }}
select * from {{ ref('"""
+ _TABLE_ONE_DOT_MODEL_NAME
+ """') }}
"""
)
_TABLE_TWO_DOT_MODEL = "select * from {{ ref('" + _TABLE_ONE_DOT_MODEL_NAME + "') }}"

_TABLE_THREE_SCHEMA = "test"
_TABLE_THREE = (
Expand Down
8 changes: 6 additions & 2 deletions tests/functional/schema/test_custom_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
_TABLE_TWO,
_TABLE_TWO_DOT_MODEL,
_TABLE_TWO_DOT_MODEL_NAME,
_TABLE_TWO_DOT_MODEL_SCHEMA,
_TABLE_TWO_SCHEMA,
_VALIDATION_SQL,
)
Expand Down Expand Up @@ -201,15 +202,18 @@ def test__postgres__custom_schema_from_model_name(
project.run_sql(_VALIDATION_SQL)
run_dbt(["seed"])
results = run_dbt(["run"])
# Model 2 is ephemeral, so it should not show up in the results list
assert len(results) == 2
assert len(results) == 3
table_results = {r.node.name: r.node.schema for r in results.results}

assert table_results[_TABLE_ONE_DOT_MODEL_NAME] == _TABLE_ONE_DOT_MODEL_SCHEMA
assert table_results[_TABLE_TWO_DOT_MODEL_NAME] == _TABLE_TWO_DOT_MODEL_SCHEMA
assert table_results["table_3"] == f"{project.test_schema}"
check_relations_equal(
adapter=project.adapter, relation_names=("seed", _TABLE_ONE_DOT_MODEL_NAME)
)
check_relations_equal(
adapter=project.adapter, relation_names=("seed", _TABLE_TWO_DOT_MODEL_NAME)
)
check_relations_equal(
adapter=project.adapter, relation_names=("agg", f"{project.test_schema}.table_3")
)

0 comments on commit 5da895c

Please sign in to comment.