Skip to content

Commit

Permalink
pymongo driver does not support conn_*
Browse files Browse the repository at this point in the history
  • Loading branch information
aclark4life committed Dec 5, 2024
1 parent 56fe609 commit 4d155ac
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ MONGODB_URI = "mongodb+srv://myDatabaseUser:D1fficultP%[email protected]
DATABASES["default"] = django_mongodb.parse_uri(MONGODB_URI)
```

#### `django_mongodb.parse_uri(uri, conn_max_age=0, conn_health_checks=False, test=None)`
#### `django_mongodb.parse_uri(uri, test=None)`

- Use `conn_max_age` and `conn_health_checks` to configure [persistent database
connections](https://docs.djangoproject.com/en/stable/ref/databases/#persistent-database-connections).
- Use `test` to provide a dictionary of [settings for test databases](
https://docs.djangoproject.com/en/stable/ref/settings/#test).

Expand Down
4 changes: 1 addition & 3 deletions django_mongodb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def check_django_compatability():
)


def parse_uri(uri, conn_max_age=0, conn_health_checks=False, test=None):
def parse_uri(uri, test=None):
"""
Convert the given uri into a dictionary suitable for Django's DATABASES
setting.
Expand All @@ -51,8 +51,6 @@ def parse_uri(uri, conn_max_age=0, conn_health_checks=False, test=None):
"USER": uri.get("username"),
"PASSWORD": uri.get("password"),
"OPTIONS": uri.get("options"),
"CONN_MAX_AGE": conn_max_age,
"CONN_HEALTH_CHECKS": conn_health_checks,
}
if test:
settings_dict["TEST"] = test
Expand Down
8 changes: 0 additions & 8 deletions tests/utils_/test_parse_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ def test_localhosts_with_ports(self):
self.assertEqual(settings_dict["HOST"], "localhost:27017,localhost:27018,localhost:27019")
self.assertEqual(settings_dict["PORT"], None)

def test_conn_max_age(self):
settings_dict = parse_uri(URI, conn_max_age=600)
self.assertEqual(settings_dict["CONN_MAX_AGE"], 600)

def test_conn_health_checks(self):
settings_dict = parse_uri(URI, conn_health_checks=True)
self.assertEqual(settings_dict["CONN_HEALTH_CHECKS"], True)

def test_test_kwarg(self):
settings_dict = parse_uri(URI, test={"NAME": "test_db"})
self.assertEqual(settings_dict["TEST"]["NAME"], "test_db")
Expand Down

0 comments on commit 4d155ac

Please sign in to comment.