|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# pylint: disable=C0301,W0105,W0401,W0614 |
| 3 | +''' |
| 4 | +Tests for tarantool.request module |
| 5 | +''' |
| 6 | + |
| 7 | +import binascii |
| 8 | +import unittest |
| 9 | + |
| 10 | + |
| 11 | +import tarantool.request |
| 12 | + |
| 13 | + |
| 14 | +class RequestInsert(unittest.TestCase): |
| 15 | + |
| 16 | + def test__cast_to_bytes(self): |
| 17 | + ''' |
| 18 | + Test binary INSERT request representation |
| 19 | + ''' |
| 20 | + self.assertEqual( |
| 21 | + bytes(tarantool.request.RequestInsert(1, (1, 2000, 30000), False)), |
| 22 | + binascii.unhexlify("0d0000001b00000000000000010000000000000003000000040100000004d00700000430750000") |
| 23 | + ) |
| 24 | + |
| 25 | + self.assertEqual( |
| 26 | + bytes(tarantool.request.RequestInsert(1, (b"AAA", b"BBBB", b"CCCCCC"), False)), |
| 27 | + binascii.unhexlify("0d0000001c0000000000000001000000000000000300000003414141044242424206434343434343") |
| 28 | + ) |
| 29 | + |
| 30 | + |
| 31 | +class RequestDelete(unittest.TestCase): |
| 32 | + |
| 33 | + def test__cast_to_bytes(self): |
| 34 | + ''' |
| 35 | + Test binary DELETE request representation |
| 36 | + ''' |
| 37 | + self.assertEqual( |
| 38 | + bytes(tarantool.request.RequestDelete(1, 1, False)), |
| 39 | + binascii.unhexlify("1500000011000000000000000100000000000000010000000401000000") |
| 40 | + ) |
| 41 | + |
| 42 | + self.assertEqual( |
| 43 | + bytes(tarantool.request.RequestDelete(1, b"AAA", False)), |
| 44 | + binascii.unhexlify("15000000100000000000000001000000000000000100000003414141") |
| 45 | + ) |
| 46 | + |
| 47 | + # Raises a TypeError exception because the primary key must be a scalar value (int or str) |
| 48 | + with self.assertRaises(TypeError): |
| 49 | + tarantool.request.RequestDelete(1, [1,2], False) |
| 50 | + |
| 51 | + |
| 52 | +class RequestSelect(unittest.TestCase): |
| 53 | + |
| 54 | + def test__cast_to_bytes(self): |
| 55 | + ''' |
| 56 | + Test binary SELECT request representation |
| 57 | + ''' |
| 58 | + # select * from t1 where k0 = 1 |
| 59 | + self.assertEqual( |
| 60 | + bytes(tarantool.request.RequestSelect(1, 0, [(1,)], 0, 0xffff)), |
| 61 | + binascii.unhexlify("110000001d00000000000000010000000000000000000000ffff000001000000010000000401000000") |
| 62 | + ) |
| 63 | + |
| 64 | + # select * from t1 where k0 = "AAA" |
| 65 | + self.assertEqual( |
| 66 | + bytes(tarantool.request.RequestSelect(1, 0, [(b"AAA",)], 0, 0xffff)), |
| 67 | + binascii.unhexlify("110000001c00000000000000010000000000000000000000ffff0000010000000100000003414141") |
| 68 | + ) |
| 69 | + |
| 70 | + # select * from t1 where k0 in (1, 2, 3) |
| 71 | + self.assertEqual( |
| 72 | + bytes(tarantool.request.RequestSelect(1, 0, [(1,), (2,), (3,)], 0, 0xffff)), |
| 73 | + binascii.unhexlify("110000002f00000000000000010000000000000000000000ffff000003000000010000000401000000010000000402000000010000000403000000") |
| 74 | + ) |
0 commit comments