4
4
5
5
import sys
6
6
import unittest
7
+ import uuid
7
8
import decimal
8
9
import warnings
9
10
import tarantool
10
11
11
12
from .lib .tarantool_server import TarantoolServer
12
- from .lib .skip import skip_or_run_decimal_test
13
+ from .lib .skip import skip_or_run_decimal_test , skip_or_run_UUID_test
13
14
from tarantool .error import MsgpackError , MsgpackWarning
14
15
15
16
class TestSuite_ExtTypes (unittest .TestCase ):
@@ -24,6 +25,7 @@ def setUpClass(self):
24
25
self .adm = self .srv .admin
25
26
self .adm (r"""
26
27
_, decimal = pcall(require, 'decimal')
28
+ _, uuid = pcall(require, 'uuid')
27
29
28
30
box.schema.space.create('test')
29
31
box.space['test']:create_index('primary', {
@@ -212,6 +214,50 @@ def test_decimal_encode_with_precision_loss(self):
212
214
213
215
self .assertSequenceEqual (self .con .eval (lua_eval ), [True ])
214
216
217
+
218
+ UUID_cases = [
219
+ "ae28d4f6-076c-49dd-8227-7f9fae9592d0" ,
220
+ "b3121301-9300-4038-a652-ead943fb9c39" ,
221
+ "dfa69f02-92e6-44a5-abb5-84b39292ff93" ,
222
+ "8b69a1ce-094a-4e21-a5dc-4cdae7cd8960" ,
223
+ "25932334-1d42-4686-9299-ec1a7165227c" ,
224
+ ]
225
+
226
+ @skip_or_run_UUID_test
227
+ def test_UUID_decode (self ):
228
+ for i in range (len (self .UUID_cases )):
229
+ with self .subTest (msg = str (i )):
230
+ UUID_case = self .UUID_cases [i ]
231
+
232
+ self .adm ("box.space['test']:replace{%d, uuid.fromstr('%s')}" % (i , UUID_case ))
233
+
234
+ self .assertSequenceEqual (
235
+ self .con .select ('test' , i ),
236
+ [[i , uuid .UUID (UUID_case )]])
237
+
238
+ @skip_or_run_UUID_test
239
+ def test_UUID_encode (self ):
240
+ for i in range (len (self .UUID_cases )):
241
+ with self .subTest (msg = str (i )):
242
+ UUID_case = self .UUID_cases [i ]
243
+
244
+ self .con .insert ('test' , [i , uuid .UUID (UUID_case )])
245
+
246
+ lua_eval = f"""
247
+ local tuple = box.space['test']:get({ i } )
248
+ assert(tuple ~= nil)
249
+
250
+ local id = uuid.fromstr('{ UUID_case } ')
251
+ if tuple[2] == id then
252
+ return true
253
+ else
254
+ return nil, ('%s is not equal to expected %s'):format(
255
+ tostring(tuple[2]), tostring(id))
256
+ end
257
+ """
258
+
259
+ self .assertSequenceEqual (self .con .eval (lua_eval ), [True ])
260
+
215
261
@classmethod
216
262
def tearDownClass (self ):
217
263
self .con .close ()
0 commit comments