def test_empty_bin(self): file_1 = os.path.join(self.test_folder_path, 'file_1') os.mknod(file_1) bin_config_manager.history_add(file_1) clean_path.move(file_1, user_config_manager.get_property('bin_path')) self.assertTrue( os.path.exists( os.path.join(user_config_manager.get_property('bin_path'), 'file_1'))) self.assertFalse(os.path.exists(file_1), msg="File should be in bin.") self.assertEqual(bin_config_manager.history_get('file_1')['src_dir'], os.path.dirname(file_1), msg="Initial preparations fails.") self.assertEqual(bin_command.empty_bin(), 0, msg='Bin command should return success code: 0.') self.assertTrue(os.path.isdir( user_config_manager.get_property('bin_path')), msg="Binempty should not delete existing bin folder.") self.assertFalse( os.path.exists( os.path.join(user_config_manager.get_property('bin_path'), 'file_1'))) self.assertEqual(len(bin_config_manager.get_property('history')), 0)
def move_bin(path, options=None): """Move Function Function allow move bin folder by path with bin history changes. Parameters: path: where to move. options: list of copy politics. Returns: value: 0 - successful, 1 - fail. """ try: # Check if command run in confirm mod and if it's so, ask # user about activity confirmation. if not confirm_question("Try to move bin to: \n{}\n".format(path), "no", options): return 1 # Check if command run in dry mode and if so skip main management # operation and only print info if not bin_config_manager.is_dry_mode(options): clean_path.move(user_config_manager.get_property('bin_path'), os.path.abspath(path)) user_config_manager.set_property('bin_path', os.path.abspath(path)) # Print info about what was done while operation get_log().info(INFO_MESSAGES['bin_move'].format(os.path.abspath(path))) return 0 except Exception as e: get_log().error(e) return 1
def test_move_bin(self): file_1 = os.path.join(self.test_folder_path, 'file_1') bin_move_path = os.path.join(self.test_folder_path, 'bin_move_path') os.mknod(file_1) bin_config_manager.history_add(file_1) clean_path.move(file_1, user_config_manager.get_property('bin_path')) self.assertEqual(bin_command.move_bin(bin_move_path), 0) self.assertFalse( os.path.exists(os.path.join(self.test_bin_path, 'file_1'))) self.assertTrue(os.path.exists(os.path.join(bin_move_path, 'file_1'))) self.assertEqual(user_config_manager.get_property('bin_path'), bin_move_path) self.assertEqual(len(bin_config_manager.get_property('history')), 1)
def test_create_bin(self): file_1 = os.path.join(self.test_folder_path, 'file_1') os.mknod(file_1) clean_path.move(file_1, user_config_manager.get_property('bin_path')) bin_config_manager.history_add(file_1) new_bin_location = os.path.join(self.test_folder_path, 'new_bin_location') self.assertEqual(bin_command.create_bin(new_bin_location), 0, msg='Bin command should return success code: 0.') self.assertEqual(len(bin_config_manager.get_property('history')), 0, msg="New bin should be empty.") self.assertEqual(user_config_manager.get_property('bin_path'), new_bin_location, msg="New path should be writen to user config file")
def test_copy_bin(self): file_1 = os.path.join(self.test_folder_path, 'file_1') bin_copy_path = os.path.join(self.test_folder_path, 'bin_copy_path') os.mknod(file_1) bin_config_manager.history_add(file_1) clean_path.move(file_1, user_config_manager.get_property('bin_path')) self.assertEqual(bin_command.copy_bin(bin_copy_path), 0, msg="Should return success code: 0.") self.assertEqual( len(bin_config_manager.get_property('history')), 1, ) self.assertTrue(os.path.exists(os.path.join(bin_copy_path, 'file_1')), msg="Should copy innear files too") self.assertEqual(user_config_manager.get_property('bin_path'), self.test_bin_path)
def _move_from_bin(paths, options=None): """Copy From Bin Function Do not use this function outside of module. Function allow copy bin files to destination. Parameters: paths: what to copy. options: list of copy politics. """ # Go through every path in paths and move every element # from bin folder for path in paths: # Move obj to src location. clean_path.move( os.path.join( user_config_manager.get_property('bin_path'), bin_config_manager.history_get(path, options)['bin_name'] ), os.path.join( bin_config_manager.history_get(path, options)['src_dir'], bin_config_manager.history_get(path, options)['src_name'], ), options ) # Delete element from history list bin_config_manager.history_del(path, options) # Print Progress bar of operation get_log().info( INFO_MESSAGES['progress_res'].format( ascii_bar.get_progress_bar( paths.index(path) + 1, len(paths) ), path ) )
def test_move_with_file(self): test_dir_dest = os.path.join(self.test_folder_path, 'test_dir_1') test_file_1 = os.path.join(self.test_folder_path, 'test_file_1') os.mkdir(test_dir_dest) os.mknod(test_file_1) self.assertEqual( clean_path.move(test_file_1, test_dir_dest), 0, "Move function should return success code: 0." ) self.assertFalse( os.path.exists(test_file_1), msg="Move should remove current location file." ) self.assertTrue( os.path.exists( os.path.join(test_dir_dest, os.path.basename(test_file_1))), msg="Move should create file in dest location." )
def test_move_with_folder(self): dest_dir = os.path.join(self.test_folder_path, 'dest_dir') os.mkdir(dest_dir) dir_1 = os.path.join(self.test_folder_path, 'dir_1') os.mkdir(dir_1) file_1 = os.path.join(dir_1, 'file_1') os.mknod(file_1) dir_1_after_move = os.path.join(dest_dir, 'dir_1_after_move') self.assertEqual( clean_path.move(dir_1, dir_1_after_move), 0, "Move function should return success code: 0." ) self.assertFalse( os.path.exists(file_1), msg="Move should remove current location file." ) self.assertTrue( os.path.exists( os.path.join(dir_1_after_move, os.path.basename(file_1))), msg="Move should create file in dest location." )