summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rwxr-xr-xtests/__init__.py12
-rwxr-xr-xtests/extras_dictcursor.py2
-rw-r--r--tests/test_connection.py2
-rw-r--r--tests/test_dates.py2
-rwxr-xr-xtests/test_psycopg2_dbapi20.py2
-rwxr-xr-xtests/test_quote.py2
-rwxr-xr-xtests/test_transaction.py6
-rwxr-xr-xtests/types_basic.py2
9 files changed, 28 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 7306f22..640f076 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-21 James Henstridge <james@jamesh.id.au>
+
+ * 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 <fog@initd.org>
* Release 2.0.7.
diff --git a/tests/__init__.py b/tests/__init__.py
index 89dbfda..83a0be1 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 c8e2222..323cc93 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 0fe73a9..306c7c3 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 303391b..7c55555 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 1d1b03e..9b6b119 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 0603032..62e7776 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 5145ace..9517541 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 58897b1..160455e 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()