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

Changes to support unit test sql format #146

Merged
merged 4 commits into from
Apr 11, 2024
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240409-084844.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support for sql fixtures in unit testing
time: 2024-04-09T08:48:44.441106-04:00
custom:
Author: gshank
Issue: "148"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% set relations = [] %}

{% set expected_rows = config.get('expected_rows') %}
{% set expected_sql = config.get('expected_sql') %}
{% set tested_expected_column_names = expected_rows[0].keys() if (expected_rows | length ) > 0 else get_columns_in_query(sql) %} %}

{%- set target_relation = this.incorporate(type='table') -%}
Expand All @@ -11,10 +12,13 @@
{%- set columns_in_relation = adapter.get_columns_in_relation(temp_relation) -%}
{%- set column_name_to_data_types = {} -%}
{%- for column in columns_in_relation -%}
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%}
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%}
{%- endfor -%}

{% set unit_test_sql = get_unit_test_sql(sql, get_expected_sql(expected_rows, column_name_to_data_types), tested_expected_column_names) %}
{% if not expected_sql %}
{% set expected_sql = get_expected_sql(expected_rows, column_name_to_data_types) %}
{% endif %}
{% set unit_test_sql = get_unit_test_sql(sql, expected_sql, tested_expected_column_names) %}

{% call statement('main', fetch_result=True) -%}

Expand Down
Loading