From 98de226dfd8f1c3df6c82ee5b36b9441fe2514ab Mon Sep 17 00:00:00 2001 From: Taimoor Zaeem Date: Thu, 18 Sep 2025 19:26:58 +0500 Subject: [PATCH] test(io): move reusable functions to postgrest.py Moves the `set_statement_timeout` and `reset_statement_timeout` function to postgrest.py. This cleans up test_io.py so it only contains tests. Also makes these functions reusable in other other tests like test_cli.py. Signed-off-by: Taimoor Zaeem --- test/io/postgrest.py | 17 +++++++++++++++++ test/io/test_io.py | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/test/io/postgrest.py b/test/io/postgrest.py index 5a7379290..66803af98 100644 --- a/test/io/postgrest.py +++ b/test/io/postgrest.py @@ -230,3 +230,20 @@ def is_ipv6(addr): return True except OSError: return False + + +def set_statement_timeout(postgrest, role, milliseconds): + """Set the statement timeout for the given role. + For this to work reliably with low previous timeout settings, + use a postgrest instance that doesn't use the affected role.""" + + response = postgrest.session.post( + "/rpc/set_statement_timeout", data={"role": role, "milliseconds": milliseconds} + ) + assert response.text == "" + assert response.status_code == 204 + + +def reset_statement_timeout(postgrest, role): + "Reset the statement timeout for the given role to the default 0 (no timeout)" + set_statement_timeout(postgrest, role, 0) diff --git a/test/io/test_io.py b/test/io/test_io.py index a997d82dd..2b4c2ba99 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -595,23 +595,6 @@ def test_db_prepared_statements_disable(defaultenv): assert response.text == "false" -def set_statement_timeout(postgrest, role, milliseconds): - """Set the statement timeout for the given role. - For this to work reliably with low previous timeout settings, - use a postgrest instance that doesn't use the affected role.""" - - response = postgrest.session.post( - "/rpc/set_statement_timeout", data={"role": role, "milliseconds": milliseconds} - ) - assert response.text == "" - assert response.status_code == 204 - - -def reset_statement_timeout(postgrest, role): - "Reset the statement timeout for the given role to the default 0 (no timeout)" - set_statement_timeout(postgrest, role, 0) - - def test_statement_timeout(defaultenv, metapostgrest): "Statement timeout times out slow statements"