From 414c69c122bac8ce27539dbfeab696f2769cb1e7 Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Fri, 30 Dec 2022 09:44:45 +0000 Subject: [PATCH] 100% test coverage (#202) --- dj_database_url.py | 12 ++---------- test_dj_database_url.py | 8 ++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dj_database_url.py b/dj_database_url.py index 8a5e141..ce3a7df 100644 --- a/dj_database_url.py +++ b/dj_database_url.py @@ -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 diff --git a/test_dj_database_url.py b/test_dj_database_url.py index 0ed8b02..c515c91 100644 --- a/test_dj_database_url.py +++ b/test_dj_database_url.py @@ -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()