Skip to content

Commit 5f42a6e

Browse files
committed
Unit tests for Request* classes updated
1 parent 3584979 commit 5f42a6e

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

tests/tarantool/request.py

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,157 @@ def test__cast_to_bytes(self):
8989
binascii.unhexlify("110000003000000000000000010000000000000000000000ffff00000200000002000000040100000004020000000200000004030000000404000000"),
9090
"Select multiple keys using composite index"
9191
)
92+
93+
94+
class RequestUpdate(unittest.TestCase):
95+
96+
def test__cast_to_bytes(self):
97+
'''
98+
Test binary UPDATE request representation
99+
'''
100+
101+
# ------------------------------------------------------------
102+
# Update operation "ASSIGN" ('='), op_code = 0
103+
104+
# update t17 set k51 = 0x11223344 where k0 = 0x22
105+
self.assertEqual(
106+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33, '=', 0x11223344)], False)),
107+
binascii.unhexlify("130000001f0000000000000011000000000000000100000004220000000100000033000000000444332211"),
108+
"Update: assign single integer value using an integer key"
109+
)
110+
111+
# update t17 set k51 = 0x11223344 where k0 = "ZZZZZZ"
112+
self.assertEqual(
113+
bytes(tarantool.request.RequestUpdate(0x11, b"ZZZZZZ", [(0x33, '=', 0x11223344)], False)),
114+
binascii.unhexlify("130000002100000000000000110000000000000001000000065a5a5a5a5a5a0100000033000000000444332211"),
115+
"Update: assign single integer value using a string key"
116+
)
117+
118+
# update t17 set k51 = "NNN" where k0 = 0x22
119+
self.assertEqual(
120+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33, '=', b"NNN")], False)),
121+
binascii.unhexlify("130000001e000000000000001100000000000000010000000422000000010000003300000000034e4e4e"),
122+
"Update: assign single string value using an integer key"
123+
)
124+
125+
# update t17 set k51 = "NNN" where k0 = "ZZZZZZ"
126+
self.assertEqual(
127+
bytes(tarantool.request.RequestUpdate(0x11, b"ZZZZZZ", [(0x33, '=', b"NNN")], False)),
128+
binascii.unhexlify("130000002000000000000000110000000000000001000000065a5a5a5a5a5a010000003300000000034e4e4e"),
129+
"Update: assign single string value using a string key"
130+
)
131+
132+
# update t17 set k51 = 0x3333, k68 = 0x4444, k85 = 0x5555 where k0 = 0x22
133+
self.assertEqual(
134+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33, '=', 0x3333), (0x44, '=', 0x4444), (0x55, '=', 0x5555)], False)),
135+
binascii.unhexlify("130000003300000000000000110000000000000001000000042200000003000000330000000004333300004400000000044444000055000000000455550000"),
136+
"Update: assign multiple integer values using an integer key"
137+
)
138+
139+
# update t17 set k51 = 0x3333, k68 = 0x4444, k85 = 0x5555 where k0 = "ZZZZZZ"
140+
self.assertEqual(
141+
bytes(tarantool.request.RequestUpdate(0x11, "ZZZZZZ", [(0x33, '=', 0x3333), (0x44, '=', 0x4444), (0x55, '=', 0x5555)], False)),
142+
binascii.unhexlify("130000003500000000000000110000000000000001000000065a5a5a5a5a5a03000000330000000004333300004400000000044444000055000000000455550000"),
143+
"Update: assign multiple integer values using a string key"
144+
)
145+
146+
# update t17 set k51 = "KKK", k68 = "LLL", k85 = "MMM" where k0 = 0x22
147+
self.assertEqual(
148+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33,'=', b"KKK"), (0x44,'=', b"LLL"), (0x55,'=', b"MMM")], False)),
149+
binascii.unhexlify("1300000030000000000000001100000000000000010000000422000000030000003300000000034b4b4b4400000000034c4c4c5500000000034d4d4d"),
150+
"Update: assign multiple string values using an integer key"
151+
)
152+
153+
# update t17 set k51 = "KKK", k68 = "LLL", k85 = "MMM" where k0 = "ZZZZZZ"
154+
self.assertEqual(
155+
bytes(tarantool.request.RequestUpdate(0x11, b"ZZZZZZ", [(0x33,'=', b"KKK"), (0x44,'=', b"LLL"), (0x55,'=', b"MMM")], False)),
156+
binascii.unhexlify("130000003200000000000000110000000000000001000000065a5a5a5a5a5a030000003300000000034b4b4b4400000000034c4c4c5500000000034d4d4d"),
157+
"Update: assign multiple string values using a string key"
158+
)
159+
160+
# ------------------------------------------------------------
161+
# Update operation "ADD" ('+'), op_code = 1
162+
163+
# update t17 set k51 = k51 + 0x55 where k0 = 0x22
164+
self.assertEqual(
165+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33, '+', 0x55)], False)),
166+
binascii.unhexlify("130000001f00000000000000"
167+
+"11000000" # space_no
168+
+"00000000" # flags
169+
+"01000000" # key cardinality
170+
+ "0422000000" # key value
171+
+"01000000" # count (number of operations)
172+
# --- operation triplets ---
173+
+ "33000000" # field_no = 0x33
174+
+ "01" # op_code = add ('+')
175+
+ "0455000000" # field = 0x55
176+
),
177+
#
178+
"Update: ADD single integer value using an integer key"
179+
)
180+
181+
# ------------------------------------------------------------
182+
# Update operation bitwise "AND" ('&'), op_code = 2
183+
184+
# update t17 set k51 = k51 & 0x55 where k0 = 0x22
185+
self.assertEqual(
186+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33, '&', 0x55)], False)),
187+
binascii.unhexlify("130000001f00000000000000" # 12 byte header
188+
+ "11000000" # space_no
189+
+ "00000000" # flags
190+
+ "01000000" # key cardinality
191+
+ "04220000000" # key value
192+
+ "1000000" # count (number of operations)
193+
# --- operation triplets ---
194+
+ "33000000" # field_no = 0x33
195+
+ "02" # op_code = AND ('&')
196+
+ "0455000000" # field = 0x55
197+
),
198+
#
199+
"Update: ADD single integer value using an integer key"
200+
)
201+
202+
203+
# ------------------------------------------------------------
204+
# Update operation bitwise "XOR" ('^'), op_code = 3
205+
206+
# update t17 set k51 = k51 | 0x55 where k0 = 0x22
207+
self.assertEqual(
208+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33, '^', 0x55)], False)),
209+
binascii.unhexlify("130000001f00000000000000" # 12 byte header
210+
+ "11000000" # space_no
211+
+ "00000000" # flags
212+
+ "01000000" # key cardinality
213+
+ "04220000000" # key value
214+
+ "1000000" # count (number of operations)
215+
# --- operation triplets ---
216+
+ "33000000" # field_no = 0x33
217+
+ "03" # op_code = XOR ('^')
218+
+ "0455000000" # field = 0x55
219+
),
220+
#
221+
"Update: OR single integer value using an integer key"
222+
)
223+
224+
225+
# ------------------------------------------------------------
226+
# Update operation bitwise "OR" ('|'), op_code = 4
227+
228+
# update t17 set k51 = k51 | 0x55 where k0 = 0x22
229+
self.assertEqual(
230+
bytes(tarantool.request.RequestUpdate(0x11, 0x22, [(0x33, '|', 0x55)], False)),
231+
binascii.unhexlify("130000001f00000000000000" # 12 byte header
232+
+ "11000000" # space_no
233+
+ "00000000" # flags
234+
+ "01000000" # key cardinality
235+
+ "04220000000" # key value
236+
+ "1000000" # count (number of operations)
237+
# --- operation triplets ---
238+
+ "33000000" # field_no = 0x33
239+
+ "04" # op_code = OR ('|')
240+
+ "0455000000" # field = 0x55
241+
),
242+
#
243+
"Update: OR single integer value using an integer key"
244+
)
245+

0 commit comments

Comments
 (0)