Changeset 667


Ignore:
Timestamp:
Dec 23, 2015, 10:53:02 AM (4 years ago)
Author:
cito
Message:

More sophisticated creation of missing database

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.x/module/tests/test_dbapi20.py

    r666 r667  
    4343            con = self._connect()
    4444            con.close()
    45         except pgdb.Error:
     45        except pgdb.Error:  # try to create a missing database
    4646            import pg
    47             pg.DB('postgres',dbhost,dbport).query('create database ' + dbname)
     47            try:  # first try to log in as superuser
     48                db = pg.DB('postgres', dbhost or None, dbport or -1,
     49                    user='postgres')
     50            except Exception:  # then try to log in as current user
     51                db = pg.DB('postgres', dbhost or None, dbport or -1)
     52            db.query('create database ' + dbname)
     53
    4854
    4955    def tearDown(self):
  • trunk/module/tests/test_dbapi20.py

    r665 r667  
    5050            con = self._connect()
    5151            con.close()
    52         except pgdb.Error:
     52        except pgdb.Error:  # try to create a missing database
     53            warning.
    5354            import pg
    54             pg.DB().query('create database ' + dbname)
     55            try:  # first try to log in as superuser
     56                db = pg.DB('postgres', dbhost or None, dbport or -1,
     57                    user='postgres')
     58            except Exception:  # then try to log in as current user
     59                db = pg.DB('postgres', dbhost or None, dbport or -1)
     60            db.query('create database ' + dbname)
    5561
    5662    def tearDown(self):
Note: See TracChangeset for help on using the changeset viewer.