|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +from __future__ import print_function |
| 4 | + |
| 5 | +import sys |
| 6 | +import unittest |
| 7 | + |
| 8 | +import dbapi20 |
| 9 | + |
| 10 | +import tarantool |
| 11 | +from tarantool import dbapi |
| 12 | +from .lib.tarantool_server import TarantoolServer |
| 13 | + |
| 14 | + |
| 15 | +class TestSuite_DBAPI(dbapi20.DatabaseAPI20Test): |
| 16 | + table_prefix = 'dbapi20test_' # If you need to specify a prefix for tables |
| 17 | + |
| 18 | + ddl0 = 'create table %s (id INTEGER PRIMARY KEY AUTOINCREMENT, ' \ |
| 19 | + 'name varchar(20))' |
| 20 | + ddl1 = 'create table %sbooze (name varchar(20) primary key)' % table_prefix |
| 21 | + ddl2 = 'create table %sbarflys (name varchar(20) primary key, ' \ |
| 22 | + 'drink varchar(30))' % table_prefix |
| 23 | + |
| 24 | + ddl_params = [ |
| 25 | + {'id': None, 'name': 'Michael'}, |
| 26 | + {'id': None, 'name': 'Mary'}, |
| 27 | + {'id': None, 'name': 'John'}, |
| 28 | + {'id': None, 'name': 'Ruth'}, |
| 29 | + {'id': None, 'name': 'Rachel'} |
| 30 | + ] |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def setUpClass(self): |
| 34 | + print(' DBAPI '.center(70, '='), file=sys.stderr) |
| 35 | + print('-' * 70, file=sys.stderr) |
| 36 | + self.srv = TarantoolServer() |
| 37 | + self.srv.script = 'unit/suites/box.lua' |
| 38 | + self.srv.start() |
| 39 | + self.con = tarantool.Connection(self.srv.host, self.srv.args['primary']) |
| 40 | + self.driver = dbapi |
| 41 | + self.connect_kw_args = dict( |
| 42 | + host=self.srv.host, |
| 43 | + port=self.srv.args['primary']) |
| 44 | + |
| 45 | + def setUp(self): |
| 46 | + # prevent a remote tarantool from clean our session |
| 47 | + if self.srv.is_started(): |
| 48 | + self.srv.touch_lock() |
| 49 | + self.con.flush_schema() |
| 50 | + |
| 51 | + # grant full access to guest |
| 52 | + self.srv.admin("box.schema.user.grant('guest', 'create,read,write," |
| 53 | + "execute', 'universe')") |
| 54 | + |
| 55 | + @classmethod |
| 56 | + def tearDownClass(self): |
| 57 | + self.con.close() |
| 58 | + self.srv.stop() |
| 59 | + self.srv.clean() |
| 60 | + |
| 61 | + def test_rowcount(self): |
| 62 | + con = self._connect() |
| 63 | + try: |
| 64 | + cur = con.cursor() |
| 65 | + self.executeDDL1(cur) |
| 66 | + dbapi20._failUnless(self,cur.rowcount in (-1,1), # Bug #543885 |
| 67 | + 'cursor.rowcount should be -1 or 0 after executing no-result ' |
| 68 | + 'statements' + str(cur.rowcount) |
| 69 | + ) |
| 70 | + cur.execute("%s into %sbooze values ('Victoria Bitter')" % ( |
| 71 | + self.insert, self.table_prefix |
| 72 | + )) |
| 73 | + dbapi20._failUnless(self,cur.rowcount in (-1,1), |
| 74 | + 'cursor.rowcount should == number or rows inserted, or ' |
| 75 | + 'set to -1 after executing an insert statement' |
| 76 | + ) |
| 77 | + cur.execute("select name from %sbooze" % self.table_prefix) |
| 78 | + dbapi20._failUnless(self,cur.rowcount in (-1,1), |
| 79 | + 'cursor.rowcount should == number of rows returned, or ' |
| 80 | + 'set to -1 after executing a select statement' |
| 81 | + ) |
| 82 | + self.executeDDL2(cur) |
| 83 | + dbapi20._failUnless(self,cur.rowcount in (-1,1), # Bug #543885 |
| 84 | + 'cursor.rowcount should be -1 or 0 after executing no-result ' |
| 85 | + 'statements' |
| 86 | + ) |
| 87 | + finally: |
| 88 | + con.close() |
| 89 | + |
| 90 | + @unittest.skip('Not implemented') |
| 91 | + def test_Binary(self): |
| 92 | + pass |
| 93 | + |
| 94 | + @unittest.skip('Not implemented') |
| 95 | + def test_STRING(self): |
| 96 | + pass |
| 97 | + |
| 98 | + @unittest.skip('Not implemented') |
| 99 | + def test_BINARY(self): |
| 100 | + pass |
| 101 | + |
| 102 | + @unittest.skip('Not implemented') |
| 103 | + def test_NUMBER(self): |
| 104 | + pass |
| 105 | + |
| 106 | + @unittest.skip('Not implemented') |
| 107 | + def test_DATETIME(self): |
| 108 | + pass |
| 109 | + |
| 110 | + @unittest.skip('Not implemented') |
| 111 | + def test_ROWID(self): |
| 112 | + pass |
| 113 | + |
| 114 | + @unittest.skip('Not implemented') |
| 115 | + def test_Date(self): |
| 116 | + pass |
| 117 | + |
| 118 | + @unittest.skip('Not implemented') |
| 119 | + def test_Time(self): |
| 120 | + pass |
| 121 | + |
| 122 | + @unittest.skip('Not implemented') |
| 123 | + def test_Timestamp(self): |
| 124 | + pass |
| 125 | + |
| 126 | + @unittest.skip('Not implemented as optional.') |
| 127 | + def test_nextset(self): |
| 128 | + pass |
| 129 | + |
| 130 | + @unittest.skip('To do') |
| 131 | + def test_callproc(self): |
| 132 | + pass |
| 133 | + |
| 134 | + def test_setoutputsize(self): # Do nothing |
| 135 | + pass |
| 136 | + |
| 137 | + @unittest.skip('To do') |
| 138 | + def test_description(self): |
| 139 | + pass |
0 commit comments