Skip to content

Commit

Permalink
Merge pull request #3 from kgmcquate/main
Browse files Browse the repository at this point in the history
Merging changes for v0.2.0
  • Loading branch information
kgmcquate authored Dec 31, 2023
2 parents d249bdd + c247026 commit 9760299
Show file tree
Hide file tree
Showing 19 changed files with 479 additions and 100 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/dbt_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
test-duckdb:
name: Test on DuckDB
runs-on: ubuntu-latest
environment: production
#environment: production
container:
image: python:3.11

Expand All @@ -27,18 +27,18 @@ jobs:
run: pip install dbt-core duckdb dbt-duckdb

- name: Install DBT deps
run: dbt deps --target duckdb
run: dbt deps --target duckdb

- name: load test data
run: dbt seed --target duckdb
run: dbt seed --target duckdb

- name: dbt test
run: dbt test --target duckdb
run: dbt test --target duckdb

test-postgres:
name: Test on Postgres
runs-on: ubuntu-latest
environment: production
#environment: production
container:
image: python:3.11

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ clean-targets:

seeds:
+schema: integration_test_data
+quote_columns: false
+quote_columns: true
5 changes: 4 additions & 1 deletion integration_tests/run_docker.sh
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
docker run -it -v ${PWD}:/run/dbt-testgen dbt-testgen-integration-test bash
docker run -it -v ${PWD}:/run/dbt-testgen dbt-testgen-integration-test bash


docker run -it -v ${PWD}:/run/dbt-testgen python:3.11 bash
4 changes: 4 additions & 0 deletions integration_tests/seeds/colnames_with_spaces.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
First Name,Age (Years),Current City
John,25,New York
Alice,30,San Francisco
Bob,22,Chicago
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


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

{% set expected_yaml %}
models:
- name: colnames_with_spaces
columns:
- name: First Name
description: Accepted values test generated by dbt-testgen
tests:
- accepted_values:
values:
- Alice
- Bob
- John
- name: Age (Years)
description: Accepted values test generated by dbt-testgen
tests:
- accepted_values:
values:
- '22'
- '25'
- '30'
- name: Current City
description: Accepted values test generated by dbt-testgen
tests:
- accepted_values:
values:
- Chicago
- New York
- San Francisco
{% endset %}

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


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

{% set expected_yaml %}
models:
- name: colnames_with_spaces
columns:
- name: Age (Years)
description: Numeric range test generated by dbt-testgen
tests:
- dbt_utils.accepted_range:
min_value: 22
max_value: 30
{% endset %}

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


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

{% set expected_yaml %}
models:
- name: users
columns:
- name: user_id
description: Uniqueness test generated by dbt-testgen
tests:
- unique
- not_null
- 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
{% endset %}

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


{% set actual_yaml = testgen.print_uniqueness_test_suggestions(
ref('users'),
compound_key_length = 1
)
%}

{% set expected_yaml %}
{% set input_yaml_1 %}
models:
- name: users
tests: []
Expand All @@ -20,7 +12,14 @@ models:
- not_null:
tags:
- uniqueness
- name: username
{% endset %}

{% set input_yaml_2 %}
models:
- name: users
tests: []
columns:
- name: email
description: Uniqueness test generated by dbt-testgen
tests:
- unique:
Expand All @@ -29,8 +28,30 @@ models:
- not_null:
tags:
- uniqueness
{% endset %}

{% set actual_yaml = toyaml(
testgen.merge_dbt_configs(
fromyaml(input_yaml_1),
fromyaml(input_yaml_2)
)
)
%}


{% set expected_yaml %}
models:
- name: users
columns:
- name: user_id
tests:
- unique:
tags:
- uniqueness
- not_null:
tags:
- uniqueness
- name: email
description: Uniqueness test generated by dbt-testgen
tests:
- unique:
tags:
Expand Down
58 changes: 58 additions & 0 deletions integration_tests/tests/merge_dbt_configs/merge_dbt_configs_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% set input_yaml_1 %}
models:
- name: users
tests: []
columns:
- name: user_id
description: Uniqueness test generated by dbt-testgen
tests:
- unique:
tags:
- uniqueness
- not_null:
tags:
- uniqueness
{% endset %}

{% set input_yaml_2 %}
models:
- name: users
tests: []
columns:
- name: user_id
description: Uniqueness test generated by dbt-testgen
tests:
- accepted_values:
values:
- active
- inactive
{% endset %}

{% set actual_yaml = toyaml(
testgen.merge_dbt_configs(
fromyaml(input_yaml_1),
fromyaml(input_yaml_2)
)
)
%}


{% set expected_yaml %}
models:
- name: users
columns:
- name: user_id
tests:
- unique:
tags:
- uniqueness
- not_null:
tags:
- uniqueness
- accepted_values:
values:
- active
- inactive
{% endset %}

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


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

{% set expected_yaml %}
models:
- name: users
columns:
- name: user_id
tests:
- unique
- not_null
- dbt_utils.accepted_range:
min_value: 1
max_value: 30
- name: username
tests:
- unique
- not_null
- name: email
tests:
- unique
- not_null
- name: user_status
tests:
- accepted_values:
values:
- active
- inactive
- name: age
tests:
- dbt_utils.accepted_range:
min_value: 22
max_value: 35
{% endset %}

{{ assert_equal (actual_yaml | trim, expected_yaml | trim) }}
Loading

0 comments on commit 9760299

Please sign in to comment.