From f16faadec18207e9e4bb19c7de1cfcce5e92b192 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 11 Feb 2021 20:42:22 +0100 Subject: [PATCH] Test server-side cursor hold --- tests/test_server_cursor.py | 18 ++++++++++++++++++ tests/test_server_cursor_async.py | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tests/test_server_cursor.py b/tests/test_server_cursor.py index 09ae7bac4..551579e95 100644 --- a/tests/test_server_cursor.py +++ b/tests/test_server_cursor.py @@ -238,6 +238,24 @@ def test_non_scrollable(conn): curs.scroll(-1) +@pytest.mark.parametrize("kwargs", [{}, {"hold": False}]) +def test_no_hold(conn, kwargs): + with pytest.raises(e.InvalidCursorName): + with conn.cursor("foo") as curs: + curs.execute("select generate_series(0, 2)", **kwargs) + assert curs.fetchone() == (0,) + conn.commit() + curs.fetchone() + + +def test_hold(conn): + with conn.cursor("foo") as curs: + curs.execute("select generate_series(0, 5)", hold=True) + assert curs.fetchone() == (0,) + conn.commit() + assert curs.fetchone() == (1,) + + def test_steal_cursor(conn): cur1 = conn.cursor() cur1.execute("declare test cursor for select generate_series(1, 6)") diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py index 8326578d6..fa2d9425c 100644 --- a/tests/test_server_cursor_async.py +++ b/tests/test_server_cursor_async.py @@ -245,6 +245,24 @@ async def test_non_scrollable(aconn): await curs.scroll(-1) +@pytest.mark.parametrize("kwargs", [{}, {"hold": False}]) +async def test_no_hold(aconn, kwargs): + with pytest.raises(e.InvalidCursorName): + async with aconn.cursor("foo") as curs: + await curs.execute("select generate_series(0, 2)", **kwargs) + assert await curs.fetchone() == (0,) + await aconn.commit() + await curs.fetchone() + + +async def test_hold(aconn): + async with aconn.cursor("foo") as curs: + await curs.execute("select generate_series(0, 5)", hold=True) + assert await curs.fetchone() == (0,) + await aconn.commit() + assert await curs.fetchone() == (1,) + + async def test_steal_cursor(aconn): cur1 = aconn.cursor() await cur1.execute( -- 2.47.2