From 79e3058687446b7345cd693334375b75cfd71dee Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Clark" Date: Tue, 3 Dec 2024 12:04:49 -0500 Subject: [PATCH] s/parse/parse_uri/ --- django_mongodb/__init__.py | 4 ++-- django_mongodb/utils.py | 6 +++--- tests/utils_/test_parse.py | 24 +++++++++++++----------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/django_mongodb/__init__.py b/django_mongodb/__init__.py index 17300b84..5ee8bc1c 100644 --- a/django_mongodb/__init__.py +++ b/django_mongodb/__init__.py @@ -2,7 +2,7 @@ # Check Django compatibility before other imports which may fail if the # wrong version of Django is installed. -from .utils import check_django_compatability, parse +from .utils import check_django_compatability, parse_uri check_django_compatability() @@ -14,7 +14,7 @@ from .lookups import register_lookups # noqa: E402 from .query import register_nodes # noqa: E402 -__all__ = ['parse'] +__all__ = ["parse_uri"] register_aggregates() register_expressions() diff --git a/django_mongodb/utils.py b/django_mongodb/utils.py index f5154fd5..d04780a9 100644 --- a/django_mongodb/utils.py +++ b/django_mongodb/utils.py @@ -6,7 +6,7 @@ from django.core.exceptions import ImproperlyConfigured from django.db.backends.utils import logger from django.utils.version import get_version_tuple -from pymongo.uri_parser import parse_uri +from pymongo.uri_parser import parse_uri as parse_uri_mongo def check_django_compatability(): @@ -26,7 +26,7 @@ def check_django_compatability(): ) -def parse( +def parse_uri( uri, engine=None, conn_max_age=None, conn_health_checks=None, ssl_require=None, test=None ): """ @@ -35,7 +35,7 @@ def parse( ``pymongo.uri_parser.parse_uri()`` function that converts PyMongo's settings dictionary into a Django database settings dictionary. """ - uri = parse_uri(uri) + uri = parse_uri_mongo(uri) host = None port = None diff --git a/tests/utils_/test_parse.py b/tests/utils_/test_parse.py index 016ea1e9..b484626d 100644 --- a/tests/utils_/test_parse.py +++ b/tests/utils_/test_parse.py @@ -10,7 +10,7 @@ class MongoParseURITests(SimpleTestCase): """ - Test django_mongodb.parse(uri) function + Test django_mongodb.parse_uri(uri) function """ def setUp(self): @@ -22,14 +22,16 @@ def setUp(self): @patch("dns.resolver.resolve") def test_uri(self, mock_resolver): - settings_dict = django_mongodb.parse("mongodb://cluster0.example.mongodb.net/myDatabase") + settings_dict = django_mongodb.parse_uri( + "mongodb://cluster0.example.mongodb.net/myDatabase" + ) self.assertEqual(settings_dict["ENGINE"], "django_mongodb") self.assertEqual(settings_dict["NAME"], "myDatabase") self.assertEqual(settings_dict["HOST"], "cluster0.example.mongodb.net") @patch("dns.resolver.resolve") def test_srv_uri_with_options(self, mock_resolver): - settings_dict = django_mongodb.parse(URI) + settings_dict = django_mongodb.parse_uri(URI) self.assertEqual(settings_dict["ENGINE"], "django_mongodb") self.assertEqual(settings_dict["NAME"], "myDatabase") self.assertEqual(settings_dict["HOST"], "mongodb+srv://cluster0.example.mongodb.net") @@ -41,41 +43,41 @@ def test_srv_uri_with_options(self, mock_resolver): ) def test_localhost(self): - settings_dict = django_mongodb.parse("mongodb://localhost/myDatabase") + settings_dict = django_mongodb.parse_uri("mongodb://localhost/myDatabase") self.assertEqual(settings_dict["ENGINE"], "django_mongodb") self.assertEqual(settings_dict["NAME"], "myDatabase") self.assertEqual(settings_dict["HOST"], "localhost") def test_localhost_bad_credentials(self): with self.assertRaises(pymongo.errors.InvalidURI): - django_mongodb.parse("mongodb://:@localhost/myDatabase") + django_mongodb.parse_uri("mongodb://:@localhost/myDatabase") @patch("dns.resolver.resolve") def test_engine_kwarg(self, mock_resolver): - settings_dict = django_mongodb.parse(URI, engine="some_other_engine") + settings_dict = django_mongodb.parse_uri(URI, engine="some_other_engine") self.assertEqual(settings_dict["ENGINE"], "some_other_engine") @patch("dns.resolver.resolve") def test_conn_max_age_kwarg(self, mock_resolver): - settings_dict = django_mongodb.parse(URI, conn_max_age=600) + settings_dict = django_mongodb.parse_uri(URI, conn_max_age=600) self.assertEqual(settings_dict["CONN_MAX_AGE"], 600) @patch("dns.resolver.resolve") def test_conn_health_checks_kwarg(self, mock_resolver): - settings_dict = django_mongodb.parse(URI, conn_health_checks=True) + settings_dict = django_mongodb.parse_uri(URI, conn_health_checks=True) self.assertEqual(settings_dict["CONN_HEALTH_CHECKS"], True) @patch("dns.resolver.resolve") def test_ssl_require_kwarg(self, mock_resolver): - settings_dict = django_mongodb.parse(URI, ssl_require=True) + settings_dict = django_mongodb.parse_uri(URI, ssl_require=True) self.assertEqual(settings_dict["SSL_REQUIRE"], True) @patch("dns.resolver.resolve") def test_test_kwarg(self, mock_resolver): - settings_dict = django_mongodb.parse(URI, test={"NAME": "test_db"}) + settings_dict = django_mongodb.parse_uri(URI, test={"NAME": "test_db"}) self.assertEqual(settings_dict["TEST"]["NAME"], "test_db") @patch("dns.resolver.resolve") def test_uri_no_prefix(self, mock_resolver): with self.assertRaises(pymongo.errors.InvalidURI): - django_mongodb.parse("cluster0.example.mongodb.net/myDatabase") + django_mongodb.parse_uri("cluster0.example.mongodb.net/myDatabase")