def _is_valid_dest(self, dest): """ Check if the test argument is valid """ result = True if not dest.is_dir(): self.errors.add( error.NoSuchDirectoryToSubcmdInto(self.subcmd, dest)) result = False else: if not utils.is_directory_writable(dest): self.errors.add( error.InsufficientPermissionsToSubcmdTo(self.subcmd, dest)) result = False if not utils.is_directory_readable(dest): self.errors.add( error.InsufficientPermissionsToSubcmdTo(self.subcmd, dest)) result = False if not utils.is_directory_executable(dest): self.errors.add( error.InsufficientPermissionsToSubcmdTo(self.subcmd, dest)) result = False return result
def test_unstow_with_read_only_dest(source_a, dest): dploy.stow([source_a], dest) utils.remove_write_permission(dest) with pytest.raises(PermissionError) as e: dploy.unstow([source_a], dest) assert error.InsufficientPermissionsToSubcmdTo( subcmd=SUBCMD, file=dest).msg in str(e.value)
def test_link_with_read_only_dest(file_a, dest): dest_file = os.path.join(dest, 'file_a_link') utils.remove_write_permission(dest) message = str( error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD, file=dest_file)) with pytest.raises(error.InsufficientPermissionsToSubcmdTo, match=message): dploy.link(file_a, dest_file)
def test_unstow_with_read_only_dest(source_a, dest): dploy.stow([source_a], dest) utils.remove_write_permission(dest) message = str( error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD, file=dest)) with pytest.raises(error.InsufficientPermissionsToSubcmdTo, match=message): dploy.unstow([source_a], dest)
def test_link_with_read_only_dest(file_a, dest): dest_file = os.path.join(dest, 'file_a_link') utils.remove_write_permission(dest) with pytest.raises(PermissionError) as e: dploy.link(file_a, dest_file) assert (error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD, file=dest_file).msg in str(e.value))
def test_unstow_with_dest_dir_with_no_executue_permissions( source_a, source_b, dest): dest_dir = os.path.join(dest, 'aaa') dploy.stow([source_a, source_b], dest) utils.remove_execute_permission(os.path.join(dest, 'aaa')) message = str( error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD, file=dest_dir)) with pytest.raises(error.InsufficientPermissionsToSubcmdTo, match=message): dploy.unstow([source_a, source_b], dest)
def test_unstow_with_dest_dir_with_no_executue_permissions( source_a, source_b, dest): dest_dir = os.path.join(dest, 'aaa') dploy.stow([source_a, source_b], dest) utils.remove_execute_permission(os.path.join(dest, 'aaa')) with pytest.raises(PermissionError) as e: dploy.unstow([source_a, source_b], dest) assert error.InsufficientPermissionsToSubcmdTo(subcmd=SUBCMD, file=dest_dir).msg in str( e.value)
def _is_valid_dest(self, dest): if not dest.parent.exists(): self.errors.add( error.NoSuchFileOrDirectory(self.subcmd, dest.parent)) return False elif (not utils.is_file_writable(dest.parent) or not utils.is_directory_writable(dest.parent)): self.errors.add( error.InsufficientPermissionsToSubcmdTo(self.subcmd, dest)) return False return True