def test_pull_dir_client_to_server(self): """Copy dir from client to server""" h_register_dummy_user_device_client() client_folder = gen_paths.normalize_path( client_paths.LOCAL_CLIENT_DATA, "folder1") h_fill_dummy_dir(client_folder) actions = [ c_sync.create_action(gen_paths.normalize_path("folder1"), gen_paths.normalize_path(""), gen_json.ACTION_PULL, remote_abs_path=client_folder, is_directory=True) ] net_interface.server.execute_actions(actions) self.assertTrue( os.path.exists((path_utils.rel_user_path_to_abs("folder1", 1)))) self.assertTrue( os.path.exists( (path_utils.rel_user_path_to_abs("folder1/inner1", 1)))) self.assertTrue( os.path.exists( (path_utils.rel_user_path_to_abs("folder1/inner2", 1)))) self.assertTrue( os.path.exists((path_utils.rel_user_path_to_abs( "folder1/inner1/test_inner.txt", 1)))) self.assertTrue( os.path.exists( (path_utils.rel_user_path_to_abs("folder1/test.txt", 1))))
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 simulate_many_folders(): h_register_dummy_user_device_client() file_changes_json.init_file() for i in range(3): h_watch_dummy_folder(f"folder {i}") time.sleep(0.1) time.sleep(2) gui.open_gui()
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
def auto_login(): """Gui auto login -> explorer""" h_register_dummy_user_device_client() file_changes_json.init_file(empty=True) time.sleep(1) main_thread = threading.Thread(target=main_prog.start, daemon=True) main_thread.start() time.sleep(2) #interface.add_sync_folder(c_paths.normalize_path(c_paths.LOCAL_DATA, "folder1"), "folder1") main.main(screens.REGISTRATION, try_auto_login=True)
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)
def test_pull_dir_server_to_client(self): """Copy dir from server to client""" h_register_dummy_user_device_client() server_folder = gen_paths.normalize_path( path_utils.rel_user_path_to_abs("folder1", 1)) client_folder = gen_paths.normalize_path( client_paths.LOCAL_CLIENT_DATA, "folder1") h_fill_dummy_dir(server_folder) net_interface.server.get_dir("folder1", client_folder) self.assertTrue(os.path.exists((os.path.join(client_folder)))) self.assertTrue(os.path.exists((os.path.join(client_folder, "inner1")))) self.assertTrue(os.path.exists((os.path.join(client_folder, "inner2")))) self.assertTrue( os.path.exists((os.path.join(client_folder, "inner1/test_inner.txt")))) self.assertTrue( os.path.exists((os.path.join(client_folder, "test.txt"))))
def demonstration_example(): user = h_register_dummy_user_device_client() print(f"Username: {user.username}") print(f"Password: {user.password}") main_thread = threading.Thread(target=main_prog.start, daemon=True) main_thread.start() time.sleep(3) main.main(screens.LOGIN_MANUAL, try_auto_login=False)
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
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 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 test_login_auto(self): h_register_dummy_user_device_client() status = client_side.interface.login_auto() self.assertTrue(status.was_successful())
def test_login_manual_user_device_cli(self): user = h_register_dummy_user_device_client() inputs = (in_val for in_val in [user.username]) with mock.patch('builtins.input', mock_input(inputs)), mock.patch( "getpass.getpass", return_value=user.password): client_side.authentication.login_manual_user_device_cli()
def test_login_manual(self): user = h_register_dummy_user_device_client() status = client_side.interface.login_manual(user.username, user.password) self.assertTrue(status.was_successful())
def simulate_main(): h_register_dummy_user_device_client() main_thread = threading.Thread(target=main.start, daemon=True) main_thread.start() gui.main.main() main.shutdown()
def test_get_server_changes(self): h_register_dummy_user_device_client() changes = c_sync._get_server_changes() self.assertEqual({}, changes)