Пример #1
0
 def setUp(self) -> None:
     h_clear_init_all_folders()
     self._server_process = h_start_server_process()
     self.folder1_abs_local_path = client_paths.normalize_path(
         client_paths.LOCAL_CLIENT_DATA, "folder1")
     h_create_empty(self.folder1_abs_local_path)
     main.MIN_UPDATE_PAUSE_TIME = 1
Пример #2
0
def h_create_files_folders(abs_dest_path: str, structure: dict, start_empty=False):
    """

    :param abs_dest_path: files and folders are created inside
    :param structure: A dict with the following structure:

        Folder:
            "folder_name": top_folder_name,
            "files": List[file_names]
            "folders": List[Folder]

    :param start_empty: removes everything that is already in the folder at the beginning
    :return: None
    """
    if start_empty:
        h_create_empty(abs_dest_path)

    def recursive_creation(inner_abs_path: str, folder: dict):
        try:
            os.mkdir(inner_abs_path)
        except FileExistsError:
            pass
        for file in folder["files"]:
            file_path = os.path.join(inner_abs_path, file)
            with open(file_path, "w"):
                pass
            time.sleep(0.5)
        for f in folder["folders"]:
            f_path = os.path.join(inner_abs_path, f["folder_name"])
            recursive_creation(f_path, f)

    return recursive_creation(abs_dest_path, structure)
Пример #3
0
def simulate_explorer():
    h_create_empty(
        client_paths.normalize_path(client_paths.LOCAL_CLIENT_DATA, "folder1"))
    h_register_dummy_user_device_client()
    file_changes_json.init_file(empty=True)
    h_add_dummy_server_folder("folder1")
    h_add_dummy_server_folder("folder2")
    gui.main.main()
def h_setup_execution_env():
    server_folder = os.path.join(server_paths.FOLDERS_ROOT, 'user_1/folder1')
    h_register_dummy_user_device_client()
    h_create_empty(server_folder)

    client_folder = os.path.join(client_paths.LOCAL_CLIENT_DATA, "folder1")
    h_create_empty(client_folder)
    return server_folder
Пример #5
0
 def setUp(self) -> None:
     time.sleep(0.2)
     if file_changes.observer.is_alive():
         file_changes.stop_observing()
     # file_changes.observer.unschedule_all()
     h_clear_init_all_folders()
     self._server_process = h_start_server_process()
     file_changes_json.init_file(empty=True)
     file_changes.start_observing()
     self.folder1_abs_local_path = client_paths.normalize_path(
         client_paths.LOCAL_CLIENT_DATA, "folder1")
     h_create_empty(self.folder1_abs_local_path)
    def test_execute_client_actions_delete(self):
        h_create_empty(os.path.join(client_paths.LOCAL_CLIENT_DATA, "folder1"))
        client_src_path = os.path.join(client_paths.LOCAL_CLIENT_DATA,
                                       "folder1/test.txt")
        with open(client_src_path, "w") as f:
            f.write("Lorem ipsum " * 10)

        client_actions = [
            c_sync.create_action(
                gen_paths.normalize_path(client_paths.LOCAL_CLIENT_DATA,
                                         "folder1"),
                gen_paths.normalize_path("test.txt"), gen_json.ACTION_DELETE)
        ]
        c_sync.execute_client_actions(client_actions)
        self.assertFalse(os.path.isfile(client_src_path))
Пример #7
0
    def test_merge_folders(self):
        c_json.init_file(empty=True)
        h_register_dummy_user_device_client()
        abs_local_path = normalize_path(c_paths.LOCAL_CLIENT_DATA, "folder1")
        h_create_empty(abs_local_path)
        dummy_content = {"folder_name": "folder1", "files": ["test.txt", "test2.txt"], "folders": [
            {"folder_name": "inner1", "files": ["inner1_test.txt", "inner1_test2.txt"], "folders": []},
            {"folder_name": "inner2", "files": ["inner2_test.txt", "inner2_test2.txt"], "folders": []}
        ]}
        h_create_files_folders(abs_local_path, dummy_content)

        interface.add_sync_folder(abs_local_path, "folder1")

        server_path = path_utils.rel_user_path_to_abs("folder1", 1)
        current_structure = gen_merge_folders.generate_content_of_folder(server_path, only_files_list=True,
                                                                         top_folder_name="folder1")
        expected_structure = dummy_content
        self.assertEqual(expected_structure, current_structure)
Пример #8
0
    def h_test_merge_method(self, merge_method, f1_init_content, f2_init_content, expected_content):
        c_json.init_file(empty=True)
        h_register_dummy_user_device_client()
        abs_local_path = normalize_path(c_paths.LOCAL_CLIENT_DATA, "folder1")
        h_create_empty(abs_local_path)
        f1_path = os.path.join(c_paths.LOCAL_CLIENT_DATA, "folder1")
        f2_path = path_utils.rel_user_path_to_abs("folder1", 1)
        net_interface.server.add_folder(f2_init_content["folder_name"])

        h_create_files_folders(f1_path, f1_init_content)
        h_create_files_folders(f2_path, f2_init_content)

        yield

        interface.add_sync_folder(abs_local_path, "folder1", merge_method=merge_method)

        f1_structure = gen_merge_folders.generate_content_of_folder(f1_path, only_files_list=True,
                                                                    top_folder_name=f1_init_content["folder_name"])
        f2_structure = gen_merge_folders.generate_content_of_folder(f2_path, only_files_list=True,
                                                                    top_folder_name=f2_init_content["folder_name"])
        self.assertEqual(expected_content, f2_structure)
        self.assertEqual(expected_content, f1_structure)
        yield
Пример #9
0
def h_create_empty_dummy_folder(id_: int = 1) -> paths.NormalizedPath:
    path = os.path.join(paths.LOCAL_CLIENT_DATA, f"dummy_folder_{id_}")
    h_create_empty(path)
    return paths.normalize_path(path)