From 4e74d749ab435d31138b8ea40a1d39d4fc3f71d5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 10 Feb 2021 02:05:31 +0100 Subject: [PATCH] Add scrollable tests --- tests/test_named_cursor.py | 18 ++++++++++++++++++ tests/test_named_cursor_async.py | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tests/test_named_cursor.py b/tests/test_named_cursor.py index 2961d96cb..252bb88b6 100644 --- a/tests/test_named_cursor.py +++ b/tests/test_named_cursor.py @@ -148,3 +148,21 @@ def test_scroll(conn): with pytest.raises(ValueError): cur.scroll(9, mode="wat") + + +def test_scrollable(conn): + curs = conn.cursor("foo") + curs.execute("select generate_series(0, 5)") + curs.scroll(5) + for i in range(4, -1, -1): + curs.scroll(-1) + assert i == curs.fetchone()[0] + curs.scroll(-1) + + +def test_non_scrollable(conn): + curs = conn.cursor("foo") + curs.execute("select generate_series(0, 5)", scrollable=False) + curs.scroll(5) + with pytest.raises(conn.OperationalError): + curs.scroll(-1) diff --git a/tests/test_named_cursor_async.py b/tests/test_named_cursor_async.py index 1dd643b41..568b31201 100644 --- a/tests/test_named_cursor_async.py +++ b/tests/test_named_cursor_async.py @@ -155,3 +155,21 @@ async def test_scroll(aconn): with pytest.raises(ValueError): await cur.scroll(9, mode="wat") + + +async def test_scrollable(aconn): + curs = await aconn.cursor("foo") + await curs.execute("select generate_series(0, 5)") + await curs.scroll(5) + for i in range(4, -1, -1): + await curs.scroll(-1) + assert i == (await curs.fetchone())[0] + await curs.scroll(-1) + + +async def test_non_scrollable(aconn): + curs = await aconn.cursor("foo") + await curs.execute("select generate_series(0, 5)", scrollable=False) + await curs.scroll(5) + with pytest.raises(aconn.OperationalError): + await curs.scroll(-1) -- 2.47.2