Skip to content

Commit 5160aaf

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 e43e41e commit 5160aaf

File tree

4 files changed

+135
-3
lines changed

4 files changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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 pyyaml dbapi-compliance==1.15.0
2020

2121
# Run tests.
2222
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

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

Comments
 (0)