def test_full_backup_04(self):
        """ Backup -> change one file -> Backup -> check if 2nd backup """
        bck_params = BackupParameters()
        # Every archive will be one(1) disc.
        bck_params.single_archive_size = 1050
        bck_params.disc_size = bck_params.single_archive_size

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_root:
                destination_dir1 = destination_root + "/0"
                os.mkdir(destination_dir1)
                destination_dir2 = destination_root + "/1"
                os.mkdir(destination_dir2)

                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir1

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    # change the source
                    self.create_test_file(src_file_list[0], -1)

                    bck_params = BackupParameters()
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.single_archive_size = 1050
                    bck_params.disc_size = bck_params.single_archive_size
                    bck_params.destination = destination_dir2

                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    for subdir, dirs, files in os.walk(destination_dir2):
                        assert len(dirs) != 0 or len(files) != 0, \
                            "There should be directories <%s> or files <%s>" % (dirs, files)

                    with tempfile.TemporaryDirectory() as restore_dir:
                        rst_params = RestoreParameters()
                        rst_params.database_location = db_filename.name
                        rst_params.source = destination_root
                        rst_params.destination = restore_dir
                        rst_params.encryption_key = bck_params.encryption_key

                        ctrl = RestoreController(GeneralSettings())
                        ctrl.execute(rst_params)

                        assert DirCompare(source_dir, restore_dir).compare()
    def test_backup_01(self):
        """ Backup -> validate backup structure (unencrypted) """
        bck_params = BackupParameters()
        expected_extensions = ['tar.bz2', 'sqlite', 'yml']

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_dir:
                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir

                    # Every archive will be one(1) disc.
                    bck_params.single_archive_size = 1050
                    bck_params.disc_size = bck_params.single_archive_size

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    for subdir, dirs, files in os.walk(destination_dir):
                        for file in files:
                            ok = False
                            for ext in expected_extensions:
                                if file.endswith(ext):
                                    ok = True
                                    break

                            assert ok, "Found file that was not expected <%s>" % file
    def test_backup_00(self):
        """ Backup -> read database """
        bck_params = BackupParameters()

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_dir:
                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir

                    # Every archive will be one(1) disc.
                    bck_params.single_archive_size = 1050
                    bck_params.disc_size = bck_params.single_archive_size

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    db = DatabaseManager(db_filename.name)
                    backup_reader = db.read_backup(None)

                    for file in src_file_list:
                        relative_file = file[len(bck_params.database_location
                                                 ):]
                        test = backup_reader.find_relative_file(relative_file)
                        assert test is not None
    def test_full_backup_03(self):
        """ Backup -> Backup -> check if 2nd backup is empty """
        bck_params = BackupParameters()
        # Every archive will be one(1) disc.
        bck_params.single_archive_size = 1050
        bck_params.disc_size = bck_params.single_archive_size

        with tempfile.NamedTemporaryFile() as db_filename:
            with tempfile.TemporaryDirectory() as destination_dir:
                with tempfile.TemporaryDirectory() as source_dir:
                    bck_params.database_location = db_filename.name
                    bck_params.source = source_dir
                    bck_params.destination = destination_dir

                    src_file_list = self.create_sourceStructure(
                        source_dir, [10, 10])
                    ctrl = BackupController(GeneralSettings())

                    # Preparations complete start backup...
                    ctrl.execute(bck_params)
                    # ... backup ended.

                    with tempfile.TemporaryDirectory() as destination_dir2:
                        bck_params = BackupParameters()
                        bck_params.database_location = db_filename.name
                        bck_params.source = source_dir
                        bck_params.single_archive_size = 1050
                        bck_params.disc_size = bck_params.single_archive_size
                        bck_params.destination = destination_dir2

                        ctrl = BackupController(GeneralSettings())

                        # Preparations complete start backup...
                        ctrl.execute(bck_params)
                        # ... backup ended.

                        for subdir, dirs, files in os.walk(destination_dir2):
                            assert len(
                                dirs
                            ) == 0, "Found file that was not expected <%s>" % dirs