def test_datatore_tuple(self): conn = DataStoreFactory('pg:chula@localhost/chula_test', 'chula') cursor = conn.cursor(type='tuple') try: cursor.execute('SELECT * FROM cars LIMIT 1;') values = cursor.fetchone() self.assertEquals(values, (1, 'Honda', 'Civic')) finally: conn.rollback() conn.close()
def test_datatore_basic(self): conn = DataStoreFactory('pg:chula@localhost/chula_test', 'chula') cursor = conn.cursor() try: cursor.execute('SELECT * FROM cars LIMIT 1;') keys = cursor.fetchone().keys() keys.sort() self.assertEquals(keys, ['make', 'model', 'uid']) finally: conn.rollback() conn.close()
class Backend(base.Backend): def __init__(self, config, guid): super(Backend, self).__init__(config, guid) self.cursor = None self.log = logger.Logger(config).logger('chula.session.postgresql') self.connect() def connect(self): if self.conn is None: uri = 'pg:%(session_username)s@%(session_host)s/%(session_db)s' uri = uri % self.config try: self.conn = DataStoreFactory(uri, self.config.session_password) except Exception, ex: self.log.error('Unable to connect', exc_info=True, extra=EXTRA) try: self.cursor = self.conn.cursor() except Exception, ex: self.log.error('Cursor error', exc_info=True, extra=EXTRA) if not self.conn is None and not self.cursor is None: self.log.debug('Successfull connection to postgresql')