File tree Expand file tree Collapse file tree 5 files changed +85
-1
lines changed
src/dbt/include/global_project/macros/materializations/tests
dbt-postgres/tests/functional/adapter
src/dbt/tests/adapter/unit_testing Expand file tree Collapse file tree 5 files changed +85
-1
lines changed Original file line number Diff line number Diff line change 1+ kind : Fixes
2+ body : Correct column mapping lookup in unit test macro
3+ time : 2025-08-18T17:42:17.687393-05:00
4+ custom :
5+ Author : QMalcolm
6+ Issue : " 1273"
Original file line number Diff line number Diff line change 1919
2020 {%- set expected_column_names_quoted = [] - %}
2121 {%- for column_name in tested_expected_column_names - %}
22- {%- do expected_column_names_quoted .append (column_name_to_quoted[column_name]) - %}
22+ {%- do expected_column_names_quoted .append (column_name_to_quoted[column_name| lower ]) - %}
2323 {%- endfor - %}
2424
2525 {% if not expected_sql %}
Original file line number Diff line number Diff line change 11from dbt .tests .adapter .unit_testing .test_case_insensitivity import BaseUnitTestCaseInsensivity
22from dbt .tests .adapter .unit_testing .test_invalid_input import BaseUnitTestInvalidInput
3+ from dbt .tests .adapter .unit_testing .test_quoted_reserved_word_column_names import (
4+ BaseUnitTestQuotedReservedWordColumnNames ,
5+ )
36from dbt .tests .adapter .unit_testing .test_types import BaseUnitTestingTypes
47
58
@@ -13,3 +16,7 @@ class TestPostgresUnitTestInvalidInput(BaseUnitTestInvalidInput):
1316
1417class TestPostgresUnitTestingTypes (BaseUnitTestingTypes ):
1518 pass
19+
20+
21+ class TestPostgresUnitTestQuotedReservedWordColumnNames (BaseUnitTestQuotedReservedWordColumnNames ):
22+ pass
Original file line number Diff line number Diff line change 1+ kind : Features
2+ body : Add new test for test unit tests involing models with columns with reserved
3+ words
4+ time : 2025-08-18T18:19:37.508909-05:00
5+ custom :
6+ Author : QMalcolm
7+ Issue : " 1273"
Original file line number Diff line number Diff line change 1+ import pytest
2+ from dbt .tests .util import run_dbt
3+
4+
5+ my_model_sql = """
6+ select
7+ * from {{ ref('my_upstream_model')}}
8+ """
9+
10+ my_upstream_model_with_reserved_word_column_name_sql = """
11+ select 1 as "GROUP"
12+ """
13+
14+ test_my_model_csv_fixtures_yml = """
15+ unit_tests:
16+ - name: test_my_model
17+ model: my_model
18+ given:
19+ - input: ref('my_upstream_model')
20+ format: csv
21+ fixture: input_fixture
22+ expect:
23+ format: csv
24+ fixture: expect_fixture
25+ """
26+
27+ input_fixture_csv = """
28+ GROUP
29+ 1
30+ 2
31+ 3
32+ """
33+
34+ expect_fixture_csv = """
35+ GROUP
36+ 1
37+ 2
38+ 3
39+ """
40+
41+
42+ class BaseUnitTestQuotedReservedWordColumnNames :
43+ @pytest .fixture (scope = "class" )
44+ def models (self ):
45+ return {
46+ "my_model.sql" : my_model_sql ,
47+ "my_upstream_model.sql" : my_upstream_model_with_reserved_word_column_name_sql ,
48+ "unit_tests.yml" : test_my_model_csv_fixtures_yml ,
49+ }
50+
51+ @pytest .fixture (scope = "class" )
52+ def tests (self ):
53+ return {
54+ "fixtures" : {
55+ "input_fixture.csv" : input_fixture_csv ,
56+ "expect_fixture.csv" : expect_fixture_csv ,
57+ },
58+ }
59+
60+ def test_quoted_reserved_word_column_names (self , project ):
61+ results = run_dbt (["run" ])
62+ assert len (results ) == 2
63+
64+ results = run_dbt (["test" ])
You can’t perform that action at this time.
0 commit comments