'The _nodb_connection property fallbacks to the default connection
database when access to the \'postgres\' database is not granted.'

def test_nodb_connection(self):

    def mocked_connect(self):
        if (self.settings_dict['NAME'] is None):
            raise DatabaseError()
        return ''
    nodb_conn = connection._nodb_connection
    self.assertIsNone(nodb_conn.settings_dict['NAME'])
    with warnings.catch_warnings(record=True) as w:
        with mock.patch('django.db.backends.base.base.BaseDatabaseWrapper.connect', side_effect=mocked_connect, autospec=True):
            warnings.simplefilter('always', RuntimeWarning)
            nodb_conn = connection._nodb_connection
    self.assertIsNotNone(nodb_conn.settings_dict['NAME'])
    self.assertEqual(nodb_conn.settings_dict['NAME'], connection.settings_dict['NAME'])
    self.assertEqual(len(w), 1)
    self.assertEqual(w[0].message.__class__, RuntimeWarning)
