100% test coverage (#202)

This commit is contained in:
Tom Parker-Shemilt 2022-12-30 09:44:45 +00:00 committed by GitHub
parent 797fe1e7ce
commit 414c69c122
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View file

@ -112,11 +112,7 @@ def parse(
# Split query strings from path.
path = spliturl.path[1:]
if "?" in path and not spliturl.query:
path, raw_query = path.split("?", 2)
else:
path, raw_query = path, spliturl.query
query = urlparse.parse_qs(raw_query)
query = urlparse.parse_qs(spliturl.query)
# If we are using sqlite and we have no path, then assume we
# want an in-memory database (this is the behaviour of sqlalchemy)
@ -130,8 +126,6 @@ def parse(
hostname = spliturl.netloc
if "@" in hostname:
hostname = hostname.rsplit("@", 1)[1]
if ":" in hostname:
hostname = hostname.split(":", 1)[0]
# Use URL Parse library to decode % encodes
hostname = urlparse.unquote(hostname)
@ -161,6 +155,7 @@ def parse(
"PORT": port or "",
"CONN_MAX_AGE": conn_max_age,
"CONN_HEALTH_CHECKS": conn_health_checks,
"ENGINE": engine,
}
)
if test_options:
@ -196,7 +191,4 @@ def parse(
if options:
parsed_config["OPTIONS"] = options
if engine:
parsed_config["ENGINE"] = engine
return parsed_config

View file

@ -545,6 +545,14 @@ class DatabaseTestSuite(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "No support for 'foo'. We support: "):
dj_database_url.parse("foo://bar")
@mock.patch.dict(
os.environ,
{"DATABASE_URL": "postgres://user:password@instance.amazonaws.com:5431/d8r8?"},
)
def test_ssl_require(self):
url = dj_database_url.config(ssl_require=True)
assert url["OPTIONS"] == {'sslmode': 'require'}
if __name__ == "__main__":
unittest.main()