def test_get_sync_client_unexpected_error(mock_evernote_client): mock_evernote_client.fake_auth_verify_unexpected_error = True network_error_retry_count = 50 max_chunk_results = 200 with pytest.raises(EDAMUserException): cli_app_auth.get_sync_client("fake_token", "evernote", network_error_retry_count, max_chunk_results)
def test_get_sync_client_unexpected_error(mock_evernote_client): mock_evernote_client.fake_auth_verify_unexpected_error = True network_error_retry_count = 50 max_chunk_results = 200 fake_token = "S=1:U=ff:E=fff:C=ff:P=1:A=test222:V=2:H=ff" with pytest.raises(EDAMUserException): cli_app_auth.get_sync_client(fake_token, "evernote", network_error_retry_count, max_chunk_results)
def test_get_sync_client_token_invalid_error(mock_evernote_client): mock_evernote_client.fake_is_token_invalid = True network_error_retry_count = 50 max_chunk_results = 200 with pytest.raises(ProgramTerminatedError) as excinfo: cli_app_auth.get_sync_client("fake_token", "evernote", network_error_retry_count, max_chunk_results) assert str(excinfo.value) == "Invalid authentication token!"
def test_get_sync_client_token_expired_error(mock_evernote_client): mock_evernote_client.fake_is_token_expired = True network_error_retry_count = 50 max_chunk_results = 200 fake_token = "S=1:U=ff:E=fff:C=ff:P=1:A=test222:V=2:H=ff" with pytest.raises(ProgramTerminatedError) as excinfo: cli_app_auth.get_sync_client(fake_token, "evernote", network_error_retry_count, max_chunk_results) assert str(excinfo.value) == "Authentication token expired or revoked!"
def sync( database: Path, max_chunk_results: int, max_download_workers: int, download_cache_memory_limit: int, network_retry_count: int, ) -> None: storage = get_storage(database) raise_on_old_database_version(storage) backend = storage.config.get_config_value("backend") auth_token = storage.config.get_config_value("auth_token") note_client = get_sync_client(auth_token, backend, network_retry_count, max_chunk_results) note_synchronizer = NoteSynchronizer(note_client, storage, max_download_workers, download_cache_memory_limit) try: note_synchronizer.sync() except WrongAuthUserError as e: raise ProgramTerminatedError( f"Current user of this database is {e.local_user}, not {e.remote_user}!" " Each user must use a different database file.") logger.info("Synchronization completed!")
def reauth( database: Path, auth_user: Optional[str], auth_password: Optional[str], auth_is_oauth: bool, auth_oauth_port: int, auth_oauth_host: str, auth_token: Optional[str], network_retry_count: int, ) -> None: storage = get_storage(database) raise_on_old_database_version(storage) backend = storage.config.get_config_value("backend") if not auth_token: auth_token = get_auth_token( auth_user, auth_password, auth_is_oauth, auth_oauth_port, auth_oauth_host, backend, network_retry_count, ) note_client = get_sync_client(auth_token, backend, network_retry_count, 1) local_user = storage.config.get_config_value("user") if local_user != note_client.user: raise ProgramTerminatedError( f"Current user of this database is {local_user}, not {note_client.user}!" " Each user must use a different database file.") storage.config.set_config_value("auth_token", auth_token) logger.info(f"Successfully refreshed auth token for {local_user}!")
def init_db( database: Path, auth_user: Optional[str], auth_password: Optional[str], auth_is_oauth: bool, auth_oauth_port: int, auth_oauth_host: str, auth_token: Optional[str], force: bool, backend: str, network_retry_count: int, ) -> None: if not force: raise_on_existing_database(database) if not auth_token: auth_token = get_auth_token( auth_user, auth_password, auth_is_oauth, auth_oauth_port, auth_oauth_host, backend, network_retry_count, ) note_client = get_sync_client(auth_token, backend, network_retry_count, 1) storage = initialize_storage(database, force) new_user = note_client.user storage.config.set_config_value("DB_VERSION", str(CURRENT_DB_VERSION)) storage.config.set_config_value("USN", "0") storage.config.set_config_value("auth_token", auth_token) storage.config.set_config_value("user", new_user) storage.config.set_config_value("backend", backend) logger.info(f"Successfully initialized database for {new_user}!")