Skip to content

Commit

Permalink
100% test coverage (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey authored Dec 30, 2022
1 parent 797fe1e commit 414c69c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 2 additions & 10 deletions dj_database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -196,7 +191,4 @@ def parse(
if options:
parsed_config["OPTIONS"] = options

if engine:
parsed_config["ENGINE"] = engine

return parsed_config
8 changes: 8 additions & 0 deletions test_dj_database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,14 @@ def test_bad_url_parsing(self):
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()

0 comments on commit 414c69c

Please sign in to comment.