Exemplo n.º 1
0
    def empty_cursor_pool(self):
        """This method cleans (rollback) all current transactions over actual
        cursor in order to avoid errors with waiting transactions.
            - request.cr.rollback()

        Also connections on current database's only are closed by the next
        statement
            - dsn = openerp.sql_db.dsn(request.cr.dbname)
            - openerp.sql_db._Pool.close_all(dsn[1])
        Otherwise next error will be trigger
        'InterfaceError: connection already closed'

        Finally new cursor is assigned to the request object, this cursor will
        take the os.environ setted. In this case the os.environ is setted with
        all 'PGOPTIONS' required to log all sql transactions in postgres.log
        file.

        If this method is called one more time, it will create a new cursor and
        take the os.environ again, this is usefully if we want to reset
        'PGOPTIONS'

        """
        request.cr.rollback()
        dsn = sql_db.dsn(request.cr.dbname)
        sql_db._Pool.close_all(dsn[1])
        db = sql_db.db_connect(request.cr.dbname)
        request._cr = db.cursor()
Exemplo n.º 2
0
def local_pgadmin_cursor():
    cnx = None
    try:
        cnx = psycopg2.connect(dsn("postgres")[1])
        cnx.autocommit = True  # required for admin commands
        yield cnx.cursor()
    finally:
        if cnx: cnx.close()
Exemplo n.º 3
0
 def run(self, result):
     # clean slate
     if sql_db._Pool is not None:
         sql_db._Pool.close_all(sql_db.dsn(tools.config['db_name']))
     # check for PhantomJS...
     try:
         subprocess.call([ 'phantomjs', '-v' ], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT)
     except OSError:
         test = WebsiteUiTest('UI Tests')
         result.startTest(test)
         result.addSkip(test, "phantomjs command not found (cf. http://phantomjs.org/)")
         result.stopTest(test)
         return
     # ...then run the actual test
     result._exc_info_to_string = _exc_info_to_string
     try:
         self._run(result)
     finally:
         del result._exc_info_to_string
Exemplo n.º 4
0
 def run(self, result):
     return
     # clean slate
     if sql_db._Pool is not None:
         sql_db._Pool.close_all(sql_db.dsn(tools.config['db_name']))
     # check for PhantomJS...
     try:
         subprocess.call(['phantomjs', '-v'],
                         stdout=open(os.devnull, 'w'),
                         stderr=subprocess.STDOUT)
     except OSError:
         test = WebsiteUiTest('UI Tests')
         result.startTest(test)
         result.addSkip(
             test,
             "phantomjs command not found (cf. http://phantomjs.org/)")
         result.stopTest(test)
         return
     # ...then run the actual test
     result._exc_info_to_string = _exc_info_to_string
     try:
         self._run(result)
     finally:
         del result._exc_info_to_string
Exemplo n.º 5
0
 def run(self, result):
     if sql_db._Pool is not None:
         sql_db._Pool.close_all(sql_db.dsn(tools.config['db_name']))
     return super(WebSuite, self).run(result)
Exemplo n.º 6
0
def get_conn_and_cr(database):
    conn = connect(dsn=dsn(database), async=1)
    gevent_wait_callback(conn)
    cr = conn.cursor()
    return conn, cr
Exemplo n.º 7
0
def get_conn_and_cr(database):
    conn = connect(dsn=dsn(database), async=1)
    gevent_wait_callback(conn)
    cr = conn.cursor()
    return conn, cr