Setting connection parameters in tests
Jorgen Austvik - Sun Norway <Jorgen.Austvik-UdXhSnd/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, when running the tests in psycopg/tests, the database name, database host, port number and user name are hard coded. The attached patches let you change the default with environment variables, which is nice to have if you e.g. want to test in client/server environment over a network. I have used environment variable names from here: http://www.postgresql.org/docs/8.2/interactive/app-psql.html An alternative implementation would be to place this functionality into the driver itself. What do you think? -J -- Jørgen Austvik, Software Engineering - QA Sun Microsystems Database Technology Group Sun Microsystems AS Haakon VII gt. 7b N-7485 Trondheim, Norway Phone +47 73 84 21 10 Fax +47 73 84 21 01 Mobile +47 90 19 78 86 _______________________________________________ Psycopg mailing list Psycopg-IAPFreCvJWPBWskQ1e/[email protected] http://lists.initd.org/mailman/listinfo/psycopg
extras_dictcursor.py.patch
(text/x-patch, 818 B)
--- extras_dictcursor.py.orig Fri Apr 11 12:12:11 2008
+++ extras_dictcursor.py Mon Apr 7 14:07:38 2008
@@ -14,6 +14,7 @@
import psycopg2
import psycopg2.extras
+import os
from unittest import TestCase, TestSuite, main
@@ -21,7 +22,11 @@
"""Test if DictCursor extension class works."""
def setUp(self):
- self.conn = psycopg2.connect("dbname=test")
+ port = os.environ.get("PGPORT", 5432)
+ hostname = os.environ.get("PGHOST", "localhost")
+ username = os.environ.get("PGUSER", "postgres")
+ dbname = os.environ.get("PGDATABASE", "test")
+ self.conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(dbname, hostname, port, username))
curs = self.conn.cursor()
curs.execute("CREATE TABLE ExtrasDictCursorTests (foo text)")
test_psycopg2_dbapi20.py.patch
(text/x-patch, 1.1 KB)
--- test_psycopg2_dbapi20.py.orig Fri Apr 11 12:12:19 2008
+++ test_psycopg2_dbapi20.py Mon Apr 7 14:21:39 2008
@@ -1,5 +1,6 @@
#!/usr/bin/env python
import dbapi20
+import os
import unittest
import psycopg2
import popen2
@@ -6,8 +7,14 @@
class test_Psycopg(dbapi20.DatabaseAPI20Test):
driver = psycopg2
+ port = os.environ.get("PGPORT", 5432)
+ hostname = os.environ.get("PGHOST", "localhost")
+ username = os.environ.get("PGUSER", "postgres")
+ dbname = os.environ.get("PGDATABASE", "dbapi20_test")
+ dsn = "dbname=%s host=%s port=%s user=%s" %(dbname, hostname, port, username)
+
connect_args = ()
- connect_kw_args = {'dsn': 'dbname=dbapi20_test'}
+ connect_kw_args = {'dsn': dsn}
lower_func = 'lower' # For stored procedure test
@@ -20,7 +27,7 @@
con = self._connect()
con.close()
except:
- cmd = "psql -c 'create database dbapi20_test' template1"
+ cmd = "psql -c 'create database %s' template1" %(dbname)
cout,cin = popen2.popen2(cmd)
cin.close()
cout.read()
types_basic.py.patch
(text/x-patch, 764 B)
--- types_basic.py.orig Fri Apr 11 12:12:27 2008
+++ types_basic.py Thu Apr 10 13:26:38 2008
@@ -18,6 +18,7 @@
except:
pass
import psycopg2
+import os
from unittest import TestCase, TestSuite, main
@@ -25,8 +26,12 @@
"""Test presence of mandatory attributes and methods."""
def setUp(self):
- self.conn = psycopg2.connect("dbname=test")
+ port = os.environ.get("PGPORT", 5432)
+ hostname = os.environ.get("PGHOST", "localhost")
+ username = os.environ.get("PGUSER", "postgres")
+ dbname = os.environ.get("PGDATABASE", "test")
+ self.conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(dbname, hostname, port, username))
def execute(self, *args):
curs = self.conn.cursor()
jorgen_austvik.vcf
(text/x-vcard, 411 B)
begin:vcard fn;quoted-printable:J=C3=B8rgen Austvik n;quoted-printable:Austvik;J=C3=B8rgen org:Sun Microsystems;Database Technology Group adr:;;Haakon VII gt. 7b;Trondheim;;NO-7485;Norway email;internet:[email protected] title:Senior Engineer tel;work:+47 73 84 21 10 tel;fax:+47 73 84 21 01 tel;cell:+47 901 97 886 x-mozilla-html:FALSE url:http://www.sun.com/ version:2.1 end:vcard