author | Radek Brich <radek.brich@devl.cz> |
Sat, 29 Sep 2012 12:08:47 +0200 | |
changeset 48 | b82c7c2fb5af |
parent 37 | 5b0eb4b11940 |
child 49 | 08e4dfe1b0cb |
permissions | -rwxr-xr-x |
37 | 1 |
#!/usr/bin/env python3.2 |
22 | 2 |
|
48
b82c7c2fb5af
PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
37
diff
changeset
|
3 |
from tests.config import Config |
b82c7c2fb5af
PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
37
diff
changeset
|
4 |
from pgtoolkit import pgmanager |
b82c7c2fb5af
PgManager: Fix logging, log queries before executing, possible exceptions are logged after. Add tests for RowDict. Add tests.py - runs all tests.
Radek Brich <radek.brich@devl.cz>
parents:
37
diff
changeset
|
5 |
|
22 | 6 |
import unittest |
7 |
||
8 |
||
9 |
class TestSuite(unittest.TestCase): |
|
10 |
||
11 |
def setUp(self): |
|
12 |
cfg = Config('tests.conf') |
|
13 |
self.m = pgmanager.get_instance() |
|
14 |
self.m.create_conn(**cfg) |
|
15 |
self.m.create_conn('autocommit', isolation_level='autocommit', **cfg) |
|
16 |
||
17 |
def tearDown(self): |
|
18 |
self.m.destroy_conn() |
|
19 |
self.m.destroy_conn('autocommit') |
|
20 |
||
21 |
def test_connection_get_put(self): |
|
22 |
conn = self.m.get_conn() |
|
23 |
||
24 |
curs = conn.cursor() |
|
25 |
curs.execute('SELECT %s AS t', [True]) |
|
26 |
d = curs.fetchone_dict() |
|
27 |
self.assertTrue(d.t) |
|
28 |
||
29 |
self.m.put_conn(conn) |
|
30 |
||
31 |
def test_connection_with(self): |
|
32 |
with self.m.cursor() as curs: |
|
33 |
curs.execute('SELECT %s AS t', [True]) |
|
34 |
d = curs.fetchone_dict() |
|
35 |
self.assertTrue(d.t) |
|
36 |
||
37 |
def test_connection_autocommit(self): |
|
38 |
conn = self.m.get_conn('autocommit') |
|
39 |
curs = conn.cursor() |
|
40 |
name = 'test' |
|
41 |
curs.execute('DELETE FROM test WHERE name = %s', [name]) |
|
42 |
curs.execute('INSERT INTO test (name) VALUES (%s)', [name]) |
|
43 |
conn.close() |
|
44 |
||
45 |
conn = self.m.get_conn('autocommit') |
|
46 |
curs = conn.cursor() |
|
47 |
curs.execute('SELECT * FROM test WHERE name = %s', [name]) |
|
48 |
self.assertTrue(curs.rowcount == 1) |
|
49 |
self.m.put_conn(conn) |
|
50 |
||
51 |
if __name__ == '__main__': |
|
52 |
unittest.main() |
|
53 |