Better error on missing schema (#196)

This commit is contained in:
Tom Parker-Shemilt 2022-12-21 08:19:39 +00:00 committed by GitHub
parent 11854687fa
commit e47382d4ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -115,7 +115,13 @@ def parse(
hostname = urlparse.unquote(hostname)
# Lookup specified engine.
engine = SCHEMES[url.scheme] if engine is None else engine
if engine is None:
engine = SCHEMES.get(url.scheme)
if engine is None:
raise ValueError(
"No support for '%s'. We support: %s"
% (url.scheme, ", ".join(sorted(SCHEMES.keys())))
)
port = (
str(url.port)

View file

@ -541,6 +541,10 @@ class DatabaseTestSuite(unittest.TestCase):
assert url["CONN_MAX_AGE"] == 600
assert url["CONN_HEALTH_CHECKS"] is True
def test_bad_url_parsing(self):
with self.assertRaisesRegex(ValueError, "No support for 'foo'. We support: "):
dj_database_url.parse("foo://bar")
if __name__ == "__main__":
unittest.main()