Beispiel #1
0
    def test_error_when_file_does_not_exist(self, exists):
        """
        Test that exception is raised when backup file item on the disk does not exist.
        """
        exists1 = "/a/b/c"
        exists2 = "/d/e/f"
        nonexistent = "/g/f/h"

        def side_effect(filename):
            if filename == exists1 or filename == exists2:
                return True
            else:
                return False

        exists.side_effect = side_effect

        # error is not raised when all files exists
        self.assertIsNone(
            backup._check_item(
                FilesBackupItem(includes=(exists1, exists2),
                                excludes=(),
                                rotation_strategy=None)))

        # error is raised when any of the files missing
        self.assertRaises(
            OSError,
            backup._check_item,
            FilesBackupItem(
                includes=(exists1, exists2),
                excludes=(nonexistent, ),
                rotation_strategy=None,
            ),
        )
Beispiel #2
0
 def __create_file_item(
     self,
     includes: Tuple[str] = ((), ),
     excludes: Tuple[str] = ((), ),
     rotation_strategy: RotationStrategy = None,
 ) -> FilesBackupItem:
     return FilesBackupItem(includes=includes,
                            excludes=excludes,
                            rotation_strategy=rotation_strategy)
Beispiel #3
0
def __parse_files(item: Dict[str, Any]) -> FilesBackupItem:
    if "includes" in item:
        includes = tuple([os.path.expanduser(x) for x in item.get("includes")])
    else:
        includes = ()
    if "excludes" in item:
        excludes = tuple([os.path.expanduser(x) for x in item.get("excludes")])
    else:
        excludes = ()
    return FilesBackupItem(
        includes=includes,
        excludes=excludes,
        rotation_strategy=parse_rotation_strategy(item["rotation_strategy"])
        if "rotation_strategy" in item else None,
    )
Beispiel #4
0
    def test_remote_disk_space(self, transmitter):
        """
        Test error is raised when there is no enough disk space.
        """
        transmitter.get_transfer_file_size.return_value = 2
        transmitter.get_disk_space_available.return_value = 1

        self.assertRaises(
            OSError,
            backup._check_remote_disk_space,
            transmitter,
            "",
            FilesBackupItem(includes=(), excludes=(), rotation_strategy=None),
            "",
            "",
        )
Beispiel #5
0
    def test_backup_verified_error(self, subprocess):
        item = FilesBackupItem(
            includes=(("/a/b/c"),), excludes=(("/a/b/c/d"),), rotation_strategy=None
        )
        server = SshBackupServer(
            name="name",
            rotation_strategy=RotationStrategy(0, 0, 0),
            location="/location",
            hostname="hostname",
            port=22,
            username="******",
            key_path=None,
        )

        subprocess.return_value = self.__get_subprocess_mock(stdout=(".Xcstpoguax",))

        transmitter = SshTransmitter(server)
        self.assertFalse(transmitter.verify_backup(item, "/remote_path"))
        self.assertTrue(subprocess.called)