forked from leancloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_op.py
More file actions
68 lines (48 loc) · 1.86 KB
/
Copy pathtest_op.py
File metadata and controls
68 lines (48 loc) · 1.86 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
# coding: utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from nose.tools import assert_equal
import leancloud
from leancloud import Object
from leancloud import operation # type:ignore
__author__ = 'asaka <lan@leancloud.rocks>'
def test_set(): # type: () -> None
s = operation.Set(10)
assert s.value == 10
def test_unset(): # type: () -> None
s = operation.Unset()
assert s._apply(operation.Set(10)) == operation._UNSET
def test_increment(): # type: () -> None
s = operation.Increment(1)
assert s.amount == 1
previous = operation.Increment(2)
new = s._merge(previous)
assert isinstance(new, operation.Increment)
assert new.amount == 3
def test_apply_relation_op(): # type: () -> None
album = leancloud.Object.create("Album",
objectId="abc001",
title="variety")
band1 = leancloud.Object.create("Band",
objectId="abc101",
name="xxx")
band2 = leancloud.Object.create("Band",
objectId="abc102",
name="ooo")
relation = album.relation("band")
op = operation.Relation([band1], [band2])
val = op._apply(None, album, "band")
assert isinstance(val, leancloud.Relation)
val._ensure_parent_and_key(album, "band")
val = op._apply(relation)
assert isinstance(val, leancloud.Relation)
val._ensure_parent_and_key(album, "band")
def test_bit_op(): # type: () -> None
unset = operation.Unset()
add_ = operation.BitAnd(123)
assert_equal(add_._merge(unset).value, 0)
or_ = operation.BitOr(321)
assert_equal(or_._merge(unset).value, 321)
xor = operation.BitOr(321)
assert_equal(xor._merge(unset).value, 321)