Python django.db.connection.connect() Examples
The following are 10
code examples of django.db.connection.connect().
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.connection
, or try the search function
.
Example #1
Source File: test_basic.py From django-transaction-hooks with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_hooks_cleared_on_reconnect(self, track): with atomic(): track.do(1) connection.close() connection.connect() with atomic(): track.do(2) track.assert_done([2])
Example #2
Source File: __init__.py From django-dbconn-retry with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self) -> None: _log.debug("[FullErrorTests] patching for setup") self.s_connect = BaseDatabaseWrapper.connect BaseDatabaseWrapper.connect = Mock(side_effect=OperationalError('fail testing')) BaseDatabaseWrapper.connection = property(lambda x: None, lambda x, y: None) # type: ignore
Example #3
Source File: __init__.py From django-dbconn-retry with BSD 3-Clause "New" or "Revised" License | 5 votes |
def tearDown(self) -> None: _log.debug("[FullErrorTests] restoring") BaseDatabaseWrapper.connect = self.s_connect del BaseDatabaseWrapper.connection
Example #4
Source File: __init__.py From django-dbconn-retry with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_prehook(self) -> None: cb = Mock(name='pre_reconnect_hook') ddr.pre_reconnect.connect(cb) self.assertRaises(OperationalError, connection.ensure_connection) self.assertTrue(cb.called) del connection._connection_retries
Example #5
Source File: __init__.py From django-dbconn-retry with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_posthook(self) -> None: cb = Mock(name='post_reconnect_hook') ddr.post_reconnect.connect(cb) self.assertRaises(OperationalError, connection.ensure_connection) self.assertTrue(cb.called) del connection._connection_retries
Example #6
Source File: __init__.py From django-dbconn-retry with BSD 3-Clause "New" or "Revised" License | 5 votes |
def fix_connection(sender: type, *, dbwrapper: BaseDatabaseWrapper, **kwargs: Any) -> None: dbwrapper.connect = dbwrapper.s_connect
Example #7
Source File: __init__.py From django-dbconn-retry with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_posthook(self) -> None: cb = Mock(name='post_reconnect_hook') ddr.pre_reconnect.connect(fix_connection) ddr.post_reconnect.connect(cb) from django.db import connection connection.close() connection.s_connect = connection.connect connection.connect = Mock(side_effect=OperationalError('reconnect testing')) connection.ensure_connection() ReconnectTests.cls_atomics['default'] = transaction.atomic(using='default') ReconnectTests.cls_atomics['default'].__enter__() self.assertTrue(cb.called) self.assertTrue(connection.is_usable())
Example #8
Source File: tests.py From django-sqlserver with MIT License | 5 votes |
def test_hooks_cleared_on_reconnect(self): with transaction.atomic(): self.do(1) connection.close() connection.connect() with transaction.atomic(): self.do(2) self.assertDone([2])
Example #9
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_hooks_cleared_on_reconnect(self): with transaction.atomic(): self.do(1) connection.close() connection.connect() with transaction.atomic(): self.do(2) self.assertDone([2])
Example #10
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_disallowed_database_connections(self): expected_message = ( "Database connections to 'default' are not allowed in SimpleTestCase " "subclasses. Either subclass TestCase or TransactionTestCase to " "ensure proper test isolation or add 'default' to " "test_utils.tests.DisallowedDatabaseQueriesTests.databases to " "silence this failure." ) with self.assertRaisesMessage(AssertionError, expected_message): connection.connect() with self.assertRaisesMessage(AssertionError, expected_message): connection.temporary_connection()