コード例 #1
0
ファイル: coretest.py プロジェクト: BorjaPintos/whatthefile
    def test_run_zipextractor(self):
        conf = WhatTheFileConfiguration()
        output_safe_directory = "./tests/examples/safe_directory"
        conf.parse_string("""
        [whatthefile]
        modules_package = src.modules
        safe_output_path = """ + output_safe_directory + """
        output = list
        log_output = stdout
        [module.zipextractor]
        active = true
        """)

        final_file = os.path.abspath(output_safe_directory) + \
                     "/1/zipextractor/" + \
                     os.path.abspath("./tests/examples/collie.jpg.zip/collie.jpg").replace(":", "")
        final_file = os.path.abspath(final_file)
        if os.path.exists(final_file):
            os.remove(final_file)
        self._remove_test_folders(output_safe_directory)

        self.assertFalse(os.path.exists(final_file))
        path = "./tests/examples/collie.jpg.zip"
        output = OutputFactory.get_output_by_conf(conf)
        core = Core(conf, output)
        core.run(path)
        self.assertTrue(os.path.exists(final_file))

        paths = []
        for element in output.get_list():
            paths.append(element["path"])
        self.assertTrue(os.path.abspath(final_file) in paths)

        os.remove(final_file)
        self._remove_test_folders(output_safe_directory)
コード例 #2
0
ファイル: coretest.py プロジェクト: BorjaPintos/whatthefile
    def test_zipextractor_unzip_with_zip_inside(self):

        output_safe_directory = "./tests/examples/safe_directory"
        final_file = os.path.abspath(output_safe_directory) + \
                     "/2/zipextractor/" + \
                     os.path.abspath(output_safe_directory).replace(":", "") + \
                     "/1/zipextractor/" + \
                     os.path.abspath("./tests/examples/folderzip.zip/folderzip/Surprisezip.txt.zip/Surprisezip.txt").replace(":", "")
        final_file = os.path.abspath(final_file)
        temporal_zip = os.path.abspath(output_safe_directory) + \
                       "/1/zipextractor/" + \
                       os.path.abspath("./tests/examples/folderzip.zip/folderzip/Surprisezip.txt.zip").replace(":", "")
        temporal_zip = os.path.abspath(temporal_zip)
        conf = WhatTheFileConfiguration()
        conf.parse_string("""
                [whatthefile]
                modules_package = src.modules
                safe_output_path = """ + output_safe_directory + """
                output = list
                log_output = stdout
                [module.zipextractor]
                active = true
                """)

        if os.path.exists(final_file):
            os.remove(final_file)
        self._remove_test_folders(output_safe_directory)

        self.assertFalse(os.path.exists(final_file))
        path = "./tests/examples/folderzip.zip"
        output = OutputFactory.get_output_by_conf(conf)
        core = Core(conf, output)
        core.run(path)

        paths = []
        for element in output.get_list():
            paths.append(os.path.abspath(element["path"]))

        self.assertTrue(temporal_zip in paths)
        self._remove_test_folders(output_safe_directory)
コード例 #3
0
 def test_load_conf_string(self):
     conf = WhatTheFileConfiguration()
     conf.parse_string(self.get_conf_string())
     self.assertEqual(len(conf.get_modules_names()), 10)
     self.assertTrue(conf.get_property_boolean("module.hashes", "active"))
     self.assertTrue("active" in conf.get_section("module.hashes"))