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 2121 "apps" ,
2222 "async" ,
2323 "auth_tests" ,
24+ "backend_" ,
2425 "backends" ,
2526 "basic" ,
2627 "bulk_create" ,
Original file line number Diff line number Diff line change 11import contextlib
22
3+ from django .core .exceptions import ImproperlyConfigured
34from django .db .backends .base .base import BaseDatabaseWrapper
45from pymongo .collection import Collection
56from pymongo .mongo_client import MongoClient
@@ -151,13 +152,13 @@ def __getattr__(self, attr):
151152 raise AttributeError (attr )
152153
153154 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" ]]
157156 super ().init_connection_state ()
158157
159158 def get_connection_params (self ):
160159 settings_dict = self .settings_dict
160+ if not settings_dict ["NAME" ]:
161+ raise ImproperlyConfigured ('settings.DATABASES is missing the "NAME" value.' )
161162 return {
162163 "host" : settings_dict ["HOST" ] or None ,
163164 "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