Python django.db.utils.ConnectionHandler() Examples

The following are 5 code examples of django.db.utils.ConnectionHandler(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.db.utils , or try the search function .
Example #1
Source File: tests.py    From django-sqlserver with MIT License 5 votes vote down vote up
def test_no_databases(self):
        """
        Empty DATABASES setting default to the dummy backend.
        """
        DATABASES = {}
        conns = ConnectionHandler(DATABASES)
        self.assertEqual(conns[DEFAULT_DB_ALIAS].settings_dict['ENGINE'], 'django.db.backends.dummy')
        with self.assertRaises(ImproperlyConfigured):
            conns[DEFAULT_DB_ALIAS].ensure_connection() 
Example #2
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_connection_handler_no_databases(self):
        """Empty DATABASES setting defaults to the dummy backend."""
        DATABASES = {}
        conns = ConnectionHandler(DATABASES)
        self.assertEqual(conns[DEFAULT_DB_ALIAS].settings_dict['ENGINE'], 'django.db.backends.dummy')
        msg = (
            'settings.DATABASES is improperly configured. Please supply the '
            'ENGINE value. Check settings documentation for more details.'
        )
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            conns[DEFAULT_DB_ALIAS].ensure_connection() 
Example #3
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def assertImproperlyConfigured(self, DATABASES):
        conns = ConnectionHandler(DATABASES)
        self.assertEqual(conns[DEFAULT_DB_ALIAS].settings_dict['ENGINE'], 'django.db.backends.dummy')
        msg = (
            'settings.DATABASES is improperly configured. Please supply the '
            'ENGINE value. Check settings documentation for more details.'
        )
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            conns[DEFAULT_DB_ALIAS].ensure_connection() 
Example #4
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_no_default_database(self):
        DATABASES = {'other': {}}
        conns = ConnectionHandler(DATABASES)
        msg = "You must define a 'default' database."
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            conns['other'].ensure_connection() 
Example #5
Source File: tests.py    From edx-analytics-data-api with GNU Affero General Public License v3.0 5 votes vote down vote up
def override_database_connections(databases):
        with mock.patch('analyticsdataserver.views.connections', ConnectionHandler(databases)):
            yield