Skip to content

Commit

Permalink
[#1117] Move some helpers into shared test helper data module
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Jul 26, 2013
1 parent f3d0de6 commit f234745
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
16 changes: 16 additions & 0 deletions ckan/new_tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,19 @@ def typical_user():
'email': 'fred@fred.com',
'password': 'wilma',
}


def validator_data_dict():
'''Return a data dict with some arbitrary data in it, suitable to be passed
to validator functions for testing.
'''
return {('other key',): 'other value'}


def validator_errors_dict():
'''Return an errors dict with some arbitrary errors in it, suitable to be
passed to validator functions for testing.
'''
return {('other key',): ['other error']}
32 changes: 5 additions & 27 deletions ckan/new_tests/lib/navl/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,7 @@

import nose.tools


def _data():
'''Return a data dict with some arbitrary data in it, suitable to be passed
to validators for testing.
This is a function that returns a dict (rather than just a dict as a
module-level variable) so that if one test method modifies the dict the
next test method gets a new clean copy.
'''
return {('other key',): 'other value'}


def _errors():
'''Return an errors dict with some arbitrary errors in it, suitable to be
passed to validators for testing.
This is a function that returns a dict (rather than just a dict as a
module-level variable) so that if one test method modifies the dict the
next test method gets a new clean copy.
'''
return {('other key',): ['other error']}
import ckan.new_tests.data as test_data


class TestValidators(object):
Expand All @@ -50,12 +28,12 @@ def test_ignore_missing_with_value_missing(self):
key = ('key to be validated',)

# The data to pass to the validator function for validation.
data = _data()
data = test_data.validator_data_dict()
if value != 'skip':
data[key] = value

# The errors dict to pass to the validator function.
errors = _errors()
errors = test_data.validator_errors_dict()
errors[key] = []

# Make copies of the data and errors dicts for asserting later.
Expand Down Expand Up @@ -88,9 +66,9 @@ def test_ignore_missing_with_a_value(self):
import ckan.lib.navl.validators as validators

key = ('key to be validated',)
data = _data()
data = test_data.validator_data_dict()
data[key] = 'value to be validated'
errors = _errors()
errors = test_data.validator_errors_dict()
errors[key] = []

# Make copies of the data and errors dicts for asserting later.
Expand Down

0 comments on commit f234745

Please sign in to comment.