def delete_removed_files(self, local_path: str, bucket_name: str): """ Removes from the target bucket only files that are no longer in the given path. Args: str local_path: path to look for the files. str bucket_name: name of the bucket Returns: list of the deleted files.t """ remote_files = self.get_remote_file_names(bucket_name) local_files = directory_files_recursively(local_path, full_path=False) files_to_delete = get_files_to_delete(local_files, remote_files) if files_to_delete.get('Objects'): return self.delete_aws_files(files_to_delete, bucket_name) else: return []
def test_should_delete_one_file(self): local_file = ['file1'] remote_files = ['file1', 'file2'] removed_files = get_files_to_delete(local_file, remote_files) self.assertEqual({'Objects': [{'Key': 'file2'}]}, removed_files)
def test_should_not_get_error_between_different_iterables(self): local_file = () remote_file = {'test'} removed_files = get_files_to_delete(local_file, remote_file) self.assertEqual({'Objects': [{'Key': 'test'}]}, removed_files)
def test_should_not_get_error_with_tuple_type(self): local_file = ('test',) remote_file = () removed_files = get_files_to_delete(local_file, remote_file) self.assertEqual({'Objects': []}, removed_files)
def test_should_not_get_error_with_none_types(self): local_file = None remote_files = None removed_files = get_files_to_delete(local_file, remote_files) self.assertEqual({'Objects': []}, removed_files)
def test_should_not_delete_empty_list(self): local_file = [] remote_files = [] removed_files = get_files_to_delete(local_file, remote_files) self.assertEqual({'Objects': []}, removed_files)
def test_should_not_delete_any_file(self): local_file = ['file1.exe', 'files2.exe'] remote_files = ['file1.exe', 'files2.exe'] removed_files = get_files_to_delete(local_file, remote_files) self.assertEqual({'Objects': []}, removed_files)
def test_should_delete_file_with_extension(self): local_file = ['file1.exe', 'files2.exe'] remote_files = ['file1.exe', 'files2.exe', 'program 2231.exe'] removed_files = get_files_to_delete(local_file, remote_files) self.assertEqual({'Objects': [{'Key': 'program 2231.exe'}]}, removed_files)