9
9
10
10
11
11
import tarantool .request
12
+ from tarantool .schema import Schema
13
+
14
+
15
+ class ConnectionMock (object ):
16
+ def __init__ (self , default_type ):
17
+ self .schema = Schema ({
18
+ 1 : {
19
+ 'name' : 'users' ,
20
+ 'default_type' : default_type ,
21
+ 'fields' : {
22
+ 0 : ('f1' , default_type ),
23
+ 1 : ('f2' , default_type ),
24
+ 2 : ('f3' , default_type ),
25
+ },
26
+ 'indexes' : {
27
+ 0 : ('pk' , [0 , 0 ]),
28
+ },
29
+ }
30
+ })
12
31
13
32
14
33
class RequestInsert (unittest .TestCase ):
34
+ def setUp (self ):
35
+ self .conn1 = ConnectionMock (tarantool .NUM )
36
+ self .conn2 = ConnectionMock (tarantool .STR )
15
37
16
38
def test__cast_to_bytes (self ):
17
39
'''
18
40
Test binary INSERT request representation
19
41
'''
20
42
self .assertEqual (
21
- bytes (tarantool .request .RequestInsert (1 , (1 , 2000 , 30000 ), False )),
43
+ bytes (tarantool .request .RequestInsert (self . conn1 , 1 , (1 , 2000 , 30000 ), False )),
22
44
binascii .unhexlify ("0d0000001b00000000000000010000000000000003000000040100000004d00700000430750000" )
23
45
)
24
46
25
47
self .assertEqual (
26
- bytes (tarantool .request .RequestInsert (1 , (b"AAA" , b"BBBB" , b"CCCCCC" ), False )),
48
+ bytes (tarantool .request .RequestInsert (self . conn2 , 1 , (b"AAA" , b"BBBB" , b"CCCCCC" ), False )),
27
49
binascii .unhexlify ("0d0000001c0000000000000001000000000000000300000003414141044242424206434343434343" )
28
50
)
29
51
30
52
31
53
class RequestDelete (unittest .TestCase ):
54
+ def setUp (self ):
55
+ self .conn1 = ConnectionMock (tarantool .NUM )
56
+ self .conn2 = ConnectionMock (tarantool .STR )
32
57
33
58
def test__cast_to_bytes (self ):
34
59
'''
35
60
Test binary DELETE request representation
36
61
'''
37
62
self .assertEqual (
38
- bytes (tarantool .request .RequestDelete (1 , 1 , False )),
63
+ bytes (tarantool .request .RequestDelete (self . conn1 , 1 , 1 , False )),
39
64
binascii .unhexlify ("1500000011000000000000000100000000000000010000000401000000" )
40
65
)
41
66
42
67
self .assertEqual (
43
- bytes (tarantool .request .RequestDelete (1 , b"AAA" , False )),
68
+ bytes (tarantool .request .RequestDelete (self . conn2 , 1 , b"AAA" , False )),
44
69
binascii .unhexlify ("15000000100000000000000001000000000000000100000003414141" )
45
70
)
46
71
@@ -50,48 +75,53 @@ def test__cast_to_bytes(self):
50
75
51
76
52
77
class RequestSelect (unittest .TestCase ):
78
+ def setUp (self ):
79
+ self .conn1 = ConnectionMock (tarantool .NUM )
80
+ self .conn2 = ConnectionMock (tarantool .STR )
53
81
54
82
def test__cast_to_bytes (self ):
55
83
'''
56
84
Test binary SELECT request representation
57
85
'''
58
86
# select * from t1 where k0 = 1
59
87
self .assertEqual (
60
- bytes (tarantool .request .RequestSelect (1 , 0 , [(1 ,)], 0 , 0xffff )),
88
+ bytes (tarantool .request .RequestSelect (self . conn1 , 1 , 0 , [(1 ,)], 0 , 0xffff )),
61
89
binascii .unhexlify ("110000001d00000000000000010000000000000000000000ffff000001000000010000000401000000" ),
62
90
"Select using integer key"
63
91
)
64
92
65
93
# select * from t1 where k0 = "AAA"
66
94
self .assertEqual (
67
- bytes (tarantool .request .RequestSelect (1 , 0 , [(b"AAA" ,)], 0 , 0xffff )),
95
+ bytes (tarantool .request .RequestSelect (self . conn2 , 1 , 0 , [(b"AAA" ,)], 0 , 0xffff )),
68
96
binascii .unhexlify ("110000001c00000000000000010000000000000000000000ffff0000010000000100000003414141" ),
69
97
"Select using string key"
70
98
)
71
99
72
100
# select * from t1 where k0 in (1, 2, 3)
73
101
self .assertEqual (
74
- bytes (tarantool .request .RequestSelect (1 , 0 , [(1 ,), (2 ,), (3 ,)], 0 , 0xffff )),
102
+ bytes (tarantool .request .RequestSelect (self . conn1 , 1 , 0 , [(1 ,), (2 ,), (3 ,)], 0 , 0xffff )),
75
103
binascii .unhexlify ("110000002f00000000000000010000000000000000000000ffff000003000000010000000401000000010000000402000000010000000403000000" ),
76
104
"Select multiple keys"
77
105
)
78
106
79
107
# select * from t1 where k0 = (1, 2)
80
108
self .assertEqual (
81
- bytes (tarantool .request .RequestSelect (1 , 0 , [(1 , 2 )], 0 , 0xffff )),
109
+ bytes (tarantool .request .RequestSelect (self . conn1 , 1 , 0 , [(1 , 2 )], 0 , 0xffff )),
82
110
binascii .unhexlify ("110000002200000000000000010000000000000000000000ffff0000010000000200000004010000000402000000" ),
83
111
"Select using composite index"
84
112
)
85
113
86
114
# select * from t1 where k0 = (1, 2) or k0 = (3, 4)
87
115
self .assertEqual (
88
- bytes (tarantool .request .RequestSelect (1 , 0 , [(1 , 2 ), (3 , 4 )], 0 , 0xffff )),
116
+ bytes (tarantool .request .RequestSelect (self . conn1 , 1 , 0 , [(1 , 2 ), (3 , 4 )], 0 , 0xffff )),
89
117
binascii .unhexlify ("110000003000000000000000010000000000000000000000ffff00000200000002000000040100000004020000000200000004030000000404000000" ),
90
118
"Select multiple keys using composite index"
91
119
)
92
120
93
121
94
122
class RequestUpdate (unittest .TestCase ):
123
+ def setUp (self ):
124
+ self .conn = ConnectionMock (tarantool .NUM )
95
125
96
126
def test__cast_to_bytes (self ):
97
127
'''
@@ -103,56 +133,56 @@ def test__cast_to_bytes(self):
103
133
104
134
# update t17 set k51 = 0x11223344 where k0 = 0x22
105
135
self .assertEqual (
106
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '=' , 0x11223344 )], False )),
136
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '=' , 0x11223344 )], False )),
107
137
binascii .unhexlify ("130000001f0000000000000011000000000000000100000004220000000100000033000000000444332211" ),
108
138
"Update: assign single integer value using an integer key"
109
139
)
110
140
111
141
# update t17 set k51 = 0x11223344 where k0 = "ZZZZZZ"
112
142
self .assertEqual (
113
- bytes (tarantool .request .RequestUpdate (0x11 , b"ZZZZZZ" , [(0x33 , '=' , 0x11223344 )], False )),
143
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , b"ZZZZZZ" , [(0x33 , '=' , 0x11223344 )], False )),
114
144
binascii .unhexlify ("130000002100000000000000110000000000000001000000065a5a5a5a5a5a0100000033000000000444332211" ),
115
145
"Update: assign single integer value using a string key"
116
146
)
117
147
118
148
# update t17 set k51 = "NNN" where k0 = 0x22
119
149
self .assertEqual (
120
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '=' , b"NNN" )], False )),
150
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '=' , b"NNN" )], False )),
121
151
binascii .unhexlify ("130000001e000000000000001100000000000000010000000422000000010000003300000000034e4e4e" ),
122
152
"Update: assign single string value using an integer key"
123
153
)
124
154
125
155
# update t17 set k51 = "NNN" where k0 = "ZZZZZZ"
126
156
self .assertEqual (
127
- bytes (tarantool .request .RequestUpdate (0x11 , b"ZZZZZZ" , [(0x33 , '=' , b"NNN" )], False )),
157
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , b"ZZZZZZ" , [(0x33 , '=' , b"NNN" )], False )),
128
158
binascii .unhexlify ("130000002000000000000000110000000000000001000000065a5a5a5a5a5a010000003300000000034e4e4e" ),
129
159
"Update: assign single string value using a string key"
130
160
)
131
161
132
162
# update t17 set k51 = 0x3333, k68 = 0x4444, k85 = 0x5555 where k0 = 0x22
133
163
self .assertEqual (
134
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '=' , 0x3333 ), (0x44 , '=' , 0x4444 ), (0x55 , '=' , 0x5555 )], False )),
164
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '=' , 0x3333 ), (0x44 , '=' , 0x4444 ), (0x55 , '=' , 0x5555 )], False )),
135
165
binascii .unhexlify ("130000003300000000000000110000000000000001000000042200000003000000330000000004333300004400000000044444000055000000000455550000" ),
136
166
"Update: assign multiple integer values using an integer key"
137
167
)
138
168
139
169
# update t17 set k51 = 0x3333, k68 = 0x4444, k85 = 0x5555 where k0 = "ZZZZZZ"
140
170
self .assertEqual (
141
- bytes (tarantool .request .RequestUpdate (0x11 , "ZZZZZZ" , [(0x33 , '=' , 0x3333 ), (0x44 , '=' , 0x4444 ), (0x55 , '=' , 0x5555 )], False )),
171
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , "ZZZZZZ" , [(0x33 , '=' , 0x3333 ), (0x44 , '=' , 0x4444 ), (0x55 , '=' , 0x5555 )], False )),
142
172
binascii .unhexlify ("130000003500000000000000110000000000000001000000065a5a5a5a5a5a03000000330000000004333300004400000000044444000055000000000455550000" ),
143
173
"Update: assign multiple integer values using a string key"
144
174
)
145
175
146
176
# update t17 set k51 = "KKK", k68 = "LLL", k85 = "MMM" where k0 = 0x22
147
177
self .assertEqual (
148
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 ,'=' , b"KKK" ), (0x44 ,'=' , b"LLL" ), (0x55 ,'=' , b"MMM" )], False )),
178
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 ,'=' , b"KKK" ), (0x44 ,'=' , b"LLL" ), (0x55 ,'=' , b"MMM" )], False )),
149
179
binascii .unhexlify ("1300000030000000000000001100000000000000010000000422000000030000003300000000034b4b4b4400000000034c4c4c5500000000034d4d4d" ),
150
180
"Update: assign multiple string values using an integer key"
151
181
)
152
182
153
183
# update t17 set k51 = "KKK", k68 = "LLL", k85 = "MMM" where k0 = "ZZZZZZ"
154
184
self .assertEqual (
155
- bytes (tarantool .request .RequestUpdate (0x11 , b"ZZZZZZ" , [(0x33 ,'=' , b"KKK" ), (0x44 ,'=' , b"LLL" ), (0x55 ,'=' , b"MMM" )], False )),
185
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , b"ZZZZZZ" , [(0x33 ,'=' , b"KKK" ), (0x44 ,'=' , b"LLL" ), (0x55 ,'=' , b"MMM" )], False )),
156
186
binascii .unhexlify ("130000003200000000000000110000000000000001000000065a5a5a5a5a5a030000003300000000034b4b4b4400000000034c4c4c5500000000034d4d4d" ),
157
187
"Update: assign multiple string values using a string key"
158
188
)
@@ -162,7 +192,7 @@ def test__cast_to_bytes(self):
162
192
163
193
# update t17 set k51 = k51 + 0x55 where k0 = 0x22
164
194
self .assertEqual (
165
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '+' , 0x55 )], False )),
195
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '+' , 0x55 )], False )),
166
196
binascii .unhexlify ("130000001f00000000000000"
167
197
+ "11000000" # space_no
168
198
+ "00000000" # flags
@@ -183,7 +213,7 @@ def test__cast_to_bytes(self):
183
213
184
214
# update t17 set k51 = k51 & 0x55 where k0 = 0x22
185
215
self .assertEqual (
186
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '&' , 0x55 )], False )),
216
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '&' , 0x55 )], False )),
187
217
binascii .unhexlify ("130000001f00000000000000" # 12 byte header
188
218
+ "11000000" # space_no
189
219
+ "00000000" # flags
@@ -205,7 +235,7 @@ def test__cast_to_bytes(self):
205
235
206
236
# update t17 set k51 = k51 | 0x55 where k0 = 0x22
207
237
self .assertEqual (
208
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '^' , 0x55 )], False )),
238
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '^' , 0x55 )], False )),
209
239
binascii .unhexlify ("130000001f00000000000000" # 12 byte header
210
240
+ "11000000" # space_no
211
241
+ "00000000" # flags
@@ -227,7 +257,7 @@ def test__cast_to_bytes(self):
227
257
228
258
# update t17 set k51 = k51 | 0x55 where k0 = 0x22
229
259
self .assertEqual (
230
- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '|' , 0x55 )], False )),
260
+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '|' , 0x55 )], False )),
231
261
binascii .unhexlify ("130000001f00000000000000" # 12 byte header
232
262
+ "11000000" # space_no
233
263
+ "00000000" # flags
0 commit comments