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


Python Database.complete方法代码示例

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


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

示例1: run

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import complete [as 别名]
    def run(self):
        """Run manager thread."""
        success = True

        db = Database()
        db.lock(self.task.id)

        try:
            self.launch_analysis()
        except CuckooMachineError as e:
            log.error("Please check virtual machine status: %s" % e.message)
            success = False
        except CuckooAnalysisError as e:
            log.error(e.message)
            success = False
        finally:
            db.complete(self.task.id, success)
开发者ID:Fuitad,项目名称:cuckoo-1,代码行数:19,代码来源:scheduler.py

示例2: setUp

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import complete [as 别名]
class TestDatabase:
    def setUp(self):
        self.tmp = os.path.join(tempfile.mkdtemp(), "dbtestcuckoo")
        self.d = Database(db_file=self.tmp)

    def test_db_path_default(self):
        """@note: Regression unit test."""
        d = Database()
        assert_equals(d.db_file, os.path.join(CUCKOO_ROOT, "db", "cuckoo.db"))
        assert os.path.exists(self.d.db_file)

    def test_db_path_custom(self):
        """@note: Regression unit test."""
        tmp = tempfile.mkstemp()[1]
        d = Database(db_file=tmp)
        assert_equals(d.db_file, tmp)
        assert os.path.exists(self.d.db_file)
        os.remove(tmp)

    def test_generate(self):
        conn = sqlite3.connect(self.tmp)
        cursor = conn.cursor()
        cursor.execute("SELECT count(name) FROM sqlite_master WHERE name='tasks';")
        assert_equals(1, cursor.fetchone()[0])

    def test_add(self):
        tmp = tempfile.mkstemp()[1]
        assert_equals(1, self.d.add(file_path=tmp))
        conn = sqlite3.connect(self.tmp)
        cursor = conn.cursor()
        cursor.execute("SELECT count(*) FROM tasks;")
        assert_equals(1, cursor.fetchone()[0])
        os.remove(tmp)

    def test_add_file_not_found(self):
        assert_equals(None, self.d.add(file_path="foo"))

    def test_fetch(self):
        tmp = tempfile.mkstemp()[1]
        assert_equals(1, self.d.add(file_path=tmp))
        assert_equals(tmp, self.d.fetch()["file_path"])
        conn = sqlite3.connect(self.tmp)
        cursor = conn.cursor()
        cursor.execute("SELECT count(*) FROM tasks;")
        assert_equals(1, cursor.fetchone()[0])
        os.remove(tmp)

    def test_lock(self):
        tmp = tempfile.mkstemp()[1]
        assert_equals(1, self.d.add(file_path=tmp))
        assert self.d.lock(1)
        conn = sqlite3.connect(self.tmp)
        cursor = conn.cursor()
        cursor.execute("SELECT count(*) FROM tasks WHERE lock=0;")
        assert_equals(0, cursor.fetchone()[0])
        os.remove(tmp)

    def test_unlock(self):
        tmp = tempfile.mkstemp()[1]
        assert_equals(1, self.d.add(file_path=tmp))
        assert self.d.lock(1)
        conn = sqlite3.connect(self.tmp)
        cursor = conn.cursor()
        cursor.execute("SELECT count(*) FROM tasks WHERE lock=0;")
        assert_equals(0, cursor.fetchone()[0])
        assert self.d.unlock(1)
        cursor.execute("SELECT count(*) FROM tasks WHERE lock=0;")
        assert_equals(1, cursor.fetchone()[0])
        os.remove(tmp)

    def test_complete_success(self):
        tmp = tempfile.mkstemp()[1]
        assert_equals(1, self.d.add(file_path=tmp))
        assert self.d.complete(1, True)
        conn = sqlite3.connect(self.tmp)
        cursor = conn.cursor()
        cursor.execute("SELECT count(*) FROM tasks WHERE status=2;")
        assert_equals(1, cursor.fetchone()[0])
        os.remove(tmp)

    def test_complete_fail(self):
        tmp = tempfile.mkstemp()[1]
        assert_equals(1, self.d.add(file_path=tmp))
        assert self.d.complete(1, False)
        conn = sqlite3.connect(self.tmp)
        cursor = conn.cursor()
        cursor.execute("SELECT count(*) FROM tasks WHERE status=1;")
        assert_equals(1, cursor.fetchone()[0])
        os.remove(tmp)

    def tearDown(self):
        os.remove(self.tmp)
开发者ID:pellucide,项目名称:test-av,代码行数:94,代码来源:database_tests.py


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