def test_save_item_directory_success(self):
        shutil.rmtree(self.dest_dir)

        backup_item = BackupItem(self.source_dir, self.dest_dir)

        self.copy_manager.save_item(backup_item)

        dest_filename = os.path.join(self.source_dir,
                                     os.path.basename(self.source_file.name))

        with open(dest_filename) as f:
            self.assertEqual(f.read(), self.expected_content)
    def test_save_item_directory_dest_exists(self):
        # With the paths generated, rsync copies the source directory into the
        #   destination directory. In order to produce a collision, the whole
        #   source directory must be present.
        shutil.copytree(
            self.source_dir,
            os.path.join(self.dest_dir, os.path.basename(self.source_dir)))

        backup_item = BackupItem(self.source_dir, self.dest_dir)

        with self.assertRaises(DestinationAlreadyExistsError) as exc:
            self.copy_manager.save_item(backup_item)

        self.assertEqual(exc.exception.args,
                         ('Destination already contains colliding files', ))
    def test_creation(self):
        b = BackupItem('local', 'remote')

        self.assertEqual(b.local_path, 'local')
        self.assertEqual(b.remote_path, 'remote')