summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2015-06-02 17:02:04 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2015-06-02 17:02:04 +0100
commit1f330e9cac9c5d40c33f4f58d0dbfc0109c62edc (patch)
tree0e4d67997ee734ac3025774a163c031e8a217b7b /tests
parent2ad82b973b86fa71126657aacee89a30d2211894 (diff)
downloadpsycopg2-1f330e9cac9c5d40c33f4f58d0dbfc0109c62edc.tar.gz
Allow connection.notices and notifies to be replaced.
Close #326
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_connection.py36
-rwxr-xr-xtests/test_notify.py22
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/test_connection.py b/tests/test_connection.py
index 340693e..fa78eb3 100755
--- a/tests/test_connection.py
+++ b/tests/test_connection.py
@@ -129,6 +129,42 @@ class ConnectionTests(ConnectingTestCase):
self.assertEqual(50, len(conn.notices))
self.assert_('table99' in conn.notices[-1], conn.notices[-1])
+ def test_notices_deque(self):
+ from collections import deque
+
+ conn = self.conn
+ self.conn.notices = deque()
+ cur = conn.cursor()
+ if self.conn.server_version >= 90300:
+ cur.execute("set client_min_messages=debug1")
+
+ cur.execute("create temp table table1 (id serial); create temp table table2 (id serial);")
+ cur.execute("create temp table table3 (id serial); create temp table table4 (id serial);")
+ self.assertEqual(len(conn.notices), 4)
+ self.assert_('table1' in conn.notices.popleft())
+ self.assert_('table2' in conn.notices.popleft())
+ self.assert_('table3' in conn.notices.popleft())
+ self.assert_('table4' in conn.notices.popleft())
+ self.assertEqual(len(conn.notices), 0)
+
+ # not limited, but no error
+ for i in range(0, 100, 10):
+ sql = " ".join(["create temp table table2_%d (id serial);" % j for j in range(i, i+10)])
+ cur.execute(sql)
+
+ self.assertEqual(100, len(conn.notices))
+
+ def test_notices_noappend(self):
+ conn = self.conn
+ self.conn.notices = None # will make an error swallowes ok
+ cur = conn.cursor()
+ if self.conn.server_version >= 90300:
+ cur.execute("set client_min_messages=debug1")
+
+ cur.execute("create temp table table1 (id serial);")
+
+ self.assertEqual(self.conn.notices, None)
+
def test_server_version(self):
self.assert_(self.conn.server_version)
diff --git a/tests/test_notify.py b/tests/test_notify.py
index f838389..fc6224d 100755
--- a/tests/test_notify.py
+++ b/tests/test_notify.py
@@ -155,6 +155,27 @@ conn.close()
self.assertEqual('foo', notify.channel)
self.assertEqual('Hello, world!', notify.payload)
+ def test_notify_deque(self):
+ from collections import deque
+ self.autocommit(self.conn)
+ self.conn.notifies = deque()
+ self.listen('foo')
+ self.notify('foo').communicate()
+ time.sleep(0.5)
+ self.conn.poll()
+ notify = self.conn.notifies.popleft()
+ self.assert_(isinstance(notify, psycopg2.extensions.Notify))
+ self.assertEqual(len(self.conn.notifies), 0)
+
+ def test_notify_noappend(self):
+ self.autocommit(self.conn)
+ self.conn.notifies = None
+ self.listen('foo')
+ self.notify('foo').communicate()
+ time.sleep(0.5)
+ self.conn.poll()
+ self.assertEqual(self.conn.notifies, None)
+
def test_notify_init(self):
n = psycopg2.extensions.Notify(10, 'foo')
self.assertEqual(10, n.pid)
@@ -192,6 +213,7 @@ conn.close()
self.assertNotEqual(hash(Notify(10, 'foo', 'bar')),
hash(Notify(10, 'foo')))
+
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)