forked from noirbizarre/flask-restplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
91 lines (81 loc) · 2.39 KB
/
test_utils.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
86
87
88
89
90
91
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
try:
import unittest2 as unittest
except ImportError:
import unittest
from flask.ext.restplus import utils
class MergeTestCase(unittest.TestCase):
def test_merge_simple_dicts_without_precedence(self):
a = {'a': 'value'}
b = {'b': 'other value'}
self.assertEqual(utils.merge(a, b), {'a': 'value', 'b': 'other value'})
def test_merge_simple_dicts_with_precedence(self):
a = {'a': 'value', 'ab': 'overwritten'}
b = {'b': 'other value', 'ab': 'keep'}
self.assertEqual(utils.merge(a, b), {'a': 'value', 'b': 'other value', 'ab': 'keep'})
def test_recursions(self):
a = {
'a': 'value',
'ab': 'overwritten',
'nested_a': {
'a': 'nested'
},
'nested_a_b': {
'a': 'a only',
'ab': 'overwritten'
}
}
b = {
'b': 'other value',
'ab': 'keep',
'nested_b': {
'b': 'nested'
},
'nested_a_b': {
'b': 'b only',
'ab': 'keep'
}
}
self.assertEqual(utils.merge(a, b), {
'a': 'value',
'b': 'other value',
'ab': 'keep',
'nested_a': {
'a': 'nested'
},
'nested_b': {
'b': 'nested'
},
'nested_a_b': {
'a': 'a only',
'b': 'b only',
'ab': 'keep'
}
})
def test_recursions_with_empty(self):
a = {}
b = {
'b': 'other value',
'ab': 'keep',
'nested_b': {
'b': 'nested'
},
'nested_a_b': {
'b': 'b only',
'ab': 'keep'
}
}
self.assertEqual(utils.merge(a, b), b)
class CamelToDashTestCase(unittest.TestCase):
def test_no_transform(self):
self.assertEqual(utils.camel_to_dash('test'), 'test')
def test_transform(self):
tests = {
'aValue': 'a_value',
'aLongValue': 'a_long_value',
'Upper': 'upper',
'UpperCase': 'upper_case',
}
for value, expected in tests.items():
self.assertEqual(utils.camel_to_dash(value), expected)