From 0435320f34c56ced8c15899053920fc94fd4f3d7 Mon Sep 17 00:00:00 2001 From: Oleksandr Shulgin Date: Fri, 16 Oct 2015 16:36:03 +0200 Subject: [PATCH] Fix PSYCOPG2_TEST_REPL_DSN handling. --- tests/test_replication.py | 16 ++++++++++++++++ tests/testconfig.py | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_replication.py b/tests/test_replication.py index 231bcd08..dfe11af0 100644 --- a/tests/test_replication.py +++ b/tests/test_replication.py @@ -33,6 +33,9 @@ from testutils import ConnectingTestCase class ReplicationTestCase(ConnectingTestCase): def setUp(self): + from testconfig import repl_dsn + if not repl_dsn: + self.skipTest("replication tests disabled by default") super(ReplicationTestCase, self).setUp() self._slots = [] @@ -99,6 +102,19 @@ class ReplicationTest(ReplicationTestCase): self.create_replication_slot(cur, slot) self.assertRaises(psycopg2.ProgrammingError, self.create_replication_slot, cur, slot) + @skip_before_postgres(9, 4) # slots require 9.4 + def test_start_on_missing_replication_slot(self): + conn = self.repl_connect(connection_factory=PhysicalReplicationConnection) + if conn is None: return + cur = conn.cursor() + + slot = "test_slot1" + + self.assertRaises(psycopg2.ProgrammingError, cur.start_replication, slot) + + self.create_replication_slot(cur, slot) + cur.start_replication(slot) + class AsyncReplicationTest(ReplicationTestCase): @skip_before_postgres(9, 4) diff --git a/tests/testconfig.py b/tests/testconfig.py index d59e5a0d..841eaf1c 100644 --- a/tests/testconfig.py +++ b/tests/testconfig.py @@ -33,4 +33,8 @@ if dbuser is not None: if dbpass is not None: dsn += ' password=%s' % dbpass -repl_dsn = os.environ.get('PSYCOPG2_TEST_REPL_DSN', dsn) +# Don't run replication tests if REPL_DSN is not set, default to normal DSN if +# set to empty string. +repl_dsn = os.environ.get('PSYCOPG2_TEST_REPL_DSN', None) +if repl_dsn == '': + repl_dsn = dsn