From 82c83b7b50c7c1289e72ad5d1a4ec9cd392248c3 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 8 Feb 2024 19:42:47 -0500 Subject: [PATCH] refactor get_fixture_sql --- .../macros/unit_test_sql/get_fixture_sql.sql | 10 +++++----- .../adapter/unit_testing/test_case_insensitivity.py | 1 - dbt/tests/adapter/unit_testing/test_invalid_input.py | 1 - dbt/tests/adapter/unit_testing/test_types.py | 1 - 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql b/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql index 385fd73fc..ce6095798 100644 --- a/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql +++ b/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql @@ -77,15 +77,15 @@ union all {%- set column_type = column_name_to_data_types[column_name] %} - {#-- wrap yaml strings in quotes, apply cast --#} + {#-- sanitize column_value: wrap yaml strings in quotes, apply cast --#} + {%- set column_value_clean = column_value -%} {%- if column_value is string -%} - {%- set row_update = {column_name: safe_cast(dbt.string_literal(dbt.escape_single_quotes(column_value)), column_type) } -%} + {%- set column_value_clean = dbt.string_literal(dbt.escape_single_quotes(column_value) } -%} {%- elif column_value is none -%} - {%- set row_update = {column_name: safe_cast('null', column_type) } -%} - {%- else -%} - {%- set row_update = {column_name: safe_cast(column_value, column_type) } -%} + {%- set column_value_clean = 'null' } -%} {%- endif -%} + {%- set row_update = {column_name: safe_cast(column_value_clean, column_type) } -%} {%- do formatted_row.update(row_update) -%} {%- endfor -%} {{ return(formatted_row) }} diff --git a/dbt/tests/adapter/unit_testing/test_case_insensitivity.py b/dbt/tests/adapter/unit_testing/test_case_insensitivity.py index 84a87c5cb..f6f897664 100644 --- a/dbt/tests/adapter/unit_testing/test_case_insensitivity.py +++ b/dbt/tests/adapter/unit_testing/test_case_insensitivity.py @@ -1,6 +1,5 @@ import pytest from dbt.tests.util import run_dbt -from dbt.tests.fixtures.project import * my_model_sql = """ diff --git a/dbt/tests/adapter/unit_testing/test_invalid_input.py b/dbt/tests/adapter/unit_testing/test_invalid_input.py index a4d5aa6e9..6c41ceb93 100644 --- a/dbt/tests/adapter/unit_testing/test_invalid_input.py +++ b/dbt/tests/adapter/unit_testing/test_invalid_input.py @@ -1,6 +1,5 @@ import pytest from dbt.tests.util import run_dbt, run_dbt_and_capture -from dbt.tests.fixtures.project import * my_model_sql = """ diff --git a/dbt/tests/adapter/unit_testing/test_types.py b/dbt/tests/adapter/unit_testing/test_types.py index 5dc9838cf..1d19aafb2 100644 --- a/dbt/tests/adapter/unit_testing/test_types.py +++ b/dbt/tests/adapter/unit_testing/test_types.py @@ -1,7 +1,6 @@ import pytest from dbt.tests.util import write_file, run_dbt -from dbt.tests.fixtures.project import * my_model_sql = """ select