Add test for PgManager.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/TESTS Tue Dec 06 17:11:21 2011 +0100
@@ -0,0 +1,15 @@
+TESTS
+=====
+
+All test should work at least with Python 2.6, 2.7 and 3.2
+
+
+How to test
+-----------
+
+1. Copy tests.conf.example to tests.conf and modify it so it points to your test database.
+
+2. Create test tables using tests.sql
+
+3. Run individual tests.
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/config.py Tue Dec 06 17:11:21 2011 +0100
@@ -0,0 +1,10 @@
+import sys
+
+sys.path.insert(0, '..')
+
+
+class Config(dict):
+ def __init__(self, fname):
+ data = open(fname).read()
+ exec(data, dict(), self)
+
--- a/tests/delayedquery.py Tue Dec 06 16:45:29 2011 +0100
+++ b/tests/delayedquery.py Tue Dec 06 17:11:21 2011 +0100
@@ -3,16 +3,11 @@
import logging
import time
+from config import Config
from pgtoolkit import pgmanager
from pgtoolkit.delayedquery import DelayedQuery
-class Config(dict):
- def __init__(self, fname):
- data = open(fname).read()
- exec(data, dict(), self)
-
-
if __name__ == '__main__':
cfg = Config('tests.conf')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/testpgmanager.py Tue Dec 06 17:11:21 2011 +0100
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+import unittest
+
+from config import Config
+from pgtoolkit import pgmanager
+
+
+class TestSuite(unittest.TestCase):
+
+ def setUp(self):
+ cfg = Config('tests.conf')
+ self.m = pgmanager.get_instance()
+ self.m.create_conn(**cfg)
+ self.m.create_conn('autocommit', isolation_level='autocommit', **cfg)
+
+ def tearDown(self):
+ self.m.destroy_conn()
+ self.m.destroy_conn('autocommit')
+
+ def test_connection_get_put(self):
+ conn = self.m.get_conn()
+
+ curs = conn.cursor()
+ curs.execute('SELECT %s AS t', [True])
+ d = curs.fetchone_dict()
+ self.assertTrue(d.t)
+
+ self.m.put_conn(conn)
+
+ def test_connection_with(self):
+ with self.m.cursor() as curs:
+ curs.execute('SELECT %s AS t', [True])
+ d = curs.fetchone_dict()
+ self.assertTrue(d.t)
+
+ def test_connection_autocommit(self):
+ conn = self.m.get_conn('autocommit')
+ curs = conn.cursor()
+ name = 'test'
+ curs.execute('DELETE FROM test WHERE name = %s', [name])
+ curs.execute('INSERT INTO test (name) VALUES (%s)', [name])
+ conn.close()
+
+ conn = self.m.get_conn('autocommit')
+ curs = conn.cursor()
+ curs.execute('SELECT * FROM test WHERE name = %s', [name])
+ self.assertTrue(curs.rowcount == 1)
+ self.m.put_conn(conn)
+
+if __name__ == '__main__':
+ unittest.main()
+