1
|
|
|
"""Test munging filters.""" |
2
|
|
|
|
3
|
|
|
from flask_extras.filters import munging |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class TestFilterVals: |
7
|
|
|
"""All tests for filter_vals function.""" |
8
|
|
|
|
9
|
|
|
def test_title_returns_invalid_first(self): |
10
|
|
|
"""Test function.""" |
11
|
|
|
assert munging.filter_vals({}, None) == {} |
12
|
|
|
|
13
|
|
|
def test_title_returns_invalid_second(self): |
14
|
|
|
"""Test function.""" |
15
|
|
|
assert munging.filter_vals(None, []) is None |
16
|
|
|
|
17
|
|
|
def test_title_returns_invalid_both(self): |
18
|
|
|
"""Test function.""" |
19
|
|
|
assert munging.filter_vals(None, None) is None |
20
|
|
|
|
21
|
|
|
def test_title_returns_valid_empty(self): |
22
|
|
|
"""Test function.""" |
23
|
|
|
assert munging.filter_vals(dict(), []) == {} |
24
|
|
|
|
25
|
|
|
def test_title_returns_valid_filtered_empty(self): |
26
|
|
|
"""Test function.""" |
27
|
|
|
assert munging.filter_vals(dict(foo='bar'), ['bar']) == {} |
28
|
|
|
|
29
|
|
|
def test_title_returns_valid_filtered(self): |
30
|
|
|
"""Test function.""" |
31
|
|
|
assert munging.filter_vals( |
32
|
|
|
dict(foo='bar', bar='foo'), ['bar']) == dict(bar='foo') |
33
|
|
|
|
34
|
|
|
def test_title_returns_valid_filtered_invalid_val(self): |
35
|
|
|
"""Test function.""" |
36
|
|
|
d = dict(foo='bar', bar='foo') |
37
|
|
|
assert munging.filter_vals(d, ['baz']) == d |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
class TestFilterKeys: |
41
|
|
|
"""All tests for filter_keys function.""" |
42
|
|
|
|
43
|
|
|
def test_title_returns_invalid_first(self): |
44
|
|
|
"""Test function.""" |
45
|
|
|
assert munging.filter_keys({}, None) == {} |
46
|
|
|
|
47
|
|
|
def test_title_returns_invalid_second(self): |
48
|
|
|
"""Test function.""" |
49
|
|
|
assert munging.filter_keys(None, []) is None |
50
|
|
|
|
51
|
|
|
def test_title_returns_invalid_both(self): |
52
|
|
|
"""Test function.""" |
53
|
|
|
assert munging.filter_keys(None, None) is None |
54
|
|
|
|
55
|
|
|
def test_title_returns_valid_empty(self): |
56
|
|
|
"""Test function.""" |
57
|
|
|
assert munging.filter_keys(dict(), []) == {} |
58
|
|
|
|
59
|
|
|
def test_title_returns_valid_filtered_empty(self): |
60
|
|
|
"""Test function.""" |
61
|
|
|
assert munging.filter_keys(dict(foo='bar'), ['foo']) == {} |
62
|
|
|
|
63
|
|
|
def test_title_returns_valid_filtered(self): |
64
|
|
|
"""Test function.""" |
65
|
|
|
assert munging.filter_keys( |
66
|
|
|
dict(foo='bar', bar='foo'), ['bar']) == dict(foo='bar') |
67
|
|
|
|
68
|
|
|
def test_title_returns_valid_filtered_invalid_val(self): |
69
|
|
|
"""Test function.""" |
70
|
|
|
d = dict(foo='bar', bar='foo') |
71
|
|
|
assert munging.filter_keys(d, ['baz']) == d |
72
|
|
|
|