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


Python OssimDB.execute_non_query方法代码示例

本文整理汇总了Python中OssimDB.OssimDB.execute_non_query方法的典型用法代码示例。如果您正苦于以下问题:Python OssimDB.execute_non_query方法的具体用法?Python OssimDB.execute_non_query怎么用?Python OssimDB.execute_non_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OssimDB.OssimDB的用法示例。


在下文中一共展示了OssimDB.execute_non_query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OssimDBTest

# 需要导入模块: from OssimDB import OssimDB [as 别名]
# 或者: from OssimDB.OssimDB import execute_non_query [as 别名]

#.........这里部分代码省略.........
    @mock.patch('OssimDB.Lock', autospec=True)
    @mock.patch('OssimDB.MySQLdb', autospec=True)
    def test_exec_query_retry_fail(self, mock_mysqldb, mock_lock, mock_time):
        failing_attempts = 4
        mock_lock_obj = mock.create_autospec(Lock())
        mock_connections, mock_cursors = self.prepare_multiple_failing_queries(failing_attempts)
        mock_lock.return_value = mock_lock_obj
        mock_mysqldb.connect.side_effect = mock_connections
        self.setUp()
        self.__ossim_db.connect()

        exec_query_rv = self.__ossim_db.exec_query(self.__db_query)

        self.assertTrue(mock_lock_obj.acquire.called)
        self.assert_multiple_failing_queries(mock_connections, mock_cursors, failing_attempts)
        self.assertEqual(mock_time.sleep.call_count, failing_attempts - 1)  # last attempt without sleep()
        self.assertTrue(mock_lock_obj.release.called)
        self.assertTrue(set(exec_query_rv) == set(self.__db_query_empty_result))

    @mock.patch('OssimDB.time', autospec=True)
    @mock.patch('OssimDB.Lock', autospec=True)
    @mock.patch('OssimDB.MySQLdb', autospec=True)
    def test_exec_non_query(self, mock_mysqldb, mock_lock, mock_time):
        mock_connection = mock.create_autospec(Connection)
        mock_cursor = mock.create_autospec(Cursor)
        mock_lock_obj = mock.create_autospec(Lock())
        mock_lock.return_value = mock_lock_obj
        mock_mysqldb.connect.return_value = mock_connection
        mock_connection.cursor.return_value = mock_cursor
        mock_cursor.fetchall.return_value = self.__db_query_result
        self.setUp()
        self.__ossim_db.connect()

        exec_non_query_rv = self.__ossim_db.execute_non_query(self.__db_query, self.__db_autocommit)

        self.assertTrue(mock_lock_obj.acquire.called)
        mock_connection.autocommit.assert_called_with(self.__db_autocommit)
        self.assertTrue(mock_connection.cursor.called)
        mock_cursor.execute.assert_called_with(self.__db_query, None)
        self.assertTrue(mock_cursor.close.called)
        self.assertTrue(mock_lock_obj.release.called)
        self.assertTrue(exec_non_query_rv)
        self.assertFalse(mock_connection.commit.called)
        self.assertFalse(mock_time.sleep.called)
        self.assertFalse(mock_connection.close.called)

    @mock.patch('OssimDB.MySQLdb', autospec=True)
    def test_execute_non_query_parameterized(self, mock_mysqldb):
        mock_connection = mock.create_autospec(Connection)
        mock_cursor = mock.create_autospec(Cursor)
        mock_mysqldb.connect.return_value = mock_connection
        mock_connection.cursor.return_value = mock_cursor
        self.setUp()
        self.__ossim_db.connect()

        exec_non_query_rv = self.__ossim_db.execute_non_query(self.__db_param_query, params=self.__db_params)

        mock_cursor.execute.assert_called_with(self.__db_param_query, self.__db_params)
        self.assertTrue(exec_non_query_rv)

    @mock.patch('OssimDB.MySQLdb', autospec=True)
    def test_execute_non_query_autoconnect(self, mock_mysqldb):
        mock_connection = mock.create_autospec(Connection)
        mock_mysqldb.connect.return_value = mock_connection
        self.setUp()
开发者ID:jpalanco,项目名称:alienvault-ossim,代码行数:69,代码来源:OssimDBTest.py


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