def test_should_copy_folder_for_each_missing_folder_given_some_exist_already( self): setup_storage(self.src_storage, [ { 'folder': self.folder_one, 'files': [self.file_one] }, { 'folder': self.folder_two, 'files': [self.file_one] }, { 'folder': self.folder_three, 'files': [self.file_one] }, { 'folder': self.folder_four, 'files': [self.file_one] }, ]) setup_storage(self.dest_storage, [{ 'folder': self.folder_four, 'files': [self.file_one] }, { 'folder': self.folder_three, 'files': [self.file_one] }]) self.sync.run() self.mock.assert_has_calls_exactly([ call(self.file_one, self.folder_one.name, self.dest_storage), call(self.file_one, self.folder_two.name, self.dest_storage) ], any_order=True)
def test_should_not_copy_files_given_all_files_exist(self): setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }]) self.sync.run() self.mock.assert_not_called()
def test_should_not_delete_additional_files_given_delete_flag_false(self): self.config.delete = False setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_one, 'files': [self.file_one, self.file_two] }]) self.sync.run() self.mock_delete_file.assert_not_called() self.mock_delete_folder.assert_not_called()
def test_should_copy_missing_files_in_existing_folder_given_files_exist( self): setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one, self.file_two] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_one, 'files': [self.file_two] }]) self.sync.run() self.mock.assert_called_once_with(self.file_one, self.folder_one.name, self.dest_storage)
def test_should_delete_additional_files_in_destination(self): self.config.delete = True setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_one, 'files': [self.file_one, self.file_two] }]) self.sync.run() self.mock_delete_file.assert_called_once_with(self.file_two, self.folder_one.name) self.mock_delete_folder.assert_not_called()
def test_should_not_copy_anything_given_dry_run_enabled(self): self.config.dry_run = True setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }, { 'folder': self.folder_two, 'files': [self.file_one, self.file_two] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_two, 'files': [self.file_one] }]) self.sync.run() self.mock.assert_not_called()
def test_should_delete_additional_files_in_destination_when_comparing_root_folders( self): self.config.root_files = True self.config.delete = True setup_storage(self.src_storage, [{ 'folder': self.root_folder, 'files': [self.file_one] }]) setup_storage(self.dest_storage, [{ 'folder': self.root_folder, 'files': [self.file_one, self.file_two] }]) self.sync.run() self.mock_delete_file.assert_called_once_with(self.file_two, '') self.mock_delete_folder.assert_not_called()
def test_should_copy_missing_files_in_existing_folder(self): setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one, self.file_two] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_one, 'files': [] }]) self.sync.run() self.mock.assert_has_calls_exactly([ call(self.file_one, self.folder_one.name, self.dest_storage), call(self.file_two, self.folder_one.name, self.dest_storage) ], any_order=True)
def test_should_not_delete_folder_in_destination_when_last_file_deleted( self): self.config.delete = True setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_one, 'files': [self.file_one, self.file_two] }]) self.sync.run() self.mock_delete_file.assert_has_calls_exactly([ call(self.file_one, self.folder_one.name), call(self.file_two, self.folder_one.name) ], any_order=True) self.mock_delete_folder.assert_not_called()
def test_should_merge_files_in_root_folder_given_root_files_enabled(self): self.config.root_files = True setup_storage(self.src_storage, [ { 'folder': self.root_folder, 'files': [self.file_one, self.file_two] }, ]) setup_storage(self.dest_storage, [ { 'folder': self.root_folder, 'files': [self.file_two] }, ]) self.sync.run() self.mock.assert_has_calls_exactly([ call(self.file_one, '', self.dest_storage), ], any_order=True)
def test_should_skip_copying_when_error_occurs(self): self.mock.side_effect = FileNotFoundError() setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }, { 'folder': self.folder_two, 'files': [self.file_one, self.file_two] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_two, 'files': [self.file_one] }]) self.sync.run() self.mock.assert_has_calls_exactly([ call(self.file_one, self.folder_one.name, self.dest_storage), call(self.file_two, self.folder_two.name, self.dest_storage) ], any_order=True)
def test_should_delete_additional_folders_in_destination(self): self.config.delete = True setup_storage(self.src_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }]) setup_storage(self.dest_storage, [{ 'folder': self.folder_one, 'files': [self.file_one] }, { 'folder': self.folder_two, 'files': [self.file_one, self.file_two] }]) self.sync.run() self.mock_delete_file.assert_has_calls_exactly([ call(self.file_one, self.folder_two.name), call(self.file_two, self.folder_two.name) ], any_order=True) self.mock_delete_folder.assert_called_once_with(self.folder_two)