Skip to content

Commit

Permalink
refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin committed Jan 2, 2024
1 parent 8dacdf5 commit 110fd99
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dbt_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
- name: load test data
run: dbt seed --target duckdb

- name: Generate tests
- name: Create seed tests
run: dbt compile -q --inline "{{ testgen.get_test_suggestions(ref('users'), resource_type='seeds') }}" > seeds/users_test_suggestions.yml

- name: Generate tests
- name: Create seed tests
run: "dbt compile -q --inline \"{{ testgen.get_test_suggestions(ref('colnames_with_spaces'), resource_type='seeds', column_config={'quote': true}) }}\" > seeds/colnames_with_spaces_test_suggestions.yml"

- name: dbt test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


{% set actual_yaml = toyaml(fromjson(tojson(
{% set actual_yaml = testgen.to_yaml(
testgen.get_accepted_values_test_suggestions(
ref('colnames_with_spaces')
)
)))
)
%}

{% set expected_yaml %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


{% set actual_yaml = toyaml(fromjson(tojson(
{% set actual_yaml = testgen.to_yaml(
testgen.get_accepted_values_test_suggestions(
ref('users')
)
)))
)
%}

{% set expected_yaml %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


{% set actual_yaml = toyaml(fromjson(tojson(
{% set actual_yaml = testgen.to_yaml(
testgen.get_range_test_suggestions(
ref('colnames_with_spaces')
)
)))
)
%}

{% set expected_yaml %}
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/tests/generate_range_tests/range_users.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


{% set actual_yaml = toyaml(fromjson(tojson(
{% set actual_yaml = testgen.to_yaml(
testgen.get_range_test_suggestions(
ref('users')
)
)))
)
%}

{% set expected_yaml %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@


{% set actual_yaml = toyaml(fromjson(tojson(
{% set actual_yaml = testgen.to_yaml(
testgen.get_uniqueness_test_suggestions(
ref('colnames_with_spaces'),
composite_key_length = 1
composite_key_length = 1,
column_config={'quote': true}
)
)))
)
%}

{% set expected_yaml %}
Expand All @@ -17,16 +18,19 @@ models:
tests:
- unique
- not_null
quote: true
- name: Age (Years)
description: Uniqueness test generated by dbt-testgen
tests:
- unique
- not_null
quote: true
- name: Current City
description: Uniqueness test generated by dbt-testgen
tests:
- unique
- not_null
quote: true
{% endset %}

{{ assert_equal (actual_yaml | trim, expected_yaml | trim) }}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


{% set actual_yaml = toyaml(fromjson(tojson(
{% set actual_yaml = testgen.to_yaml(
testgen.get_uniqueness_test_suggestions(
ref('users'),
composite_key_length = 1
)
)))
)
%}

{% set expected_yaml %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ models:
- name: users
columns:
- name: user_id
description: Uniqueness test generated by dbt-testgen
tests:
- unique:
tags:
Expand All @@ -52,6 +53,7 @@ models:
tags:
- uniqueness
- name: email
description: Uniqueness test generated by dbt-testgen
tests:
- unique:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ models:
- name: users
columns:
- name: user_id
description: Uniqueness test generated by dbt-testgen
tests:
- unique:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,32 @@ models:
- name: users
columns:
- name: user_id
description: Numeric range test generated by dbt-testgen
tests:
- unique
- not_null
- dbt_utils.accepted_range:
min_value: 1
max_value: 30
- name: username
description: Uniqueness test generated by dbt-testgen
tests:
- unique
- not_null
- name: email
description: Uniqueness test generated by dbt-testgen
tests:
- unique
- not_null
- name: user_status
description: Accepted values test generated by dbt-testgen
tests:
- accepted_values:
values:
- active
- inactive
- name: age
description: Numeric range test generated by dbt-testgen
tests:
- dbt_utils.accepted_range:
min_value: 22
Expand Down

0 comments on commit 110fd99

Please sign in to comment.