示例#1
0
 def test_create_pull2(self):
     self.user = h_register_dummy_user_device_client()
     interface.add_sync_folder(self.folder1_abs_local_path, "folder1")
     file_path = os.path.join(self.folder1_abs_local_path, "dummy.txt")
     with open(file_path, "w") as f:
         f.write("Hello World")
     time.sleep(1)
     synchronization.full_synchronize()
     time.sleep(2)
     expected_path = os.path.join(
         path_utils.get_users_root_folder(self.user.user_id),
         "folder1/dummy.txt")
     self.assertTrue(os.path.exists(expected_path),
                     "dummy file is not pulled to server!")
    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)
示例#3
0
    def putest_start_logged_in(self):
        user = h_register_dummy_user_device_client()
        main_thread = threading.Thread(target=main.start, daemon=True)
        main_thread.start()
        time.sleep(2)  # wait till changes.json is created

        interface.add_sync_folder(self.folder1_abs_local_path, "folder1")
        expected_content = c_json.get_all_data()
        file_path = os.path.join(self.folder1_abs_local_path, "dummy.txt")
        with open(file_path, "w") as f:
            f.write("Hello World")
        time.sleep(5)  # wait till synchronization finished
        expected_path = os.path.join(
            server_paths.get_users_root_folder(user.user_id),
            "folder1/dummy.txt")
        self.assertTrue(os.path.exists(expected_path),
                        "dummy file is not pulled to server!")
        self.assertEqual(expected_content, c_json.get_all_data())
        time.sleep(1)  # wait till waiting...
    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