Skip to content

Commit

Permalink
Fixed tests on new Tarantool
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcoding committed Sep 30, 2017
1 parent b614e44 commit 0aed7c4
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 64 deletions.
3 changes: 2 additions & 1 deletion asynctnt/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def get_random_port():

def _create_initlua_template(self):
return """
box.cfg{
listen = "${host}:${port}",
wal_mode = "${wal_mode}",
Expand Down Expand Up @@ -385,7 +386,7 @@ def start(self):
attempts = math.ceil(self._timeout / interval)
while attempts > 0:
try:
status = self.command('box.info.status', print_greeting=False)
status = self.command('box.info.status', print_greeting=True)
if status:
status = status[0]
if status == 'running':
Expand Down
15 changes: 14 additions & 1 deletion tests/files/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,27 @@ end

_G.B = bootstrap()

function change_format()
box.space.tester:format({
{type=B.types.unsigned, name='f1'},
{type=B.types.string, name='f2'},
{type=B.types.unsigned, name='f3'},
{type=B.types.unsigned, name='f4'},
{type=B.types.any, name='f5'},
{type=B.types.any, name='f6'},
})
end

box.schema.func.create('change_format', {setuid=true})


box.once('v1', function()
box.schema.user.create('t1', {password = 't1'})
box.schema.user.grant('t1', 'read,write,execute', 'universe')

local s = box.schema.create_space('tester')
s:format({
{type=B.types.string, name='f1'},
{type=B.types.unsigned, name='f1'},
{type=B.types.string, name='f2'},
{type=B.types.unsigned, name='f3'},
{type=B.types.unsigned, name='f4'},
Expand Down
25 changes: 21 additions & 4 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class CommonTestCase(BaseTarantoolTestCase):
async def test__encoding_utf8(self):
p, p_cmp = get_complex_param(replace_bin=False)

data = [1, 'hello', p]
data_cmp = [1, 'hello', p_cmp]
data = [1, 'hello', 1, 0, p]
data_cmp = [1, 'hello', 1, 0, p_cmp]

res = await self.conn.insert(self.TESTER_SPACE_ID, data)
self.assertListEqual(res.body, [data_cmp], 'Body ok')
Expand All @@ -25,8 +25,8 @@ async def test__encoding_cp1251(self):
await self.tnt_reconnect(encoding='cp1251')
p, p_cmp = get_complex_param(replace_bin=False)

data = [1, 'hello', p]
data_cmp = [1, 'hello', p_cmp]
data = [1, 'hello', 1, 0, p]
data_cmp = [1, 'hello', 1, 0, p_cmp]

res = await self.conn.insert(self.TESTER_SPACE_ID, data)
self.assertListEqual(res.body, [data_cmp], 'Body ok')
Expand Down Expand Up @@ -55,6 +55,23 @@ async def test__schema_refetch_on_schema_change(self):
self.assertGreater(self.conn.schema_id, schema_before,
'Schema changed')

async def test__schema_refetch_on_schema_change_format(self):
await self.tnt_reconnect(auto_refetch_schema=True, username='t1', password='t1')
self.assertTrue(self.conn.fetch_schema)
self.assertTrue(self.conn.auto_refetch_schema)
schema_before = self.conn.schema_id
self.assertNotEqual(schema_before, -1)

await self.conn.call('change_format')

try:
await self.conn.ping()
except Exception as e:
self.fail(e)

self.assertGreater(self.conn.schema_id, schema_before,
'Schema changed')

async def test__schema_no_fetch_and_refetch(self):
await self.tnt_reconnect(auto_refetch_schema=False,
fetch_schema=False)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_op_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
class DeleteTestCase(BaseTarantoolTestCase):
async def _fill_data(self):
data = [
[0, 'a', 1],
[1, 'b', 0],
[0, 'a', 1, 2, 'hello my darling'],
[1, 'b', 3, 4, 'hello my darling, again'],
]
for t in data:
await self.conn.insert(self.TESTER_SPACE_ID, t)
Expand Down Expand Up @@ -132,7 +132,7 @@ async def test__delete_dict_key(self):
self.assertListEqual(res.body, [data[0]], 'Body ok')

async def test__delete_dict_resp(self):
data = [0, 'hello', 0, 'wow']
data = [0, 'hello', 0, 1, 'wow']
await self.conn.insert(self.TESTER_SPACE_ID, data)

res = await self.conn.delete(self.TESTER_SPACE_ID, [0],
Expand All @@ -141,5 +141,6 @@ async def test__delete_dict_resp(self):
'f1': 0,
'f2': 'hello',
'f3': 0,
'f4': 'wow'
'f4': 1,
'f5': 'wow'
}])
44 changes: 26 additions & 18 deletions tests/test_op_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class InsertTestCase(BaseTarantoolTestCase):
async def test__insert_one(self):
data = [1, 'hello']
data = [1, 'hello', 1, 4, 'what is up']
res = await self.conn.insert(self.TESTER_SPACE_ID, data)

self.assertIsInstance(res, Response, 'Got response')
Expand All @@ -18,7 +18,7 @@ async def test__insert_one(self):
self.assertListEqual(res.body, [data], 'Body ok')

async def test__insert_by_name(self):
data = [1, 'hello']
data = [1, 'hello', 1, 4, 'what is up']
res = await self.conn.insert(self.TESTER_SPACE_NAME, data)

self.assertIsInstance(res, Response, 'Got response')
Expand All @@ -29,28 +29,30 @@ async def test__insert_by_name(self):
async def test__insert_by_name_no_schema(self):
await self.tnt_reconnect(fetch_schema=False)

data = [1, 'hello']
data = [1, 'hello', 1, 4, 'what is up']
with self.assertRaises(TarantoolSchemaError):
await self.conn.insert(self.TESTER_SPACE_NAME, data)

async def test__insert_complex_tuple(self):
p, p_cmp = get_complex_param(replace_bin=False)
data = [1, 'hello', p]
data_cmp = [1, 'hello', p_cmp]
data = [1, 'hello', 1, 2, p]
data_cmp = [1, 'hello', 1, 2, p_cmp]

res = await self.conn.insert(self.TESTER_SPACE_ID, data)
self.assertListEqual(res.body, [data_cmp], 'Body ok')

async def test__insert_replace(self):
data = [1, 'hello']
data = [1, 'hello', 1, 4, 'what is up']

await self.conn.insert(self.TESTER_SPACE_ID, data)

try:
res = await self.conn.insert(self.TESTER_SPACE_ID, [1, 'hello2'],
data = [1, 'hello2', 1, 4, 'what is up']
res = await self.conn.insert(self.TESTER_SPACE_ID,
t=data,
replace=True)

self.assertListEqual(res.body, [[1, 'hello2']], 'Body ok')
self.assertListEqual(res.body, [data], 'Body ok')
except Exception as e:
self.fail(e)

Expand All @@ -65,11 +67,11 @@ async def test__insert_invalid_types(self):
await self.conn.insert(self.TESTER_SPACE_ID)

async def test__replace(self):
data = [1, 'hello']
data = [1, 'hello', 1, 4, 'what is up']
res = await self.conn.replace(self.TESTER_SPACE_ID, data)
self.assertListEqual(res.body, [data], 'Body ok')

data = [1, 'hello2']
data = [1, 'hello2', 1, 5, 'what is up']
res = await self.conn.replace(self.TESTER_SPACE_ID, data)
self.assertListEqual(res.body, [data], 'Body ok')

Expand All @@ -86,42 +88,48 @@ async def test__replace_invalid_types(self):
async def test__insert_dict_key(self):
data = {
'f1': 1,
'f2': 'hello'
'f2': 'hello',
'f3': 5,
'f4': 6,
'f5': 'hello dog',
}
data_cmp = [1, 'hello', None, None, None]
data_cmp = [1, 'hello', 5, 6, 'hello dog']
res = await self.conn.insert(self.TESTER_SPACE_ID, data)
self.assertListEqual(res.body, [data_cmp], 'Body ok')

async def test__insert_dict_key_holes(self):
data = {
'f1': 1,
'f2': 'hello',
'f4': 'wow'
'f3': 3,
'f4': 6,
'f5': None,
}
data_cmp = [1, 'hello', None, 'wow', None]
data_cmp = [1, 'hello', 3, 6, None]
res = await self.conn.insert(self.TESTER_SPACE_ID, data)
self.assertListEqual(res.body, [data_cmp], 'Body ok')

async def test__insert_dict_resp(self):
data = [0, 'hello', 0, 'wow']
data = [0, 'hello', 0, 5, 'wow']
res = await self.conn.insert(self.TESTER_SPACE_ID, data,
tuple_as_dict=True)
self.assertListEqual(res.body, [{
'f1': 0,
'f2': 'hello',
'f3': 0,
'f4': 'wow'
'f4': 5,
'f5': 'wow'
}])

async def test__insert_dict_resp_extra(self):
data = [0, 'hello', 5, 'wow', 'help', 'common', 'yo']
data = [0, 'hello', 5, 6, 'help', 'common', 'yo']
res = await self.conn.insert(self.TESTER_SPACE_ID, data,
tuple_as_dict=True)
self.assertListEqual(res.body, [{
'f1': 0,
'f2': 'hello',
'f3': 5,
'f4': 'wow',
'f4': 6,
'f5': 'help',
'': ['common', 'yo']
}])
14 changes: 9 additions & 5 deletions tests/test_op_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SelectTestCase(BaseTarantoolTestCase):
async def _fill_data(self, count=3):
data = []
for i in range(count):
t = [i, str(i)]
t = [i, str(i), 1, 2, 'something']
data.append(t)
await self.conn.insert(self.TESTER_SPACE_ID, t)
return data
Expand All @@ -24,7 +24,10 @@ async def _fill_data_dict(self, count=3):
for i in range(count):
t = {
'f1': i,
'f2': str(i)
'f2': str(i),
'f3': 1,
'f4': 2,
'f5': 'something',
}
t = await self.conn.insert(self.TESTER_SPACE_ID, t,
tuple_as_dict=True)
Expand Down Expand Up @@ -125,8 +128,9 @@ async def test__select_by_key_multiple_items_index(self):
data = await self._fill_data()
next_id = data[-1][0] + 1
next_txt = data[-1][1]
await self.conn.insert(self.TESTER_SPACE_ID, [next_id, next_txt])
data.append([next_id, next_txt])
await self.conn.insert(self.TESTER_SPACE_ID,
[next_id, next_txt, 1, 2, 'text'])
data.append([next_id, next_txt, 1, 2, 'text'])

res = await self.conn.select(self.TESTER_SPACE_NAME, [next_txt],
index='txt')
Expand Down Expand Up @@ -172,7 +176,7 @@ async def test__select_iterator_str(self):

async def test__select_complex(self):
p, p_cmp = get_complex_param(replace_bin=False)
data = [1, 'hello', p_cmp]
data = [1, 'hello2', 1, 4, p_cmp]

await self.conn.insert(self.TESTER_SPACE_ID, data)

Expand Down
Loading

0 comments on commit 0aed7c4

Please sign in to comment.