6
6
import unittest
7
7
import tarantool
8
8
9
+ from .lib .skip import skip_or_run_mp_bin_test , skip_or_run_varbinary_test
9
10
from .lib .tarantool_server import TarantoolServer
10
11
11
12
class TestSuite_Request (unittest .TestCase ):
@@ -16,7 +17,13 @@ def setUpClass(self):
16
17
self .srv = TarantoolServer ()
17
18
self .srv .script = 'test/suites/box.lua'
18
19
self .srv .start ()
19
- self .con = tarantool .Connection (self .srv .host , self .srv .args ['primary' ])
20
+
21
+ args = [self .srv .host , self .srv .args ['primary' ]]
22
+ self .con = tarantool .Connection (* args )
23
+ self .con_encoding_utf8 = tarantool .Connection (* args , encoding = 'utf-8' )
24
+ self .con_encoding_none = tarantool .Connection (* args , encoding = None )
25
+ self .conns = [self .con , self .con_encoding_utf8 , self .con_encoding_none ]
26
+
20
27
self .adm = self .srv .admin
21
28
self .space_created = self .adm ("box.schema.create_space('space_1')" )
22
29
self .adm ("""
@@ -31,17 +38,64 @@ def setUpClass(self):
31
38
parts = {2, 'num', 3, 'str'},
32
39
unique = false})
33
40
""" .replace ('\n ' , ' ' ))
41
+
34
42
self .space_created = self .adm ("box.schema.create_space('space_2')" )
35
43
self .adm ("""
36
44
box.space['space_2']:create_index('primary', {
37
45
type = 'hash',
38
46
parts = {1, 'num'},
39
47
unique = true})
40
48
""" .replace ('\n ' , ' ' ))
49
+
50
+ self .adm ("box.schema.create_space('space_str')" )
51
+ self .adm ("""
52
+ box.space['space_str']:create_index('primary', {
53
+ type = 'tree',
54
+ parts = {1, 'str'},
55
+ unique = true})
56
+ """ .replace ('\n ' , ' ' ))
57
+
58
+ self .adm ("box.schema.create_space('space_varbin')" )
59
+ self .adm ("""
60
+ box.space['space_varbin']:create_index('primary', {
61
+ type = 'tree',
62
+ parts = {1, 'varbinary'},
63
+ unique = true})
64
+ """ .replace ('\n ' , ' ' ))
65
+ self .adm ("""
66
+ buffer = require('buffer')
67
+ ffi = require('ffi')
68
+
69
+ function encode_bin(bytes)
70
+ local tmpbuf = buffer.ibuf()
71
+ local p = tmpbuf:alloc(3 + #bytes)
72
+ p[0] = 0x91
73
+ p[1] = 0xC4
74
+ p[2] = #bytes
75
+ for i, c in pairs(bytes) do
76
+ p[i + 3 - 1] = c
77
+ end
78
+ return tmpbuf
79
+ end
80
+
81
+ function bintuple_insert(space, bytes)
82
+ local tmpbuf = encode_bin(bytes)
83
+ ffi.cdef[[
84
+ int box_insert(uint32_t space_id, const char *tuple, const char *tuple_end, box_tuple_t **result);
85
+ ]]
86
+ ffi.C.box_insert(space.id, tmpbuf.rpos, tmpbuf.wpos, nil)
87
+ end
88
+ """ )
41
89
self .adm ("json = require('json')" )
42
90
self .adm ("fiber = require('fiber')" )
43
91
self .adm ("uuid = require('uuid')" )
44
92
93
+ def assertNotRaises (self , func , * args , ** kwargs ):
94
+ try :
95
+ func (* args , ** kwargs )
96
+ except Exception as e :
97
+ self .fail ('Function raised Exception: %s' % repr (e ))
98
+
45
99
def setUp (self ):
46
100
# prevent a remote tarantool from clean our session
47
101
if self .srv .is_started ():
@@ -54,7 +108,8 @@ def test_00_00_authenticate(self):
54
108
self .assertIsNone (self .srv .admin ("""
55
109
box.schema.user.grant('test', 'execute,read,write', 'universe')
56
110
""" ))
57
- self .assertEqual (self .con .authenticate ('test' , 'test' )._data , None )
111
+ for con in self .conns :
112
+ self .assertEqual (con .authenticate ('test' , 'test' )._data , None )
58
113
59
114
def test_00_01_space_created (self ):
60
115
# Check that space is created in setUpClass
@@ -302,6 +357,51 @@ def test_12_update_fields(self):
302
357
[[2 , 'help' , 7 ]]
303
358
)
304
359
360
+ def test_13_00_string_insert_encoding_utf8_behavior (self ):
361
+ self .assertNotRaises (
362
+ self .con_encoding_utf8 .insert ,
363
+ 'space_str' , [ 'test_13_00' ])
364
+
365
+ def test_13_01_string_select_encoding_utf8_behavior (self ):
366
+ self .adm (r"box.space['space_str']:insert{'test_13_01'}" )
367
+
368
+ strdata = 'test_13_01'
369
+ resp = self .con_encoding_utf8 .select ('space_str' , [strdata ])
370
+ self .assertEquals (resp [0 ][0 ], strdata )
371
+
372
+ @skip_or_run_mp_bin_test
373
+ @skip_or_run_varbinary_test
374
+ def test_13_02_varbinary_insert_encoding_utf8_behavior (self ):
375
+ self .assertNotRaises (
376
+ self .con_encoding_utf8 .insert ,
377
+ 'space_varbin' , [ b'test_13_02' ])
378
+
379
+ @skip_or_run_mp_bin_test
380
+ @skip_or_run_varbinary_test
381
+ def test_13_03_varbinary_select_encoding_utf8_behavior (self ):
382
+ self .adm (r"""
383
+ bintuple_insert(
384
+ box.space['space_varbin'],
385
+ {0xDE, 0xAD, 0xBE, 0xAF, 0x13, 0x03})
386
+ """ )
387
+
388
+ bindata = bytes (bytearray .fromhex ('DEADBEAF1303' ))
389
+ resp = self .con_encoding_utf8 .select ('space_varbin' , [bindata ])
390
+ self .assertEquals (resp [0 ][0 ], bindata )
391
+
392
+ def test_14_00_string_insert_encoding_none_behavior (self ):
393
+ self .assertNotRaises (
394
+ self .con_encoding_none .insert ,
395
+ 'space_str' ,
396
+ [ bytes (bytearray .fromhex ('DEADBEAF1400' )) ])
397
+
398
+ def test_14_01_string_select_encoding_none_behavior (self ):
399
+ self .adm (r"box.space['space_str']:insert{'\xDE\xAD\xBE\xAF\x14\x01'}" )
400
+
401
+ bindata = bytes (bytearray .fromhex ('DEADBEAF1401' ))
402
+ resp = self .con_encoding_none .select ('space_str' , [bindata ])
403
+ self .assertEquals (resp [0 ][0 ], bindata )
404
+
305
405
@classmethod
306
406
def tearDownClass (self ):
307
407
self .con .close ()
0 commit comments