forked from leancloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_util.py
More file actions
83 lines (67 loc) · 1.72 KB
/
Copy pathtest_util.py
File metadata and controls
83 lines (67 loc) · 1.72 KB
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
# coding: utf-8
from leancloud import Object
from leancloud import ACL
from leancloud import GeoPoint
from leancloud import utils
__author__ = 'asaka <lan@leancloud.rocks>'
def test_encode():
Foo = Object.extend('Foo')
obj = Foo()
assert utils.encode(obj) == {
'className': 'Foo',
'__type': 'Pointer',
'objectId': None,
}
acl = ACL()
assert utils.encode(acl) == {}
acl.set_read_access('xxx', True)
assert utils.encode(acl) == {'xxx': {'read': True}}
point = GeoPoint()
assert utils.encode(point) == {
'__type': 'GeoPoint',
'longitude': 0,
'latitude': 0,
}
assert utils.encode([obj, acl, point]) == [
{
'className': 'Foo',
'__type': 'Pointer',
'objectId': None,
}, {
'xxx': {'read': True}
}, {
'__type': 'GeoPoint',
'longitude': 0,
'latitude': 0,
}
]
assert utils.encode({'a': obj, 'b': acl}) == {
'a': {
'className': 'Foo',
'__type': 'Pointer',
'objectId': None,
},
'b': {
'xxx': {'read': True}
},
}
def test_decode():
p = utils.decode('test_key', {
'__type': 'GeoPoint',
'longitude': 0,
'latitude': 0,
})
assert isinstance(p, GeoPoint)
assert p.latitude == 0
assert p.longitude == 0
def test_util():
obj = Object.extend('Foo')()
def callback(o):
callback.count += 1
if callback.count == 1:
assert o == {}
elif callback.count == 2:
assert o == obj
callback.count = 0
utils.traverse_object(obj, callback)
assert callback.count == 2