Skip to content

Commit e60813f

Browse files
committed
Add unit tests for dbapi module
used dbapi-compliance package to test module according to pep-249 specification removed EOL python 3.4 from appveyor test used installer.sh from tarantool.io to set up Tarantool 2.4 version in test.sh
1 parent 4d40f07 commit e60813f

File tree

4 files changed

+131
-8
lines changed

4 files changed

+131
-8
lines changed

Diff for: appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ install:
2121
# install runtime dependencies
2222
- "%PYTHON%\\python.exe -m pip install -r requirements.txt"
2323
# install testing dependencies
24-
- "%PYTHON%\\python.exe -m pip install pyyaml%PYYAML%"
24+
- "%PYTHON%\\python.exe -m pip install pyyaml%PYYAML% dbapi-compliance==1.15.0"
2525

2626
build: off
2727

Diff for: test.sh

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
set -exu # Strict shell (w/o -o pipefail)
44

55
# Install tarantool.
6-
curl http://download.tarantool.org/tarantool/2x/gpgkey | sudo apt-key add -
7-
release=`lsb_release -c -s`
8-
echo "deb http://download.tarantool.org/tarantool/2x/ubuntu/ ${release} main" | sudo tee /etc/apt/sources.list.d/tarantool_2x.list
9-
sudo apt-get update > /dev/null
10-
sudo apt-get -q -y install tarantool
6+
curl -L https://tarantool.io/installer.sh | VER=2.4 sudo -E bash
117

128
# Install testing dependencies.
139
pip install -r requirements.txt
14-
pip install pyyaml
10+
pip install pyyaml dbapi-compliance==1.15.0
1511

1612
# Run tests.
1713
python setup.py test

Diff for: unit/suites/__init__.py

+2-1
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()

Diff for: unit/suites/test_dbapi.py

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

0 commit comments

Comments
 (0)