Exemple #1
0
 def test_rename_directory_src_does_not_exist(self, dir_function):
     basepath = dir_function.path
     src = 'a'
     dst = 'b'
     errors = file_manager.rename_directory(basepath, src, dst)
     assert errors == ['Directory {} does not exist'.format(src)]
     assert not os.path.isdir(os.path.join(basepath, dst))
Exemple #2
0
 def test_rename_directory_src_is_not_a_directory(self, dir_function, test_utils):
     basepath = dir_function.path
     src = 'a'
     dst = 'b'
     test_utils.create_empty_file(basepath, src)
     errors = file_manager.rename_directory(basepath, src, dst)
     assert errors == ['Path {} is not a directory'.format(src)]
     assert not os.path.isdir(os.path.join(basepath, dst))
Exemple #3
0
 def rename_directory(self, dir_name, new_dir_name, file_type):
     """Rename a directory inside tests, pages, or suites folder."""
     errors = validate_project_element_name(new_dir_name)
     if not errors:
         base_path = self.element_directory_path(file_type)
         src = os.sep.join(dir_name.split('.'))
         dst = os.sep.join(new_dir_name.split('.'))
         errors = file_manager.rename_directory(base_path, src, dst)
     return errors
Exemple #4
0
    def test_rename_directory(self, dir_function):
        basepath = dir_function.path
        src = 'a'
        dst = 'b'
        file_manager.create_package_directories(basepath, src)
        errors = file_manager.rename_directory(basepath, src, dst)
        assert errors == []
        assert not os.path.isdir(os.path.join(basepath, src))
        assert os.path.isdir(os.path.join(basepath, dst))
        assert os.path.isfile(os.path.join(basepath, dst, '__init__.py'))

        src = 'q'
        dst = os.sep.join(['w', 'e'])
        file_manager.create_package_directories(basepath, src)
        errors = file_manager.rename_directory(basepath, src, dst)
        assert errors == []
        assert not os.path.isdir(os.path.join(basepath, src))
        assert os.path.isdir(os.path.join(basepath, dst))
        assert os.path.isfile(os.path.join(basepath, dst, '__init__.py'))
Exemple #5
0
 def test_rename_directory_dst_exists(self, dir_function, test_utils):
     """It should return an error when dst is an existing file or folder"""
     basepath = dir_function.path
     # dst is file
     src = 'a'
     dst = 'b'
     file_manager.create_package_directories(basepath, src)
     test_utils.create_empty_file(basepath, dst)
     errors = file_manager.rename_directory(basepath, src, dst)
     assert errors == ['Path {} already exists'.format(dst)]
     assert os.path.isdir(os.path.join(basepath, src))
     assert os.path.isfile(os.path.join(basepath, dst))
     # dst is directory
     src = 'c'
     dst = 'd'
     file_manager.create_package_directories(basepath, src)
     file_manager.create_package_directories(basepath, dst)
     errors = file_manager.rename_directory(basepath, src, dst)
     assert errors == ['Path {} already exists'.format(dst)]
     assert os.path.isdir(os.path.join(basepath, src))
     assert os.path.isdir(os.path.join(basepath, dst))
Exemple #6
0
 def test_rename_directory_to_parent_path(self, dir_function, test_utils):
     """file_manager.rename_directory should return an error
     When renaming a directory to a parent path.
     """
     basepath = dir_function.path
     dst = 'a'
     src = os.sep.join([dst, 'b'])
     file_manager.create_package_directories(basepath, src)
     test_utils.create_empty_file(os.path.join(basepath, src), 'foo.txt')
     errors = file_manager.rename_directory(basepath, src, dst)
     assert errors == ['Path {} already exists'.format(dst)]
     assert os.path.isdir(os.path.join(basepath, src))
     assert os.path.isdir(os.path.join(basepath, dst))
     assert os.path.isfile(os.path.join(basepath, src, '__init__.py'))
     assert os.path.isfile(os.path.join(basepath, src, 'foo.txt'))
Exemple #7
0
 def test_rename_directory_with_files_and_folders(self, dir_function, test_utils):
     basepath = dir_function.path
     src = 'a'
     dst = 'b'
     subfolder = 'c'
     file_manager.create_package_directories(basepath, src)
     test_utils.create_empty_file(os.path.join(basepath, src), 'foo.txt')
     test_utils.create_empty_file(os.path.join(basepath, src, subfolder), 'bar.txt')
     errors = file_manager.rename_directory(basepath, src, dst)
     assert errors == []
     assert not os.path.isdir(os.path.join(basepath, src))
     assert os.path.isdir(os.path.join(basepath, dst))
     assert os.path.isdir(os.path.join(basepath, dst, subfolder))
     assert os.path.isfile(os.path.join(basepath, dst, '__init__.py'))
     assert os.path.isfile(os.path.join(basepath, dst, 'foo.txt'))
     assert os.path.isfile(os.path.join(basepath, dst, subfolder, 'bar.txt'))
Exemple #8
0
 def test_rename_directory_a_file_is_open(self, dir_function, test_utils):
     """A directory cannot be renamed if a child file is currently
     opened by another process.
     """
     basepath = dir_function.path
     src = 'a'
     dst = 'b'
     file_manager.create_package_directories(basepath, src)
     filepath = test_utils.create_empty_file(os.path.join(basepath, src), 'foo.txt')
     filepath_two = test_utils.create_empty_file(os.path.join(basepath, src), 'bar.txt')
     with open(filepath):
         errors = file_manager.rename_directory(basepath, src, dst)
         assert errors == ['Error: PermissionError']
     assert not os.path.isdir(os.path.join(basepath, dst))
     assert os.path.isdir(os.path.join(basepath, src))
     assert os.path.isfile(filepath)
     assert os.path.isfile(filepath_two)
Exemple #9
0
 def test_rename_directory_to_child_path(self, dir_function, test_utils):
     """file_manager.rename_directory should return 'Error: PermissionError'
     When renaming a directory to a descendant path.
     """
     basepath = dir_function.path
     src = 'a'
     dst = os.sep.join([src, 'b'])
     file_manager.create_package_directories(basepath, src)
     test_utils.create_empty_file(os.path.join(basepath, src), 'foo.txt')
     errors = file_manager.rename_directory(basepath, src, dst)
     if os.name == 'nt':
         assert errors == ['Error: PermissionError']
     else:
         assert errors == ['An error occurred while renaming folder']
     assert os.path.isdir(os.path.join(basepath, src))
     assert not os.path.isdir(os.path.join(basepath, dst))
     assert os.path.isfile(os.path.join(basepath, src, '__init__.py'))
     assert os.path.isfile(os.path.join(basepath, src, 'foo.txt'))