99
1010
1111import 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+ })
1231
1332
1433class RequestInsert (unittest .TestCase ):
34+ def setUp (self ):
35+ self .conn1 = ConnectionMock (tarantool .NUM )
36+ self .conn2 = ConnectionMock (tarantool .STR )
1537
1638 def test__cast_to_bytes (self ):
1739 '''
1840 Test binary INSERT request representation
1941 '''
2042 self .assertEqual (
21- bytes (tarantool .request .RequestInsert (1 , (1 , 2000 , 30000 ), False )),
43+ bytes (tarantool .request .RequestInsert (self . conn1 , 1 , (1 , 2000 , 30000 ), False )),
2244 binascii .unhexlify ("0d0000001b00000000000000010000000000000003000000040100000004d00700000430750000" )
2345 )
2446
2547 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 )),
2749 binascii .unhexlify ("0d0000001c0000000000000001000000000000000300000003414141044242424206434343434343" )
2850 )
2951
3052
3153class RequestDelete (unittest .TestCase ):
54+ def setUp (self ):
55+ self .conn1 = ConnectionMock (tarantool .NUM )
56+ self .conn2 = ConnectionMock (tarantool .STR )
3257
3358 def test__cast_to_bytes (self ):
3459 '''
3560 Test binary DELETE request representation
3661 '''
3762 self .assertEqual (
38- bytes (tarantool .request .RequestDelete (1 , 1 , False )),
63+ bytes (tarantool .request .RequestDelete (self . conn1 , 1 , 1 , False )),
3964 binascii .unhexlify ("1500000011000000000000000100000000000000010000000401000000" )
4065 )
4166
4267 self .assertEqual (
43- bytes (tarantool .request .RequestDelete (1 , b"AAA" , False )),
68+ bytes (tarantool .request .RequestDelete (self . conn2 , 1 , b"AAA" , False )),
4469 binascii .unhexlify ("15000000100000000000000001000000000000000100000003414141" )
4570 )
4671
@@ -50,48 +75,53 @@ def test__cast_to_bytes(self):
5075
5176
5277class RequestSelect (unittest .TestCase ):
78+ def setUp (self ):
79+ self .conn1 = ConnectionMock (tarantool .NUM )
80+ self .conn2 = ConnectionMock (tarantool .STR )
5381
5482 def test__cast_to_bytes (self ):
5583 '''
5684 Test binary SELECT request representation
5785 '''
5886 # select * from t1 where k0 = 1
5987 self .assertEqual (
60- bytes (tarantool .request .RequestSelect (1 , 0 , [(1 ,)], 0 , 0xffff )),
88+ bytes (tarantool .request .RequestSelect (self . conn1 , 1 , 0 , [(1 ,)], 0 , 0xffff )),
6189 binascii .unhexlify ("110000001d00000000000000010000000000000000000000ffff000001000000010000000401000000" ),
6290 "Select using integer key"
6391 )
6492
6593 # select * from t1 where k0 = "AAA"
6694 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 )),
6896 binascii .unhexlify ("110000001c00000000000000010000000000000000000000ffff0000010000000100000003414141" ),
6997 "Select using string key"
7098 )
7199
72100 # select * from t1 where k0 in (1, 2, 3)
73101 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 )),
75103 binascii .unhexlify ("110000002f00000000000000010000000000000000000000ffff000003000000010000000401000000010000000402000000010000000403000000" ),
76104 "Select multiple keys"
77105 )
78106
79107 # select * from t1 where k0 = (1, 2)
80108 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 )),
82110 binascii .unhexlify ("110000002200000000000000010000000000000000000000ffff0000010000000200000004010000000402000000" ),
83111 "Select using composite index"
84112 )
85113
86114 # select * from t1 where k0 = (1, 2) or k0 = (3, 4)
87115 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 )),
89117 binascii .unhexlify ("110000003000000000000000010000000000000000000000ffff00000200000002000000040100000004020000000200000004030000000404000000" ),
90118 "Select multiple keys using composite index"
91119 )
92120
93121
94122class RequestUpdate (unittest .TestCase ):
123+ def setUp (self ):
124+ self .conn = ConnectionMock (tarantool .NUM )
95125
96126 def test__cast_to_bytes (self ):
97127 '''
@@ -103,56 +133,56 @@ def test__cast_to_bytes(self):
103133
104134 # update t17 set k51 = 0x11223344 where k0 = 0x22
105135 self .assertEqual (
106- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '=' , 0x11223344 )], False )),
136+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '=' , 0x11223344 )], False )),
107137 binascii .unhexlify ("130000001f0000000000000011000000000000000100000004220000000100000033000000000444332211" ),
108138 "Update: assign single integer value using an integer key"
109139 )
110140
111141 # update t17 set k51 = 0x11223344 where k0 = "ZZZZZZ"
112142 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 )),
114144 binascii .unhexlify ("130000002100000000000000110000000000000001000000065a5a5a5a5a5a0100000033000000000444332211" ),
115145 "Update: assign single integer value using a string key"
116146 )
117147
118148 # update t17 set k51 = "NNN" where k0 = 0x22
119149 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 )),
121151 binascii .unhexlify ("130000001e000000000000001100000000000000010000000422000000010000003300000000034e4e4e" ),
122152 "Update: assign single string value using an integer key"
123153 )
124154
125155 # update t17 set k51 = "NNN" where k0 = "ZZZZZZ"
126156 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 )),
128158 binascii .unhexlify ("130000002000000000000000110000000000000001000000065a5a5a5a5a5a010000003300000000034e4e4e" ),
129159 "Update: assign single string value using a string key"
130160 )
131161
132162 # update t17 set k51 = 0x3333, k68 = 0x4444, k85 = 0x5555 where k0 = 0x22
133163 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 )),
135165 binascii .unhexlify ("130000003300000000000000110000000000000001000000042200000003000000330000000004333300004400000000044444000055000000000455550000" ),
136166 "Update: assign multiple integer values using an integer key"
137167 )
138168
139169 # update t17 set k51 = 0x3333, k68 = 0x4444, k85 = 0x5555 where k0 = "ZZZZZZ"
140170 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 )),
142172 binascii .unhexlify ("130000003500000000000000110000000000000001000000065a5a5a5a5a5a03000000330000000004333300004400000000044444000055000000000455550000" ),
143173 "Update: assign multiple integer values using a string key"
144174 )
145175
146176 # update t17 set k51 = "KKK", k68 = "LLL", k85 = "MMM" where k0 = 0x22
147177 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 )),
149179 binascii .unhexlify ("1300000030000000000000001100000000000000010000000422000000030000003300000000034b4b4b4400000000034c4c4c5500000000034d4d4d" ),
150180 "Update: assign multiple string values using an integer key"
151181 )
152182
153183 # update t17 set k51 = "KKK", k68 = "LLL", k85 = "MMM" where k0 = "ZZZZZZ"
154184 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 )),
156186 binascii .unhexlify ("130000003200000000000000110000000000000001000000065a5a5a5a5a5a030000003300000000034b4b4b4400000000034c4c4c5500000000034d4d4d" ),
157187 "Update: assign multiple string values using a string key"
158188 )
@@ -162,7 +192,7 @@ def test__cast_to_bytes(self):
162192
163193 # update t17 set k51 = k51 + 0x55 where k0 = 0x22
164194 self .assertEqual (
165- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '+' , 0x55 )], False )),
195+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '+' , 0x55 )], False )),
166196 binascii .unhexlify ("130000001f00000000000000"
167197 + "11000000" # space_no
168198 + "00000000" # flags
@@ -183,7 +213,7 @@ def test__cast_to_bytes(self):
183213
184214 # update t17 set k51 = k51 & 0x55 where k0 = 0x22
185215 self .assertEqual (
186- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '&' , 0x55 )], False )),
216+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '&' , 0x55 )], False )),
187217 binascii .unhexlify ("130000001f00000000000000" # 12 byte header
188218 + "11000000" # space_no
189219 + "00000000" # flags
@@ -205,7 +235,7 @@ def test__cast_to_bytes(self):
205235
206236 # update t17 set k51 = k51 | 0x55 where k0 = 0x22
207237 self .assertEqual (
208- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '^' , 0x55 )], False )),
238+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '^' , 0x55 )], False )),
209239 binascii .unhexlify ("130000001f00000000000000" # 12 byte header
210240 + "11000000" # space_no
211241 + "00000000" # flags
@@ -227,7 +257,7 @@ def test__cast_to_bytes(self):
227257
228258 # update t17 set k51 = k51 | 0x55 where k0 = 0x22
229259 self .assertEqual (
230- bytes (tarantool .request .RequestUpdate (0x11 , 0x22 , [(0x33 , '|' , 0x55 )], False )),
260+ bytes (tarantool .request .RequestUpdate (self . conn , 0x11 , 0x22 , [(0x33 , '|' , 0x55 )], False )),
231261 binascii .unhexlify ("130000001f00000000000000" # 12 byte header
232262 + "11000000" # space_no
233263 + "00000000" # flags
0 commit comments