|  | 
|  | 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 | +    @classmethod | 
|  | 25 | +    def setUpClass(self): | 
|  | 26 | +        print(' DBAPI '.center(70, '='), file=sys.stderr) | 
|  | 27 | +        print('-' * 70, file=sys.stderr) | 
|  | 28 | +        self.srv = TarantoolServer() | 
|  | 29 | +        self.srv.script = 'unit/suites/box.lua' | 
|  | 30 | +        self.srv.start() | 
|  | 31 | +        self.con = tarantool.Connection(self.srv.host, self.srv.args['primary']) | 
|  | 32 | +        self.driver = dbapi | 
|  | 33 | +        self.connect_kw_args = dict( | 
|  | 34 | +            host=self.srv.host, | 
|  | 35 | +            port=self.srv.args['primary']) | 
|  | 36 | + | 
|  | 37 | +    def setUp(self): | 
|  | 38 | +        # prevent a remote tarantool from clean our session | 
|  | 39 | +        if self.srv.is_started(): | 
|  | 40 | +            self.srv.touch_lock() | 
|  | 41 | +        self.con.flush_schema() | 
|  | 42 | + | 
|  | 43 | +        # grant full access to guest | 
|  | 44 | +        self.srv.admin("box.schema.user.grant('guest', 'create,read,write," | 
|  | 45 | +                       "execute', 'universe')") | 
|  | 46 | + | 
|  | 47 | +    @classmethod | 
|  | 48 | +    def tearDownClass(self): | 
|  | 49 | +        self.con.close() | 
|  | 50 | +        self.srv.stop() | 
|  | 51 | +        self.srv.clean() | 
|  | 52 | + | 
|  | 53 | +    def test_rowcount(self): | 
|  | 54 | +        con = self._connect() | 
|  | 55 | +        try: | 
|  | 56 | +            cur = con.cursor() | 
|  | 57 | +            self.executeDDL1(cur) | 
|  | 58 | +            dbapi20._failUnless(self,cur.rowcount in (-1, 1), | 
|  | 59 | +                'cursor.rowcount should be -1 or 1 after executing no-result ' | 
|  | 60 | +                'statements' + str(cur.rowcount) | 
|  | 61 | +                ) | 
|  | 62 | +            cur.execute("%s into %sbooze values ('Victoria Bitter')" % ( | 
|  | 63 | +                self.insert, self.table_prefix | 
|  | 64 | +                )) | 
|  | 65 | +            dbapi20._failUnless(self,cur.rowcount == 1, | 
|  | 66 | +                'cursor.rowcount should == number or rows inserted, or ' | 
|  | 67 | +                'set to -1 after executing an insert statement' | 
|  | 68 | +                ) | 
|  | 69 | +            cur.execute("select name from %sbooze" % self.table_prefix) | 
|  | 70 | +            dbapi20._failUnless(self,cur.rowcount == -1, | 
|  | 71 | +                'cursor.rowcount should == number of rows returned, or ' | 
|  | 72 | +                'set to -1 after executing a select statement' | 
|  | 73 | +                ) | 
|  | 74 | +            self.executeDDL2(cur) | 
|  | 75 | +            dbapi20._failUnless(self,cur.rowcount in (-1, 1), | 
|  | 76 | +                'cursor.rowcount should be -1 or 1 after executing no-result ' | 
|  | 77 | +                'statements' | 
|  | 78 | +                ) | 
|  | 79 | +        finally: | 
|  | 80 | +            con.close() | 
|  | 81 | + | 
|  | 82 | +    @unittest.skip('Not implemented') | 
|  | 83 | +    def test_Binary(self): | 
|  | 84 | +        pass | 
|  | 85 | + | 
|  | 86 | +    @unittest.skip('Not implemented') | 
|  | 87 | +    def test_STRING(self): | 
|  | 88 | +        pass | 
|  | 89 | + | 
|  | 90 | +    @unittest.skip('Not implemented') | 
|  | 91 | +    def test_BINARY(self): | 
|  | 92 | +        pass | 
|  | 93 | + | 
|  | 94 | +    @unittest.skip('Not implemented') | 
|  | 95 | +    def test_NUMBER(self): | 
|  | 96 | +        pass | 
|  | 97 | + | 
|  | 98 | +    @unittest.skip('Not implemented') | 
|  | 99 | +    def test_DATETIME(self): | 
|  | 100 | +        pass | 
|  | 101 | + | 
|  | 102 | +    @unittest.skip('Not implemented') | 
|  | 103 | +    def test_ROWID(self): | 
|  | 104 | +        pass | 
|  | 105 | + | 
|  | 106 | +    @unittest.skip('Not implemented') | 
|  | 107 | +    def test_Date(self): | 
|  | 108 | +        pass | 
|  | 109 | + | 
|  | 110 | +    @unittest.skip('Not implemented') | 
|  | 111 | +    def test_Time(self): | 
|  | 112 | +        pass | 
|  | 113 | + | 
|  | 114 | +    @unittest.skip('Not implemented') | 
|  | 115 | +    def test_Timestamp(self): | 
|  | 116 | +        pass | 
|  | 117 | + | 
|  | 118 | +    @unittest.skip('Not implemented as optional.') | 
|  | 119 | +    def test_nextset(self): | 
|  | 120 | +        pass | 
|  | 121 | + | 
|  | 122 | +    @unittest.skip('Not implemented') | 
|  | 123 | +    def test_callproc(self): | 
|  | 124 | +        pass | 
|  | 125 | + | 
|  | 126 | +    def test_setoutputsize(self):  # Do nothing | 
|  | 127 | +        pass | 
|  | 128 | + | 
|  | 129 | +    @unittest.skip('Not implemented') | 
|  | 130 | +    def test_description(self): | 
|  | 131 | +        pass | 
0 commit comments