本文整理汇总了Python中django.db.connection.connect方法的典型用法代码示例。如果您正苦于以下问题:Python connection.connect方法的具体用法?Python connection.connect怎么用?Python connection.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.connection
的用法示例。
在下文中一共展示了connection.connect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hooks_cleared_on_reconnect
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
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])
示例2: setUp
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
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
示例3: tearDown
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
def tearDown(self) -> None:
_log.debug("[FullErrorTests] restoring")
BaseDatabaseWrapper.connect = self.s_connect
del BaseDatabaseWrapper.connection
示例4: test_prehook
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
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
示例5: test_posthook
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
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
示例6: fix_connection
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
def fix_connection(sender: type, *, dbwrapper: BaseDatabaseWrapper, **kwargs: Any) -> None:
dbwrapper.connect = dbwrapper.s_connect
示例7: test_hooks_cleared_on_reconnect
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
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])
示例8: test_disallowed_database_connections
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import connect [as 别名]
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()