summaryrefslogtreecommitdiffstats
path: root/tests/test_pgexecute.py
diff options
context:
space:
mode:
authorIrina Truong <i.chernyavska@gmail.com>2021-05-21 15:32:34 -0700
committerGitHub <noreply@github.com>2021-05-21 15:32:34 -0700
commite0a4c18c4a074016beef46886b03e456102e2db1 (patch)
tree8e0f57064035bd73faab5d4dea3446dc2c5c376c /tests/test_pgexecute.py
parentd8532df22e1f309c8a05a452d752bd30f4869bbe (diff)
Another attempt to fix pgbouncer error (1093.) (#1097)
* Another attempt to fix pgbouncer error (1093.) * Fixes for various pgbouncer problems. * different approach with custom cursor. * Fix rebase. * Missed this. * Fix completion refresher test. * Black. * Unused import. * Changelog. * Fix race condition in test. * Switch from is_pgbouncer to more generic is_virtual_database, and duck-type it. Add very dumb unit test for virtual cursor. * Remove debugger code.
Diffstat (limited to 'tests/test_pgexecute.py')
-rw-r--r--tests/test_pgexecute.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_pgexecute.py b/tests/test_pgexecute.py
index 513e6192..109674cb 100644
--- a/tests/test_pgexecute.py
+++ b/tests/test_pgexecute.py
@@ -520,6 +520,21 @@ class BrokenConnection:
raise psycopg2.InterfaceError("I'm broken!")
+class VirtualCursor:
+ """Mock a cursor to virtual database like pgbouncer."""
+
+ def __init__(self):
+ self.protocol_error = False
+ self.protocol_message = ""
+ self.description = None
+ self.status = None
+ self.statusmessage = "Error"
+
+ def execute(self, *args, **kwargs):
+ self.protocol_error = True
+ self.protocol_message = "Command not supported"
+
+
@dbtest
def test_exit_without_active_connection(executor):
quit_handler = MagicMock()
@@ -542,3 +557,12 @@ def test_exit_without_active_connection(executor):
# an exception should be raised when running a query without active connection
with pytest.raises(psycopg2.InterfaceError):
run(executor, "select 1", pgspecial=pgspecial)
+
+
+@dbtest
+def test_virtual_database(executor):
+ virtual_connection = MagicMock()
+ virtual_connection.cursor.return_value = VirtualCursor()
+ with patch.object(executor, "conn", virtual_connection):
+ result = run(executor, "select 1")
+ assert "Command not supported" in result