Example #1
0
    def testMakeSimpleArchiveZipDir(self):
        file_path = os.path.join(self.fin_path, "testfile.txt")
        with open(file_path, "w") as fh:
            lines = ["toto", "test", "852.90$", "Truc"]
            fh.writelines(lines)

        s_zip = SevenZipFile(self.base_path)
        zip_file_path = os.path.join(self.base_path, "test.7z")
        ret = s_zip.archive_dirs([self.fin_path], "test")
        self.assertTrue(ret)
        self.assertTrue(os.path.exists(zip_file_path))

        unzip_path = os.path.join(self.base_path, "unzip")
        s_zip.extract_all(zip_file_path, unzip_path)
        another_list = os.listdir(unzip_path)
        self.assertEqual(2, len(another_list))
        fin_dir_found = False
        for root, dirs, files in os.walk(unzip_path):
            dirname = os.path.split(root)[1]
            if dirname == "Fin":
                fin_dir_found = True
                self.assertEqual(1, len(files))
                self.assertEqual(files[0], "testfile.txt")
        self.assertTrue(fin_dir_found)
Example #2
0
    def testMakeSimpleArchiveZipDir(self):
        file_path = os.path.join(self.fin_path, "testfile.txt")
        with open(file_path, "w") as fh:
            lines = ["toto", "test", "852.90$", "Truc"]
            fh.writelines(lines)

        s_zip = SevenZipFile(self.base_path)
        zip_file_path = os.path.join(self.base_path, "test.7z")
        ret = s_zip.archive_dirs([self.fin_path], "test")
        self.assertTrue(ret)
        self.assertTrue(os.path.exists(zip_file_path))

        unzip_path = os.path.join(self.base_path, "unzip")
        s_zip.extract_all(zip_file_path, unzip_path)
        another_list = os.listdir(unzip_path)
        self.assertEqual(2, len(another_list))
        fin_dir_found = False
        for root, dirs, files in os.walk(unzip_path):
            dirname = os.path.split(root)[1]
            if dirname == "Fin":
                fin_dir_found = True
                self.assertEqual(1, len(files))
                self.assertEqual(files[0], "testfile.txt")
        self.assertTrue(fin_dir_found)
Example #3
0
    def testCopyFoldersConflict(self):
        """
        Test copytree duplicate error management when two folders from two different drives have the same name.
        :return:
        """
        folders = [self.fin_path, self.bank_path, self.other_fin_path]
        for folder in folders:
            file_path = os.path.join(folder, "testfile.doc")
            with open(file_path, "w") as fh:
                fh.write("test")

        make = MakeArchive(None)
        final_dest_p = Path(self.base_path, "final_dest")
        final_dest_p.mkdir()
        final_dest_path = str(final_dest_p)

        make.create_with_dirs(
            [self.fin_path, self.bank_path, self.other_fin_path],
            self.base_path, final_dest_path)
        dir_list = os.listdir(final_dest_path)
        dir_found_dict = {"Fin": False, "Bank": False, "unittest_Fin": False}

        for file in dir_list:
            ext = os.path.splitext(file)[1]
            if ext == ".7z":
                unzip_path = os.path.join(self.base_path, "unzip")
                zip_file_path = os.path.join(final_dest_path, file)
                s_zip = SevenZipFile(zip_file_path)
                ret = s_zip.extract_all(zip_file_path, unzip_path)
                self.assertTrue(ret)
                another_list = os.listdir(unzip_path)
                self.assertEqual(1 + len(folders), len(another_list))
                for root, dirs, files in os.walk(unzip_path):
                    dirname = os.path.split(root)[1]
                    if dirname == "Fin" or dirname == "Bank" or dirname == "unittest_Fin":
                        dir_found_dict[dirname] = True
                        self.assertEqual(1, len(files))
                        for doc_file in files:
                            self.assertEqual("testfile.doc", doc_file)
            else:
                self.assertFalse(True)

            self.assertTrue(dir_found_dict["Fin"])
            self.assertTrue(dir_found_dict["Bank"])
            self.assertTrue(dir_found_dict["unittest_Fin"])
Example #4
0
    def testCopyFoldersConflict(self):
        """
        Test copytree duplicate error management when two folders from two different drives have the same name.
        :return:
        """
        folders = [self.fin_path, self.bank_path, self.other_fin_path]
        for folder in folders:
            file_path = os.path.join(folder, "testfile.doc")
            with open(file_path, "w") as fh:
                fh.write("test")

        make = MakeArchive(None)
        final_dest_p = Path(self.base_path, "final_dest")
        final_dest_p.mkdir()
        final_dest_path = str(final_dest_p)

        make.create_with_dirs([self.fin_path, self.bank_path, self.other_fin_path],
                              self.base_path, final_dest_path)
        dir_list = os.listdir(final_dest_path)
        dir_found_dict = {"Fin" : False, "Bank" : False, "unittest_Fin": False}

        for file in dir_list:
            ext = os.path.splitext(file)[1]
            if ext == ".7z":
                unzip_path = os.path.join(self.base_path, "unzip")
                zip_file_path = os.path.join(final_dest_path, file)
                s_zip = SevenZipFile(zip_file_path)
                ret = s_zip.extract_all(zip_file_path, unzip_path)
                self.assertTrue(ret)
                another_list = os.listdir(unzip_path)
                self.assertEqual(1+len(folders), len(another_list))
                for root, dirs, files in os.walk(unzip_path):
                    dirname = os.path.split(root)[1]
                    if dirname == "Fin" or dirname == "Bank" or dirname == "unittest_Fin":
                        dir_found_dict[dirname] = True
                        self.assertEqual(1, len(files))
                        for doc_file in files:
                            self.assertEqual("testfile.doc", doc_file)
            else:
                self.assertFalse(True)

            self.assertTrue(dir_found_dict["Fin"])
            self.assertTrue(dir_found_dict["Bank"])
            self.assertTrue(dir_found_dict["unittest_Fin"])
Example #5
0
    def testFullMake(self):
        folders = [self.fin_path, self.bank_path]
        for folder in folders:
            file_path = os.path.join(folder, "testfile.doc")
            with open(file_path, "w") as fh:
                fh.write("test")

        make = MakeArchive(None)
        final_dest_p = Path(self.base_path, "final_dest")
        final_dest_p.mkdir()
        final_dest_path = str(final_dest_p)

        make.create_with_dirs([self.fin_path, self.bank_path], self.base_path,
                              final_dest_path)
        dir_list = os.listdir(final_dest_path)
        dir_found_dict = {"Fin": False, "Bank": False}

        for file in dir_list:
            ext = os.path.splitext(file)[1]
            if ext == ".7z":
                unzip_path = os.path.join(self.base_path, "unzip")
                zip_file_path = os.path.join(final_dest_path, file)
                s_zip = SevenZipFile(zip_file_path)
                ret = s_zip.extract_all(zip_file_path, unzip_path)
                self.assertTrue(ret)
                another_list = os.listdir(unzip_path)
                self.assertEqual(1 + len(folders), len(another_list))
                for root, dirs, files in os.walk(unzip_path):
                    dirname = os.path.split(root)[1]
                    if dirname == "Fin" or dirname == "Bank":
                        dir_found_dict[dirname] = True
                        self.assertEqual(1, len(files))
                        for doc_file in files:
                            self.assertEqual("testfile.doc", doc_file)
            else:
                self.assertFalse(True)

            self.assertTrue(dir_found_dict["Fin"])
            self.assertTrue(dir_found_dict["Bank"])
Example #6
0
    def testFullMake(self):
        folders = [self.fin_path, self.bank_path]
        for folder in folders:
            file_path = os.path.join(folder, "testfile.doc")
            with open(file_path, "w") as fh:
                fh.write("test")

        make = MakeArchive(None)
        final_dest_p = Path(self.base_path, "final_dest")
        final_dest_p.mkdir()
        final_dest_path = str(final_dest_p)

        make.create_with_dirs([self.fin_path, self.bank_path], self.base_path, final_dest_path)
        dir_list = os.listdir(final_dest_path)
        dir_found_dict = {"Fin" : False, "Bank" : False}

        for file in dir_list:
            ext = os.path.splitext(file)[1]
            if ext == ".7z":
                unzip_path = os.path.join(self.base_path, "unzip")
                zip_file_path = os.path.join(final_dest_path, file)
                s_zip = SevenZipFile(zip_file_path)
                ret = s_zip.extract_all(zip_file_path, unzip_path)
                self.assertTrue(ret)
                another_list = os.listdir(unzip_path)
                self.assertEqual(1+len(folders), len(another_list))
                for root, dirs, files in os.walk(unzip_path):
                    dirname = os.path.split(root)[1]
                    if dirname == "Fin" or dirname == "Bank":
                        dir_found_dict[dirname] = True
                        self.assertEqual(1, len(files))
                        for doc_file in files:
                            self.assertEqual("testfile.doc", doc_file)
            else:
                self.assertFalse(True)

            self.assertTrue(dir_found_dict["Fin"])
            self.assertTrue(dir_found_dict["Bank"])