-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
57 lines (46 loc) · 1.07 KB
/
test.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
# coding: utf8
from __future__ import print_function
from azzert import azzert, ensure, mock, C, D, E
schema = {
'id': (int, r'^\d+$', E(456)),
'name': (str, E('jerry')),
'age': (D(18), E(28)),
'contact': {
'type': {'mobile', 'email'},
'value': ((True, str, lambda v: 0 < len(v) < 100), E('10020003000')),
},
'hobbies': ([(True, str, C(lambda s: s.lower()))], None, E(['Running', 'chess'])),
}
data = {
'id': '123',
'name': 'tom',
'contact': {
'type': 'mobile',
'value': '10010001000',
},
'hobbies': ['Swimming', 'movie'],
}
result = azzert(data, schema)
assert result is True
result = ensure(data, schema)
assert result == {
'id': '123',
'name': 'tom',
'age': 18,
'contact': {
'type': 'mobile',
'value': '10010001000'
},
'hobbies': ['swimming', 'movie']
}
result = mock(schema)
assert result == {
'id': 456,
'name': 'jerry',
'age': 18,
'contact': {
'type': 'mobile',
'value': '10020003000'
},
'hobbies': ['running', 'chess']
}