-
Notifications
You must be signed in to change notification settings - Fork 2k
/
test_validators.py
85 lines (62 loc) · 2.4 KB
/
test_validators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'''Unit tests for ckan/lib/navl/validators.py.
'''
import nose.tools
class TestValidators(object):
def test_ignore_missing_with_None(self):
'''If data[key] is None ignore_missing() should raise StopOnError.'''
import ckan.lib.navl.dictization_functions as df
import ckan.lib.navl.validators as validators
key = ('foo',)
data = {key: None}
errors = {key: []}
with nose.tools.assert_raises(df.StopOnError):
validators.ignore_missing(
key=key,
data=data,
errors=errors,
context={})
# ignore_missing should remove the item from the dict.
assert key not in data
def test_ignore_missing_with_missing(self):
'''If data[key] is missing ignore_missing() should raise StopOnError.
'''
import ckan.lib.navl.dictization_functions as df
import ckan.lib.navl.validators as validators
key = ('foo',)
data = {key: df.missing}
errors = {key: []}
with nose.tools.assert_raises(df.StopOnError):
validators.ignore_missing(
key=key,
data=data,
errors=errors,
context={})
# ignore_missing should remove the item from the dict.
assert key not in data
def test_ignore_missing_without_key(self):
'''If key is not in data ignore_missing() should raise StopOnError.'''
import ckan.lib.navl.dictization_functions as df
import ckan.lib.navl.validators as validators
key = ('foo',)
data = {}
errors = {key: []}
with nose.tools.assert_raises(df.StopOnError):
validators.ignore_missing(
key=key,
data=data,
errors=errors,
context={})
# ignore_missing should remove the item from the dict.
assert key not in data
def test_ignore_missing_with_a_value(self):
'''If data[key] is neither None or missing, ignore_missing() should do
nothing.
'''
import ckan.lib.navl.validators as validators
key = ('foo',)
data = {key: 'bar'}
errors = {key: []}
result = validators.ignore_missing(key=key, data=data, errors=errors,
context={})
assert result is None
assert data.get(key) == 'bar'