Skip to content

Commit 07b8109

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 adf68a5 commit 07b8109

File tree

4 files changed

+144
-3
lines changed

4 files changed

+144
-3
lines changed

appveyor.yml

+1-1
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pip install "${PYTHON_MSGPACK:-msgpack==1.0.0}"
1616
python -c 'import msgpack; print(msgpack.version)'
1717

1818
# Install testing dependencies.
19-
pip install pyyaml
19+
pip install -r requirements.txt
20+
pip install pyyaml dbapi-compliance==1.15.0
2021

2122
# Run tests.
2223
python setup.py test

unit/suites/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
from .test_reconnect import TestSuite_Reconnect
1212
from .test_mesh import TestSuite_Mesh
1313
from .test_execute import TestSuite_Execute
14+
from .test_dbapi import TestSuite_DBAPI
1415

1516
test_cases = (TestSuite_Schema_UnicodeConnection,
1617
TestSuite_Schema_BinaryConnection,
1718
TestSuite_Request, TestSuite_Protocol, TestSuite_Reconnect,
18-
TestSuite_Mesh, TestSuite_Execute)
19+
TestSuite_Mesh, TestSuite_Execute, TestSuite_DBAPI)
1920

2021
def load_tests(loader, tests, pattern):
2122
suite = unittest.TestSuite()

unit/suites/test_dbapi.py

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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

Comments
 (0)