mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-03-16 22:20:24 +00:00
Merge pull request #26 from hiisi13/master
Ability to set different engine
This commit is contained in:
commit
958717e05d
2 changed files with 18 additions and 7 deletions
|
|
@ -33,7 +33,7 @@ SCHEMES = {
|
|||
}
|
||||
|
||||
|
||||
def config(env=DEFAULT_ENV, default=None):
|
||||
def config(env=DEFAULT_ENV, default=None, engine=None):
|
||||
"""Returns configured DATABASE dictionary from DATABASE_URL."""
|
||||
|
||||
config = {}
|
||||
|
|
@ -41,12 +41,12 @@ def config(env=DEFAULT_ENV, default=None):
|
|||
s = os.environ.get(env, default)
|
||||
|
||||
if s:
|
||||
config = parse(s)
|
||||
config = parse(s, engine)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def parse(url):
|
||||
def parse(url, engine=None):
|
||||
"""Parses a database URL."""
|
||||
|
||||
if url == 'sqlite://:memory:':
|
||||
|
|
@ -82,7 +82,9 @@ def parse(url):
|
|||
'PORT': url.port or '',
|
||||
})
|
||||
|
||||
if url.scheme in SCHEMES:
|
||||
if engine:
|
||||
config['ENGINE'] = engine
|
||||
elif url.scheme in SCHEMES:
|
||||
config['ENGINE'] = SCHEMES[url.scheme]
|
||||
|
||||
return config
|
||||
|
|
|
|||
|
|
@ -12,9 +12,6 @@ POSTGIS_URL = 'postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compu
|
|||
|
||||
class DatabaseTestSuite(unittest.TestCase):
|
||||
|
||||
def test_truth(self):
|
||||
assert True
|
||||
|
||||
def test_postgres_parsing(self):
|
||||
url = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
|
||||
url = dj_database_url.parse(url)
|
||||
|
|
@ -49,6 +46,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
assert url['PORT'] is None
|
||||
|
||||
def test_database_url(self):
|
||||
del os.environ['DATABASE_URL']
|
||||
a = dj_database_url.config()
|
||||
assert not a
|
||||
|
||||
|
|
@ -77,8 +75,19 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
assert url['ENGINE'] == 'django.db.backends.sqlite3'
|
||||
assert url['NAME'] == ':memory:'
|
||||
|
||||
def test_parse_engine_setting(self):
|
||||
engine = 'django_mysqlpool.backends.mysqlpool'
|
||||
url = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true'
|
||||
url = dj_database_url.parse(url, engine)
|
||||
|
||||
assert url['ENGINE'] == engine
|
||||
|
||||
def test_config_engine_setting(self):
|
||||
engine = 'django_mysqlpool.backends.mysqlpool'
|
||||
os.environ['DATABASE_URL'] = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true'
|
||||
url = dj_database_url.config(engine=engine)
|
||||
|
||||
assert url['ENGINE'] == engine
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue