Skip to content

Commit 8ffb44e

Browse files
committed
Add unit tests for dbapi module
Used dbapi-compliance [1] package to test module according to pep-249 specification. Not implemented features are skipped in the tests. Added dbapi-compliance package to test.sh requirements and appveyor.yml [1] https://github.com/baztian/dbapi-compliance/
1 parent 282419d commit 8ffb44e

File tree

4 files changed

+134
-3
lines changed

4 files changed

+134
-3
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ install:
2323
# install runtime dependencies
2424
- "%PYTHON%\\python.exe -m pip install -r requirements.txt"
2525
# install testing dependencies
26-
- "%PYTHON%\\python.exe -m pip install pyyaml%PYYAML%"
26+
- "%PYTHON%\\python.exe -m pip install pyyaml%PYYAML% dbapi-compliance==1.15.0"
2727

2828
build: off
2929

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sudo apt-get -q -y install tarantool
1111

1212
# Install testing dependencies.
1313
pip install -r requirements.txt
14-
pip install pyyaml
14+
pip install pyyaml dbapi-compliance==1.15.0
1515

1616
# Run tests.
1717
python setup.py test

unit/suites/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from .test_protocol import TestSuite_Protocol
1010
from .test_reconnect import TestSuite_Reconnect
1111
from .test_mesh import TestSuite_Mesh
12+
from .test_dbapi import TestSuite_DBAPI
1213

1314
test_cases = (TestSuite_Schema, TestSuite_Request, TestSuite_Protocol,
14-
TestSuite_Reconnect, TestSuite_Mesh)
15+
TestSuite_Reconnect, TestSuite_Mesh, TestSuite_DBAPI)
1516

1617
def load_tests(loader, tests, pattern):
1718
suite = unittest.TestSuite()

unit/suites/test_dbapi.py

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

0 commit comments

Comments
 (0)