2008-04-21 Jorgen Austvik <Jorgen.Austvik@sun.com>

* 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.
This commit is contained in:
James Henstridge 2008-04-20 23:12:21 +00:00
parent 962c5a9a5f
commit 2f3f4c1258
9 changed files with 28 additions and 9 deletions

View File

@ -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.

View File

@ -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

View File

@ -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)")

View File

@ -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()

View File

@ -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]

View File

@ -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

View File

@ -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()

View File

@ -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):

View File

@ -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()