Files
dbt-core/tests/functional/adapter/aliases/fixtures.py
colin-rogers-dbt 15dcb9a19d Remove dbt-postgres and dbt-tests-adapter from dbt-core (#9492)
* delete dbt-tests-adapter and dbt-postgres from dbt-core

* update non-code files to reflect change

* add changie

* update build-dist.sh

* update tox.ini

* fix build-dist.sh

* move adapter tests into /functional dir

* remove adapter unit tests

* update code comments and README.md
2024-02-05 12:28:57 -08:00

211 lines
3.6 KiB
Python

# macros #
MACROS__CAST_SQL = """
{% macro string_literal(s) -%}
{{ adapter.dispatch('string_literal', macro_namespace='test')(s) }}
{%- endmacro %}
{% macro default__string_literal(s) %}
'{{ s }}'::text
{% endmacro %}
"""
MACROS__EXPECT_VALUE_SQL = """
-- cross-db compatible test, similar to accepted_values
{% test expect_value(model, field, value) %}
select *
from {{ model }}
where {{ field }} != '{{ value }}'
{% endtest %}
"""
# base aliases #
MODELS__SCHEMA_YML = """
version: 2
models:
- name: foo_alias
data_tests:
- expect_value:
field: tablename
value: foo
- name: ref_foo_alias
data_tests:
- expect_value:
field: tablename
value: ref_foo_alias
- name: alias_in_project
data_tests:
- expect_value:
field: tablename
value: project_alias
- name: alias_in_project_with_override
data_tests:
- expect_value:
field: tablename
value: override_alias
"""
MODELS__FOO_ALIAS_SQL = """
{{
config(
alias='foo',
materialized='table'
)
}}
select {{ string_literal(this.name) }} as tablename
"""
MODELS__ALIAS_IN_PROJECT_SQL = """
select {{ string_literal(this.name) }} as tablename
"""
MODELS__ALIAS_IN_PROJECT_WITH_OVERRIDE_SQL = """
{{ config(alias='override_alias') }}
select {{ string_literal(this.name) }} as tablename
"""
MODELS__REF_FOO_ALIAS_SQL = """
{{
config(
materialized='table'
)
}}
with trigger_ref as (
-- we should still be able to ref a model by its filepath
select * from {{ ref('foo_alias') }}
)
-- this name should still be the filename
select {{ string_literal(this.name) }} as tablename
"""
# error #
MODELS_DUPE__MODEL_A_SQL = """
{{ config(alias='duped_alias') }}
select 1 as id
"""
MODELS_DUPE__MODEL_B_SQL = """
{{ config(alias='duped_alias') }}
select 1 as id
"""
MODELS_DUPE__README_MD = """
these should fail because both models have the same alias
and are configured to build in the same schema
"""
# dupe custom database #
MODELS_DUPE_CUSTOM_DATABASE__SCHEMA_YML = """
version: 2
models:
- name: model_a
data_tests:
- expect_value:
field: tablename
value: duped_alias
- name: model_b
data_tests:
- expect_value:
field: tablename
value: duped_alias
"""
MODELS_DUPE_CUSTOM_DATABASE__MODEL_A_SQL = """
select {{ string_literal(this.name) }} as tablename
"""
MODELS_DUPE_CUSTOM_DATABASE__MODEL_B_SQL = """
select {{ string_literal(this.name) }} as tablename
"""
MODELS_DUPE_CUSTOM_DATABASE__README_MD = """
these should succeed, as both models have the same alias,
but they are configured to be built in _different_ schemas
"""
# dupe custom schema #
MODELS_DUPE_CUSTOM_SCHEMA__SCHEMA_YML = """
version: 2
models:
- name: model_a
data_tests:
- expect_value:
field: tablename
value: duped_alias
- name: model_b
data_tests:
- expect_value:
field: tablename
value: duped_alias
- name: model_c
data_tests:
- expect_value:
field: tablename
value: duped_alias
"""
MODELS_DUPE_CUSTOM_SCHEMA__MODEL_A_SQL = """
{{ config(alias='duped_alias', schema='schema_a') }}
select {{ string_literal(this.name) }} as tablename
"""
MODELS_DUPE_CUSTOM_SCHEMA__MODEL_B_SQL = """
{{ config(alias='duped_alias', schema='schema_b') }}
select {{ string_literal(this.name) }} as tablename
"""
MODELS_DUPE_CUSTOM_SCHEMA__MODEL_C_SQL = """
-- no custom schema for this model
{{ config(alias='duped_alias') }}
select {{ string_literal(this.name) }} as tablename
"""
MODELS_DUPE_CUSTOM_SCHEMA__README_MD = """
these should succeed, as both models have the same alias,
but they are configured to be built in _different_ schemas
"""