From: Daniele Varrazzo Date: Thu, 11 Feb 2021 19:42:22 +0000 (+0100) Subject: Test server-side cursor hold X-Git-Tag: 3.0.dev0~115^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f16faadec18207e9e4bb19c7de1cfcce5e92b192;p=thirdparty%2Fpsycopg.git Test server-side cursor hold --- 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(