497
496
where(new_table.c.deleted == deleted).\
498
497
values(deleted=default_deleted_value).\
501
def get_connect_string(backend, database, user=None, passwd=None):
502
"""Get database connection
504
Try to get a connection with a very specific set of values, if we get
505
these then we'll run the tests, otherwise they are skipped
507
args = {'backend': backend,
510
'database': database}
511
if backend == 'sqlite':
512
template = '%(backend)s:///%(database)s'
514
template = "%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s"
515
return template % args
518
def is_backend_avail(backend, database, user=None, passwd=None):
520
connect_uri = get_connect_string(backend=backend,
524
engine = sqlalchemy.create_engine(connect_uri)
525
connection = engine.connect()
527
# intentionally catch all to handle exceptions even if we don't
528
# have any backend code loaded.
536
def get_db_connection_info(conn_pieces):
537
database = conn_pieces.path.strip('/')
538
loc_pieces = conn_pieces.netloc.split('@')
541
auth_pieces = loc_pieces[0].split(':')
542
user = auth_pieces[0]
544
if len(auth_pieces) > 1:
545
password = auth_pieces[1].strip()
547
return (user, password, database, host)