Author: cito
Date: Wed Dec 23 10:53:02 2015
New Revision: 667
Log:
More sophisticated creation of missing database
Modified:
branches/4.x/module/tests/test_dbapi20.py
trunk/module/tests/test_dbapi20.py
Modified: branches/4.x/module/tests/test_dbapi20.py
==============================================================================
--- branches/4.x/module/tests/test_dbapi20.py Wed Dec 23 10:14:10 2015
(r666)
+++ branches/4.x/module/tests/test_dbapi20.py Wed Dec 23 10:53:02 2015
(r667)
@@ -42,9 +42,15 @@
try:
con = self._connect()
con.close()
- except pgdb.Error:
+ except pgdb.Error: # try to create a missing database
import pg
- pg.DB('postgres',dbhost,dbport).query('create database ' + dbname)
+ try: # first try to log in as superuser
+ db = pg.DB('postgres', dbhost or None, dbport or -1,
+ user='postgres')
+ except Exception: # then try to log in as current user
+ db = pg.DB('postgres', dbhost or None, dbport or -1)
+ db.query('create database ' + dbname)
+
def tearDown(self):
dbapi20.DatabaseAPI20Test.tearDown(self)
Modified: trunk/module/tests/test_dbapi20.py
==============================================================================
--- trunk/module/tests/test_dbapi20.py Wed Dec 23 10:14:10 2015 (r666)
+++ trunk/module/tests/test_dbapi20.py Wed Dec 23 10:53:02 2015 (r667)
@@ -49,9 +49,15 @@
try:
con = self._connect()
con.close()
- except pgdb.Error:
+ except pgdb.Error: # try to create a missing database
+ warning.
import pg
- pg.DB().query('create database ' + dbname)
+ try: # first try to log in as superuser
+ db = pg.DB('postgres', dbhost or None, dbport or -1,
+ user='postgres')
+ except Exception: # then try to log in as current user
+ db = pg.DB('postgres', dbhost or None, dbport or -1)
+ db.query('create database ' + dbname)
def tearDown(self):
dbapi20.DatabaseAPI20Test.tearDown(self)
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql