diff --git a/ChangeLog b/ChangeLog index 7306f22d..640f0765 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-04-21 James Henstridge + + * tests/*.py: use the DSN constructed in tests/__init__.py. + + * tests/__init__.py: allow setting the host, port and user for the + DSN used by the tests through the environment. + 2008-03-17 Federico Di Gregorio * Release 2.0.7. diff --git a/tests/__init__.py b/tests/__init__.py index 89dbfdaa..83a0be1a 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -3,6 +3,18 @@ import os import unittest dbname = os.environ.get('PSYCOPG2_TESTDB', 'psycopg2_test') +dbhost = os.environ.get('PSYCOPG2_TESTDB_HOST', None) +dbport = os.environ.get('PSYCOPG2_TESTDB_PORT', None) +dbuser = os.environ.get('PSYCOPG2_TESTDB_USER', None) + +# Construct a DSN to connect to the test database: +dsn = 'dbname=%s' % dbname +if dbhost is not None: + dsn += ' host=%s' % dbhost +if dbport is not None: + dsn += ' port=%s' % dbport +if dbuser is not None: + dsn += ' user=%s' % dbuser import bugX000 import extras_dictcursor diff --git a/tests/extras_dictcursor.py b/tests/extras_dictcursor.py index c8e2222d..323cc93f 100755 --- a/tests/extras_dictcursor.py +++ b/tests/extras_dictcursor.py @@ -24,7 +24,7 @@ class ExtrasDictCursorTests(unittest.TestCase): """Test if DictCursor extension class works.""" def setUp(self): - self.conn = psycopg2.connect("dbname=%s" % tests.dbname) + self.conn = psycopg2.connect(tests.dsn) curs = self.conn.cursor() curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)") diff --git a/tests/test_connection.py b/tests/test_connection.py index 0fe73a91..306c7c36 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -8,7 +8,7 @@ import tests class ConnectionTests(unittest.TestCase): def connect(self): - return psycopg2.connect("dbname=%s" % tests.dbname) + return psycopg2.connect(tests.dsn) def test_closed_attribute(self): conn = self.connect() diff --git a/tests/test_dates.py b/tests/test_dates.py index 303391b2..7c555558 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -9,7 +9,7 @@ import tests class CommonDatetimeTestsMixin: def execute(self, *args): - conn = psycopg2.connect("dbname=%s" % tests.dbname) + conn = psycopg2.connect(tests.dsn) curs = conn.cursor() curs.execute(*args) return curs.fetchone()[0] diff --git a/tests/test_psycopg2_dbapi20.py b/tests/test_psycopg2_dbapi20.py index 1d1b03e9..9b6b1192 100755 --- a/tests/test_psycopg2_dbapi20.py +++ b/tests/test_psycopg2_dbapi20.py @@ -9,7 +9,7 @@ import tests class Psycopg2TestCase(dbapi20.DatabaseAPI20Test): driver = psycopg2 connect_args = () - connect_kw_args = {'dsn': 'dbname=%s' % tests.dbname} + connect_kw_args = {'dsn': tests.dsn} lower_func = 'lower' # For stored procedure test diff --git a/tests/test_quote.py b/tests/test_quote.py index 0603032b..62e7776f 100755 --- a/tests/test_quote.py +++ b/tests/test_quote.py @@ -23,7 +23,7 @@ class QuotingTestCase(unittest.TestCase): http://www.postgresql.org/docs/8.1/static/runtime-config-compatible.html """ def setUp(self): - self.conn = psycopg2.connect("dbname=%s" % tests.dbname) + self.conn = psycopg2.connect(tests.dsn) def tearDown(self): self.conn.close() diff --git a/tests/test_transaction.py b/tests/test_transaction.py index 5145ace0..95175412 100755 --- a/tests/test_transaction.py +++ b/tests/test_transaction.py @@ -11,7 +11,7 @@ import tests class TransactionTests(unittest.TestCase): def setUp(self): - self.conn = psycopg2.connect("dbname=%s" % tests.dbname) + self.conn = psycopg2.connect(tests.dsn) self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) curs = self.conn.cursor() curs.execute(''' @@ -75,7 +75,7 @@ class DeadlockSerializationTests(unittest.TestCase): """Test deadlock and serialization failure errors.""" def connect(self): - conn = psycopg2.connect("dbname=%s" % tests.dbname) + conn = psycopg2.connect(tests.dsn) conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) return conn @@ -208,7 +208,7 @@ class QueryCancelationTests(unittest.TestCase): """Tests for query cancelation.""" def setUp(self): - self.conn = psycopg2.connect("dbname=%s" % tests.dbname) + self.conn = psycopg2.connect(tests.dsn) self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) def test_statement_timeout(self): diff --git a/tests/types_basic.py b/tests/types_basic.py index 58897b18..160455ec 100755 --- a/tests/types_basic.py +++ b/tests/types_basic.py @@ -28,7 +28,7 @@ class TypesBasicTests(unittest.TestCase): """Test presence of mandatory attributes and methods.""" def setUp(self): - self.conn = psycopg2.connect("dbname=%s" % tests.dbname) + self.conn = psycopg2.connect(tests.dsn) def execute(self, *args): curs = self.conn.cursor()