4
4
5
5
import sys
6
6
import unittest
7
+
7
8
import tarantool
8
9
9
10
from .lib .tarantool_server import TarantoolServer
10
11
12
+
11
13
class TestSuite_Request (unittest .TestCase ):
12
14
@classmethod
13
15
def setUpClass (self ):
@@ -17,6 +19,7 @@ def setUpClass(self):
17
19
self .srv .script = 'test/suites/box.lua'
18
20
self .srv .start ()
19
21
self .con = tarantool .Connection (self .srv .host , self .srv .args ['primary' ])
22
+ self .con_encoding_none = tarantool .Connection (self .srv .host , self .srv .args ['primary' ], encoding = None )
20
23
self .adm = self .srv .admin
21
24
self .space_created = self .adm ("box.schema.create_space('space_1')" )
22
25
self .adm ("""
@@ -31,17 +34,64 @@ def setUpClass(self):
31
34
parts = {2, 'num', 3, 'str'},
32
35
unique = false})
33
36
""" .replace ('\n ' , ' ' ))
37
+
34
38
self .space_created = self .adm ("box.schema.create_space('space_2')" )
35
39
self .adm ("""
36
40
box.space['space_2']:create_index('primary', {
37
41
type = 'hash',
38
42
parts = {1, 'num'},
39
43
unique = true})
40
44
""" .replace ('\n ' , ' ' ))
45
+
46
+ self .adm ("box.schema.create_space('space_str')" )
47
+ self .adm ("""
48
+ box.space['space_str']:create_index('primary', {
49
+ type = 'tree',
50
+ parts = {1, 'str'},
51
+ unique = true})
52
+ """ .replace ('\n ' , ' ' ))
53
+
54
+ self .adm ("box.schema.create_space('space_varbin')" )
55
+ self .adm ("""
56
+ box.space['space_varbin']:create_index('primary', {
57
+ type = 'tree',
58
+ parts = {1, 'varbinary'},
59
+ unique = true})
60
+ """ .replace ('\n ' , ' ' ))
61
+ self .adm ("""
62
+ buffer = require('buffer')
63
+ ffi = require('ffi')
64
+
65
+ function encode_bin(bytes)
66
+ local tmpbuf = buffer.ibuf()
67
+ local p = tmpbuf:alloc(3 + #bytes)
68
+ p[0] = 0x91
69
+ p[1] = 0xC4
70
+ p[2] = #bytes
71
+ for i, c in pairs(bytes) do
72
+ p[i + 3 - 1] = c
73
+ end
74
+ return tmpbuf
75
+ end
76
+
77
+ function bintuple_insert(space, bytes)
78
+ local tmpbuf = encode_bin(bytes)
79
+ ffi.cdef[[
80
+ int box_insert(uint32_t space_id, const char *tuple, const char *tuple_end, box_tuple_t **result);
81
+ ]]
82
+ ffi.C.box_insert(space.id, tmpbuf.rpos, tmpbuf.wpos, nil)
83
+ end
84
+ """ )
41
85
self .adm ("json = require('json')" )
42
86
self .adm ("fiber = require('fiber')" )
43
87
self .adm ("uuid = require('uuid')" )
44
88
89
+ def assertNotRaises (self , func , * args , ** kwargs ):
90
+ try :
91
+ func (* args , ** kwargs )
92
+ except Exception as e :
93
+ self .fail ('Function raised Exception: %s' % repr (e ))
94
+
45
95
def setUp (self ):
46
96
# prevent a remote tarantool from clean our session
47
97
if self .srv .is_started ():
@@ -55,6 +105,7 @@ def test_00_00_authenticate(self):
55
105
box.schema.user.grant('test', 'execute,read,write', 'universe')
56
106
""" ))
57
107
self .assertEqual (self .con .authenticate ('test' , 'test' )._data , None )
108
+ self .assertEqual (self .con_encoding_none .authenticate ('test' , 'test' )._data , None )
58
109
59
110
def test_00_01_space_created (self ):
60
111
# Check that space is created in setUpClass
@@ -299,6 +350,32 @@ def test_12_update_fields(self):
299
350
[[2 , 'help' , 7 ]]
300
351
)
301
352
353
+ def test_13_00_string_insert_default_behavior (self ):
354
+ self .assertNotRaises (self .con .insert , 'space_str' , [ 'test_13_string_insert_default_behavior' ])
355
+
356
+ def test_13_01_string_select_default_behavior (self ):
357
+ self .adm (r"box.space['space_str']:insert{'test_14_string_select_default_behavior'}" )
358
+ resp = self .con .select ('space_str' , ['test_14_string_select_default_behavior' ])
359
+ self .assertIsInstance (resp [0 ][0 ], tarantool .utils .string_types )
360
+
361
+ def test_13_02_varbinary_insert_default_behavior (self ):
362
+ self .assertNotRaises (self .con .insert , 'space_varbin' , [ b'test_15_varbinary_insert_default_behavior' ])
363
+
364
+ def test_13_03_varbinary_select_default_behavior (self ):
365
+ self .adm (r"""
366
+ bintuple_insert(box.space['space_varbin'], {0xDE, 0xAD, 0xBE, 0xAF, 0x16})
367
+ """ )
368
+ resp = self .con .select ('space_varbin' , [bytes .fromhex ('DEADBEAF16' )])
369
+ self .assertIsInstance (resp [0 ][0 ], tarantool .utils .binary_types )
370
+
371
+ def test_14_00_string_insert_encoding_none_behavior (self ):
372
+ self .assertNotRaises (self .con_encoding_none .insert , 'space_str' , [ bytes .fromhex ('DEADBEAF17' ) ])
373
+
374
+ def test_14_01_string_select_encoding_none_behavior (self ):
375
+ self .adm (r"box.space['space_str']:insert{'\xDE\xAD\xBE\xAF\x18'}" )
376
+ resp = self .con_encoding_none .select ('space_str' , [bytes .fromhex ('DEADBEAF18' )])
377
+ self .assertIsInstance (resp [0 ][0 ], tarantool .utils .binary_types )
378
+
302
379
@classmethod
303
380
def tearDownClass (self ):
304
381
self .con .close ()
0 commit comments