def sync(): sync = SyncEngine(DropboxClient("test-config")) sync.dropbox_path = "/" yield sync remove_configuration("test-config")
def config_name(prefix: str = "test-config"): i = 0 config_name = f"{prefix}-{i}" while config_name in list_configs(): i += 1 config_name = f"{prefix}-{i}" yield config_name res = stop_maestral_daemon_process(config_name) if res is Stop.Failed: raise RuntimeError("Could not stop test daemon") remove_configuration(config_name)
def sync(): local_dir = osp.join(get_home_dir(), "dummy_dir") os.mkdir(local_dir) sync = SyncEngine(DropboxClient("test-config")) sync.fs_events.enable() sync.dropbox_path = local_dir observer = Observer() observer.schedule(sync.fs_events, sync.dropbox_path, recursive=True) observer.start() yield sync observer.stop() observer.join() remove_configuration("test-config") delete(sync.dropbox_path)
def m(): config_name = "test-config" m = Maestral(config_name) m.log_level = logging.DEBUG # link with given token access_token = os.environ.get("DROPBOX_ACCESS_TOKEN") refresh_token = os.environ.get("DROPBOX_REFRESH_TOKEN") if access_token: m.client._init_sdk_with_token(access_token=access_token) m.client.auth._access_token = access_token m.client.auth._token_access_type = "legacy" elif refresh_token: m.client._init_sdk_with_token(refresh_token=refresh_token) m.client.auth._refresh_token = refresh_token m.client.auth._token_access_type = "offline" else: raise RuntimeError( "Either access token or refresh token must be given as environment " "variable DROPBOX_ACCESS_TOKEN or DROPBOX_REFRESH_TOKEN." ) # get corresponding Dropbox ID and store in keyring for other processes res = m.client.get_account_info() m.client.auth._account_id = res.account_id m.client.auth.loaded = True m.client.auth.save_creds() # set local Dropbox directory home = get_home_dir() local_dropbox_dir = generate_cc_name(home + "/Dropbox", suffix="test runner") m.create_dropbox_directory(local_dropbox_dir) # acquire test lock and perform initial sync lock = DropboxTestLock(m) if not lock.acquire(timeout=60 * 60): raise TimeoutError("Could not acquire test lock") # create / clean our temporary test folder m.test_folder_dbx = "/sync_tests" m.test_folder_local = m.to_local_path(m.test_folder_dbx) try: m.client.remove(m.test_folder_dbx) except NotFoundError: pass m.client.make_dir(m.test_folder_dbx) # start syncing m.start_sync() wait_for_idle(m) # return synced and running instance yield m # stop syncing and clean up remote folder m.stop_sync() try: m.client.remove(m.test_folder_dbx) except NotFoundError: pass try: m.client.remove("/.mignore") except NotFoundError: pass # remove all shared links res = m.client.list_shared_links() for link in res.links: m.revoke_shared_link(link.url) # remove creds from system keyring m.client.auth.delete_creds() # remove local files and folders delete(m.dropbox_path) remove_configuration(m.config_name) # release lock lock.release()
def client(): yield DropboxClient("test-config") remove_configuration("test-config")
def m(): m = Maestral("test-config") m._conf.save() yield m remove_configuration(m.config_name)
def m(): m = Maestral("test-config") m.log_level = logging.DEBUG m._conf.save() yield m remove_configuration(m.config_name)