当前位置: 首页>>代码示例>>Python>>正文


Python connection.connect方法代码示例

本文整理汇总了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]) 
开发者ID:carljm,项目名称:django-transaction-hooks,代码行数:13,代码来源:test_basic.py

示例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 
开发者ID:jdelic,项目名称:django-dbconn-retry,代码行数:7,代码来源:__init__.py

示例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 
开发者ID:jdelic,项目名称:django-dbconn-retry,代码行数:6,代码来源:__init__.py

示例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 
开发者ID:jdelic,项目名称:django-dbconn-retry,代码行数:8,代码来源:__init__.py

示例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 
开发者ID:jdelic,项目名称:django-dbconn-retry,代码行数:8,代码来源:__init__.py

示例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 
开发者ID:jdelic,项目名称:django-dbconn-retry,代码行数:4,代码来源:__init__.py

示例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]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:13,代码来源:tests.py

示例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() 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py


注:本文中的django.db.connection.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。