File tree Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 21
21
"apps" ,
22
22
"async" ,
23
23
"auth_tests" ,
24
+ "backend_" ,
24
25
"backends" ,
25
26
"basic" ,
26
27
"bulk_create" ,
Original file line number Diff line number Diff line change 1
1
import contextlib
2
2
3
+ from django .core .exceptions import ImproperlyConfigured
3
4
from django .db .backends .base .base import BaseDatabaseWrapper
4
5
from pymongo .collection import Collection
5
6
from pymongo .mongo_client import MongoClient
@@ -151,13 +152,13 @@ def __getattr__(self, attr):
151
152
raise AttributeError (attr )
152
153
153
154
def init_connection_state (self ):
154
- db_name = self .settings_dict ["NAME" ]
155
- if db_name :
156
- self .database = self .connection [db_name ]
155
+ self .database = self .connection [self .settings_dict ["NAME" ]]
157
156
super ().init_connection_state ()
158
157
159
158
def get_connection_params (self ):
160
159
settings_dict = self .settings_dict
160
+ if not settings_dict ["NAME" ]:
161
+ raise ImproperlyConfigured ('settings.DATABASES is missing the "NAME" value.' )
161
162
return {
162
163
"host" : settings_dict ["HOST" ] or None ,
163
164
"port" : int (settings_dict ["PORT" ] or 27017 ),
Original file line number Diff line number Diff line change
1
+ from django .core .exceptions import ImproperlyConfigured
2
+ from django .db import connection
3
+ from django .test import SimpleTestCase
4
+
5
+ from django_mongodb .base import DatabaseWrapper
6
+
7
+
8
+ class DatabaseWrapperTests (SimpleTestCase ):
9
+ def test_database_name_empty (self ):
10
+ settings = connection .settings_dict .copy ()
11
+ settings ["NAME" ] = ""
12
+ msg = 'settings.DATABASES is missing the "NAME" value.'
13
+ with self .assertRaisesMessage (ImproperlyConfigured , msg ):
14
+ DatabaseWrapper (settings ).get_connection_params ()
You can’t perform that action at this time.
0 commit comments