diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py index 22f76be86..0e9cffd69 100644 --- a/web/pgadmin/misc/bgprocess/processes.py +++ b/web/pgadmin/misc/bgprocess/processes.py @@ -68,9 +68,9 @@ class IProcessDesc(object, metaclass=ABCMeta): try: # check if file name is encoded with UTF-8 file = self.bfile.decode('utf-8') - except Exception as e: - str(e) + except Exception: # do nothing if bfile is not encoded. + pass path = get_complete_file_path(file) path = file if path is None else path @@ -87,14 +87,7 @@ class IProcessDesc(object, metaclass=ABCMeta): else: last_dir = file - if IS_WIN: - if '\\' in last_dir: - if len(last_dir) == 1: - last_dir = last_dir.replace('\\', '\\\\') - else: - last_dir = last_dir.replace('\\', '/') - else: - last_dir = last_dir.replace('\\', '/') + last_dir = replace_path_for_win(last_dir) return None if hasattr(self, 'is_import') and self.is_import \ else last_dir @@ -102,6 +95,16 @@ class IProcessDesc(object, metaclass=ABCMeta): return None +def replace_path_for_win(last_dir=None): + if IS_WIN: + if '\\' in last_dir and len(last_dir) == 1: + last_dir = last_dir.replace('\\', '\\\\') + else: + last_dir = last_dir.replace('\\', '/') + + return last_dir + + class BatchProcess(object): def __init__(self, **kwargs): diff --git a/web/pgadmin/tools/backup/__init__.py b/web/pgadmin/tools/backup/__init__.py index 6ddd38db4..da388ad26 100644 --- a/web/pgadmin/tools/backup/__init__.py +++ b/web/pgadmin/tools/backup/__init__.py @@ -141,11 +141,6 @@ class BackupMessage(IProcessDesc): # It should never reach here. return _("Unknown Backup") - # @property - # def current_storage_dir(self): - # return self.bfile if os.path.isdir(self.bfile) \ - # else os.path.dirname(self.bfile) - @property def message(self): name, host, port = self.get_server_details() diff --git a/web/pgadmin/tools/backup/tests/test_batch_process.py b/web/pgadmin/tools/backup/tests/test_batch_process.py index 7d2c8e712..bc8be539b 100644 --- a/web/pgadmin/tools/backup/tests/test_batch_process.py +++ b/web/pgadmin/tools/backup/tests/test_batch_process.py @@ -199,11 +199,15 @@ class BatchProcessTest(BaseTestGenerator): self.assertTrue(popen_mock.called) + @patch('os.path.realpath') + @patch('pgadmin.misc.bgprocess.processes.get_storage_directory') + @patch('pgadmin.misc.bgprocess.processes.get_complete_file_path') @patch('pgadmin.misc.bgprocess.processes.Process') @patch('pgadmin.misc.bgprocess.processes.BatchProcess.' 'update_process_info') def _check_list(self, p, backup_obj, update_process_info_mock, - process_mock): + process_mock, get_complete_file_path_mock, + get_storage_directory_mock, realpath_mock): class TestMockProcess(): def __init__(self, desc, args, cmd): self.pid = 1 @@ -222,6 +226,9 @@ class BatchProcessTest(BaseTestGenerator): self.class_params['cmd'])] update_process_info_mock.return_value = [True, True] + get_complete_file_path_mock.return_value = self.class_params['bfile'] + realpath_mock.return_value = self.class_params['bfile'] + get_storage_directory_mock.return_value = '//' ret_value = p.list() self.assertEqual(1, len(ret_value)) diff --git a/web/pgadmin/tools/import_export/tests/test_batch_process.py b/web/pgadmin/tools/import_export/tests/test_batch_process.py index 241c3a06f..2eab2e21a 100644 --- a/web/pgadmin/tools/import_export/tests/test_batch_process.py +++ b/web/pgadmin/tools/import_export/tests/test_batch_process.py @@ -213,9 +213,8 @@ class BatchProcessTest(BaseTestGenerator): @patch('pgadmin.misc.bgprocess.processes.BatchProcess.' 'update_process_info') def _check_list(self, p, import_export_obj, update_process_info_mock, - process_mock, - get_storage_directory_mock, get_complete_file_path_mock, - realpath_mock): + process_mock, get_complete_file_path_mock, + get_storage_directory_mock, realpath_mock): class TestMockProcess(): def __init__(self, desc, args, cmd): self.pid = 1