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

Test source and model quoting respects dbt_project configs as documented #10906

Closed
wants to merge 3 commits into from
Closed
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
64 changes: 64 additions & 0 deletions tests/functional/relation_quoting/test_relation_quoting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest

from dbt.tests.util import read_file, run_dbt

_SOURCES_YML = """
sources:
- name: source_name
database: source_database
schema: source_schema
tables:
- name: customers
"""


class TestSourceQuotingGlobalConfigs:
@pytest.fixture(scope="class")
def project_config_update(self):
# Postgres quoting configs are True by default -- turn them all to False to show they are not respected during source rendering
return {
"quoting": {
"database": False,
"schema": False,
"identifier": False,
},
}

@pytest.fixture(scope="class")
def models(self):
return {
"sources.yml": _SOURCES_YML,
"model.sql": "select * from {{ source('source_name', 'customers') }}",
}

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

generated_sql = read_file("target", "compiled", "test", "models", "model.sql")
assert generated_sql == 'select * from "source_database"."source_schema"."customers"'


class TestModelQuoting:
@pytest.fixture(scope="class")
def project_config_update(self):
# Postgres quoting configs are True by default -- turn them all to False to show they are respected during model rendering
return {
"quoting": {
"database": False,
"schema": False,
"identifier": False,
},
}

@pytest.fixture(scope="class")
def models(self):
return {
"model.sql": "select 1 as id",
"model_downstream.sql": "select * from {{ ref('model') }}",
}

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

generated_sql = read_file("target", "compiled", "test", "models", "model_downstream.sql")
assert generated_sql == f"select * from dbt.{project.test_schema}.model"
Loading