Skip to content

Commit

Permalink
[backport #4070] fixed error_id typo
Browse files Browse the repository at this point in the history
* fixed error_id typo and added tests

* added changelog entry
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
emmyoop committed Oct 15, 2021
1 parent 162f3a1 commit 1fdfc7a
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixes
- Performance: Use child_map to find tests for nodes in resolve_graph ([#4012](https://github.com/dbt-labs/dbt/issues/4012), [#4057](https://github.com/dbt-labs/dbt/pull/4057))
- Fix multiple partial parsing errors ([#3996](https://github.com/dbt-labs/dbt/issues/3006), [#4020](https://github.com/dbt-labs/dbt/pull/4018))
- Fixed bug with `error_if` test option ([#4070](https://github.com/dbt-labs/dbt-core/pull/4070))


## dbt 0.21.0 (October 04, 2021)
Expand Down
4 changes: 1 addition & 3 deletions core/dbt/parser/schema_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def get_static_config(self):
if self.warn_if is not None:
config['warn_if'] = self.warn_if
if self.error_if is not None:
config['error_id'] = self.error_if
config['error_if'] = self.error_if
if self.fail_calc is not None:
config['fail_calc'] = self.fail_calc
if self.store_failures is not None:
Expand All @@ -369,8 +369,6 @@ def get_static_config(self):
config['database'] = self.database
if self.schema is not None:
config['schema'] = self.schema
if self.alias is not None:
config['alias'] = self.alias
return config

def tags(self) -> List[str]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 2

models:
- name: table_limit_null
description: "The table has 1 null values, and we're okay with that, until it's more than 1."
columns:
- name: favorite_color_full_list
description: "The favorite color"
- name: count
description: "The number of responses for this favorite color - purple will be null"
tests:
- not_null:
error_if: '>1'
warn_if: '>1'

- name: table_warning_limit_null
description: "The table has 1 null value, and we're okay with 1, but want to know of any."
columns:
- name: favorite_color_full_list
description: "The favorite color"
- name: count
description: "The number of responses for this favorite color - purple will be null"
tests:
- not_null:
error_if: '>1'

- name: table_failure_limit_null
description: "The table has some 2 null values, and that's not ok. Warn and error."
columns:
- name: favorite_color_full_list
description: "The favorite color"
- name: count
description: "The number of responses for this favorite color - purple will be null"
tests:
- not_null:
error_if: '>1'

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{
config(
materialized='table'
)
}}

select * from {{ref('table_limit_null')}}

UNION ALL

select 'magenta' as favorite_color_full_list, null as count
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized='table'
)
}}

select favorite_color as favorite_color_full_list, count(*) as count
from {{ this.schema }}.seed
group by 1

UNION ALL

select 'purple' as favorite_color_full_list, null as count
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{
config(
materialized='table'
)
}}

select * from {{ref('table_limit_null')}}
63 changes: 63 additions & 0 deletions test/integration/008_schema_tests_test/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,69 @@ def test_postgres_schema_test_exclude_failures(self):
for result in test_results:
self.assertTestFailed(result)

class TestLimitedSchemaTests(DBTIntegrationTest):

def setUp(self):
DBTIntegrationTest.setUp(self)
self.run_sql_file("seed.sql")

@property
def schema(self):
return "schema_tests_008"

@property
def models(self):
return "models-v2/limit_null"

def run_schema_validations(self):
args = FakeArgs()
test_task = TestTask(args, self.config)
return test_task.run()

def assertTestFailed(self, result):
self.assertEqual(result.status, "fail")
self.assertFalse(result.skipped)
self.assertTrue(
result.failures > 0,
'test {} did not fail'.format(result.node.name)
)

def assertTestWarn(self, result):
self.assertEqual(result.status, "warn")
self.assertFalse(result.skipped)
self.assertTrue(
result.failures > 0,
'test {} passed without expected warning'.format(result.node.name)
)

def assertTestPassed(self, result):
self.assertEqual(result.status, "pass")
self.assertFalse(result.skipped)
self.assertEqual(
result.failures, 0,
'test {} failed'.format(result.node.name)
)

@use_profile('postgres')
def test_postgres_limit_schema_tests(self):
results = self.run_dbt()
self.assertEqual(len(results), 3)
test_results = self.run_schema_validations()
self.assertEqual(len(test_results), 3)

for result in test_results:
# assert that all deliberately failing tests actually fail
if 'failure' in result.node.name:
self.assertTestFailed(result)
# assert that tests with warnings have them
elif 'warning' in result.node.name:
self.assertTestWarn(result)
# assert that actual tests pass
else:
self.assertTestPassed(result)
# warnings are also marked as failures
self.assertEqual(sum(x.failures for x in test_results), 3)


class TestMalformedSchemaTests(DBTIntegrationTest):

Expand Down

0 comments on commit 1fdfc7a

Please sign in to comment.