From d074b096be7f60d96bfaf6257fad63743f4c2855 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 15 Aug 2012 01:11:26 +0100 Subject: [PATCH] Added test for scrollable cursor --- tests/test_cursor.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/test_cursor.py b/tests/test_cursor.py index b1c5c5c3..dc2d4660 100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -213,6 +213,45 @@ class CursorTests(unittest.TestCase): curs.execute("drop table withhold") self.conn.commit() + def test_scrollable(self): + self.assertRaises(psycopg2.ProgrammingError, self.conn.cursor, + scrollable=True) + + curs = self.conn.cursor() + curs.execute("create table scrollable (data int)") + curs.executemany("insert into scrollable values (%s)", + [ (i,) for i in range(100) ]) + curs.close() + + for t in range(2): + if not t: + curs = self.conn.cursor("S") + self.assertEqual(curs.scrollable, False); + curs.scrollable = True + else: + curs = self.conn.cursor("S", scrollable=True) + + self.assertEqual(curs.scrollable, True); + curs.itersize = 10 + + # complex enough to make postgres cursors declare without + # scroll/no scroll to fail + curs.execute(""" + select x.data + from scrollable x + join scrollable y on x.data = y.data + order by y.data""") + for i, (n,) in enumerate(curs): + self.assertEqual(i, n) + + curs.scroll(-1) + for i in range(99, -1, -1): + curs.scroll(-1) + self.assertEqual(i, curs.fetchone()[0]) + curs.scroll(-1) + + curs.close() + @skip_before_postgres(8, 2) def test_iter_named_cursor_efficient(self): curs = self.conn.cursor('tmp')