Merge "Add host argument to get_connect_string()"
This commit is contained in:
@@ -656,7 +656,8 @@ def _change_deleted_column_type_to_id_type_sqlite(migrate_engine, table_name,
|
||||
execute()
|
||||
|
||||
|
||||
def get_connect_string(backend, database, user=None, passwd=None):
|
||||
def get_connect_string(backend, database, user=None, passwd=None,
|
||||
host='localhost'):
|
||||
"""Get database connection
|
||||
|
||||
Try to get a connection with a very specific set of values, if we get
|
||||
@@ -665,11 +666,12 @@ def get_connect_string(backend, database, user=None, passwd=None):
|
||||
args = {'backend': backend,
|
||||
'user': user,
|
||||
'passwd': passwd,
|
||||
'host': host,
|
||||
'database': database}
|
||||
if backend == 'sqlite':
|
||||
template = '%(backend)s:///%(database)s'
|
||||
else:
|
||||
template = "%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s"
|
||||
template = "%(backend)s://%(user)s:%(passwd)s@%(host)s/%(database)s"
|
||||
return template % args
|
||||
|
||||
|
||||
|
||||
@@ -685,6 +685,11 @@ class TestConnectionUtils(test_utils.BaseTestCase):
|
||||
self.assertEqual(utils.get_db_connection_info(conn_pieces),
|
||||
('dude', 'pass', 'test', 'localhost'))
|
||||
|
||||
def test_connect_string_host(self):
|
||||
self.full_credentials['host'] = 'myhost'
|
||||
connect_string = utils.get_connect_string(**self.full_credentials)
|
||||
self.assertEqual(connect_string, 'mysql://dude:pass@myhost/test')
|
||||
|
||||
|
||||
class MyModelSoftDeletedProjectId(declarative_base(), models.ModelBase,
|
||||
models.SoftDeleteMixin):
|
||||
|
||||
Reference in New Issue
Block a user