Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert 037_external_references #6589

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

57 changes: 57 additions & 0 deletions tests/functional/external_reference/test_external_reference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest

from dbt.tests.util import run_dbt


external_model_sql = """
{{
config(
materialized = "view"
)
}}

select * from "{{ this.schema + 'z' }}"."external"
"""

model_sql = """
select 1 as id
"""


class TestExternalReference:
@pytest.fixture(scope="class")
def models(self):
return {"model.sql": external_model_sql}

def test_external_reference(self, project, unique_schema):
external_schema = unique_schema + 'z'
project.run_sql(f'create schema "{external_schema}"')
project.run_sql(f'create table "{external_schema}"."external" (id integer)')
project.run_sql(f'insert into "{external_schema}"."external" values (1), (2)')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are (1) and (2) placeholders?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are concrete values of id being inserted into the "{external_schema}"."external" table


results = run_dbt(['run'])
assert len(results) == 1

# running it again should succeed
results = run_dbt(['run'])
assert len(results) == 1


# The opposite of the test above -- check that external relations that
# depend on a dbt model do not create issues with caching
class TestExternalDependency:
@pytest.fixture(scope="class")
def models(self):
return {"model.sql": model_sql}

def test_external_reference(self, project, unique_schema):
results = run_dbt(['run'])
assert len(results) == 1

external_schema = unique_schema + 'z'
project.run_sql(f'create schema "{external_schema}"')
project.run_sql(f'create view "{external_schema}"."external" as (select * from {unique_schema}.model)')

# running it again should succeed
results = run_dbt(['run'])
assert len(results) == 1