|
6 | 6 | from django_mongodb_backend.base import DatabaseWrapper
|
7 | 7 |
|
8 | 8 |
|
9 |
| -class DatabaseWrapperTests(SimpleTestCase): |
| 9 | +class GetConnectionParamsTests(SimpleTestCase): |
10 | 10 | def test_database_name_empty(self):
|
11 | 11 | settings = connection.settings_dict.copy()
|
12 | 12 | settings["NAME"] = ""
|
13 | 13 | msg = 'settings.DATABASES is missing the "NAME" value.'
|
14 | 14 | with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
15 | 15 | DatabaseWrapper(settings).get_connection_params()
|
16 | 16 |
|
| 17 | + def test_host(self): |
| 18 | + settings = connection.settings_dict.copy() |
| 19 | + settings["HOST"] = "host" |
| 20 | + params = DatabaseWrapper(settings).get_connection_params() |
| 21 | + self.assertEqual(params["host"], "host") |
| 22 | + |
| 23 | + def test_host_empty(self): |
| 24 | + settings = connection.settings_dict.copy() |
| 25 | + settings["HOST"] = "" |
| 26 | + params = DatabaseWrapper(settings).get_connection_params() |
| 27 | + self.assertIsNone(params["host"]) |
| 28 | + |
| 29 | + def test_user(self): |
| 30 | + settings = connection.settings_dict.copy() |
| 31 | + settings["USER"] = "user" |
| 32 | + params = DatabaseWrapper(settings).get_connection_params() |
| 33 | + self.assertEqual(params["username"], "user") |
| 34 | + |
| 35 | + def test_password(self): |
| 36 | + settings = connection.settings_dict.copy() |
| 37 | + settings["PASSWORD"] = "password" # noqa: S105 |
| 38 | + params = DatabaseWrapper(settings).get_connection_params() |
| 39 | + self.assertEqual(params["password"], "password") |
| 40 | + |
| 41 | + def test_port(self): |
| 42 | + settings = connection.settings_dict.copy() |
| 43 | + settings["PORT"] = 123 |
| 44 | + params = DatabaseWrapper(settings).get_connection_params() |
| 45 | + self.assertEqual(params["port"], 123) |
| 46 | + |
| 47 | + def test_port_as_string(self): |
| 48 | + settings = connection.settings_dict.copy() |
| 49 | + settings["PORT"] = "123" |
| 50 | + params = DatabaseWrapper(settings).get_connection_params() |
| 51 | + self.assertEqual(params["port"], 123) |
| 52 | + |
| 53 | + def test_options(self): |
| 54 | + settings = connection.settings_dict.copy() |
| 55 | + settings["OPTIONS"] = {"extra": "option"} |
| 56 | + params = DatabaseWrapper(settings).get_connection_params() |
| 57 | + self.assertEqual(params["extra"], "option") |
| 58 | + |
17 | 59 |
|
18 | 60 | class DatabaseWrapperConnectionTests(TestCase):
|
19 | 61 | def test_set_autocommit(self):
|
|
0 commit comments