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