Skip to content

Commit

Permalink
Merge pull request #1876 from clausherther/add/quote-accepted-values
Browse files Browse the repository at this point in the history
Adds "quote" parameter to "accepted_values" test
  • Loading branch information
drewbanin authored Nov 1, 2019
2 parents 8239f9c + 239e673 commit e022e73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% macro test_accepted_values(model, values) %}

{% set column_name = kwargs.get('column_name', kwargs.get('field')) %}
{% set quote_values = kwargs.get('quote', True) %}

with all_values as (

Expand All @@ -20,9 +21,12 @@ validation_errors as (
from all_values
where value_field not in (
{% for value in values -%}

'{{ value }}' {% if not loop.last -%} , {%- endif %}

{% if quote_values -%}
'{{ value }}'
{%- else -%}
{{ value }}
{%- endif -%}
{%- if not loop.last -%},{%- endif %}
{%- endfor %}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ models:
- name: favorite_color
description: "The user's favorite color"
tests:
- accepted_values: { values: ['blue', 'green'] }
- accepted_values: { values: ['blue', 'green'], quote: true }
- name: fav_number
description: "The user's favorite number"
tests:
- accepted_values:
values: [3.14159265]
quote: false


- name: table_summary
description: "The summary table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_postgres_schema_tests(self):
results = self.run_dbt()
self.assertEqual(len(results), 5)
test_results = self.run_schema_validations()
# If the disabled model's tests ran, there would be 19 of these.
self.assertEqual(len(test_results), 18)
# If the disabled model's tests ran, there would be 20 of these.
self.assertEqual(len(test_results), 19)

for result in test_results:
# assert that all deliberately failing tests actually fail
Expand Down

0 comments on commit e022e73

Please sign in to comment.