mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-03-16 22:20:24 +00:00
supports database options
This commit is contained in:
parent
585ce0fa35
commit
e8ea0a64fa
2 changed files with 46 additions and 0 deletions
|
|
@ -89,9 +89,34 @@ def parse(url, engine=None):
|
|||
'PORT': url.port or '',
|
||||
})
|
||||
|
||||
# Parse the query string into OPTIONS.
|
||||
qs = urlparse.parse_qs(url.query)
|
||||
options = {}
|
||||
for k in qs:
|
||||
options[k] = qs[k][-1]
|
||||
if options:
|
||||
config['OPTIONS'] = options
|
||||
|
||||
if engine:
|
||||
config['ENGINE'] = engine
|
||||
elif url.scheme in SCHEMES:
|
||||
config['ENGINE'] = SCHEMES[url.scheme]
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def main():
|
||||
import django.db
|
||||
from django.conf import settings
|
||||
default = django.db.DEFAULT_DB_ALIAS
|
||||
settings.configure()
|
||||
settings.DATABASES[default] = config()
|
||||
db = django.db.connections[default]
|
||||
db.connect()
|
||||
import pprint
|
||||
pprint.pprint(db.settings_dict)
|
||||
print db.is_usable()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -111,5 +111,26 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
|
||||
assert url['ENGINE'] == engine
|
||||
|
||||
def test_database_url_with_options(self):
|
||||
del os.environ['DATABASE_URL']
|
||||
a = dj_database_url.config()
|
||||
assert not a
|
||||
|
||||
os.environ['DATABASE_URL'] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn?sslrootcert=rds-combined-ca-bundle.pem&sslmode=verify-full'
|
||||
|
||||
url = dj_database_url.config()
|
||||
|
||||
assert url['ENGINE'] == 'django.db.backends.postgresql_psycopg2'
|
||||
assert url['NAME'] == 'd8r82722r2kuvn'
|
||||
assert url['HOST'] == 'ec2-107-21-253-135.compute-1.amazonaws.com'
|
||||
assert url['USER'] == 'uf07k1i6d8ia0v'
|
||||
assert url['PASSWORD'] == 'wegauwhgeuioweg'
|
||||
assert url['PORT'] == 5431
|
||||
assert url['OPTIONS'] == {
|
||||
'sslrootcert': 'rds-combined-ca-bundle.pem',
|
||||
'sslmode': 'verify-full'
|
||||
}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue