def _reinit_database(self): # Close database self.ctl.dispose() # Destroy configuration folder shutil.rmtree(self.nxdrive_conf_folder_1) os.mkdir(self.nxdrive_conf_folder_1) # Recreate a controller self.ctl = Controller(self.nxdrive_conf_folder_1) self.ctl.bind_server(self.local_nxdrive_folder_1, self.nuxeo_url, self.user_1, self.password_1) self.ctl.bind_root(self.local_nxdrive_folder_1, self.workspace) self.syn = self.ctl.synchronizer
def get_controller(self, options): nb_tries = 1 while (nb_tries <= GET_CTL_MAX_NB_TRIES): try: return Controller(options.nxdrive_home, handshake_timeout=options.handshake_timeout, timeout=options.timeout, max_errors=options.max_errors, update_url=options.update_site_url) except OperationalError as e: self.log.error("OperationalError during try #%d to get" " controller, waiting for %d seconds and" " retrying at most %d times" % (nb_tries, GET_CTL_SLEEP_DURATION, GET_CTL_MAX_NB_TRIES - nb_tries), exc_info=True) time.sleep(GET_CTL_SLEEP_DURATION) nb_tries += 1 if nb_tries > 1: raise e
# Useful to launch an interactive debugging session in ipython with %ed or %run from nxdrive.controller import Controller from nxdrive.model import ServerBinding c = Controller('~/.nuxeo-drive') s = c.get_session() sb = s.query(ServerBinding).one()
def get_controller(self, options): return Controller(options.nxdrive_home, handshake_timeout=options.handshake_timeout, timeout=options.timeout, max_errors=options.max_errors)
def setUp(self): # Check the Nuxeo server test environment self.nuxeo_url = os.environ.get('NXDRIVE_TEST_NUXEO_URL') self.admin_user = os.environ.get('NXDRIVE_TEST_USER') self.password = os.environ.get('NXDRIVE_TEST_PASSWORD') # Take default parameter if none has been set if self.nuxeo_url is None: self.nuxeo_url = "http://localhost:8080/nuxeo" if self.admin_user is None: self.admin_user = "******" if self.password is None: self.password = "******" if None in (self.nuxeo_url, self.admin_user, self.password): raise unittest.SkipTest( "No integration server configuration found in environment.") # Check the local filesystem test environment self.local_test_folder_1 = tempfile.mkdtemp(u'-nxdrive-tests-user-1') self.local_test_folder_2 = tempfile.mkdtemp(u'-nxdrive-tests-user-2') self.local_nxdrive_folder_1 = os.path.join(self.local_test_folder_1, u'Nuxeo Drive') os.mkdir(self.local_nxdrive_folder_1) self.local_nxdrive_folder_2 = os.path.join(self.local_test_folder_2, u'Nuxeo Drive') os.mkdir(self.local_nxdrive_folder_2) self.nxdrive_conf_folder_1 = os.path.join(self.local_test_folder_1, u'nuxeo-drive-conf') os.mkdir(self.nxdrive_conf_folder_1) self.nxdrive_conf_folder_2 = os.path.join(self.local_test_folder_2, u'nuxeo-drive-conf') os.mkdir(self.nxdrive_conf_folder_2) # Set echo to True to enable SQL statements and transactions logging # and echo_pool to True to enable connection pool logging self.controller_1 = Controller(self.nxdrive_conf_folder_1, echo=False, echo_pool=False) self.controller_2 = Controller(self.nxdrive_conf_folder_2, echo=False, echo_pool=False) self.controller_1.synchronizer.test_delay = 3 self.controller_2.synchronizer.test_delay = 3 self.version = self.controller_1.get_version() # Long timeout for the root client that is responsible for the test # environment set: this client is doing the first query on the Nuxeo # server and might need to wait for a long time without failing for # Nuxeo to finish initialize the repo on the first request after # startup root_remote_client = RemoteDocumentClient( self.nuxeo_url, self.admin_user, u'nxdrive-test-administrator-device', self.version, password=self.password, base_folder=u'/', timeout=60) # Call the Nuxeo operation to setup the integration test environment credentials = root_remote_client.execute( "NuxeoDrive.SetupIntegrationTests", userNames="user_1, user_2", permission='ReadWrite') credentials = [c.strip().split(u":") for c in credentials.split(u",")] self.user_1, self.password_1 = credentials[0] self.user_2, self.password_2 = credentials[1] ws_info = root_remote_client.fetch(self.TEST_WORKSPACE_PATH) self.workspace = ws_info[u'uid'] self.workspace_title = ws_info[u'title'] # Document client to be used to create remote test documents # and folders self.upload_tmp_dir = tempfile.mkdtemp(u'-nxdrive-uploads') remote_document_client_1 = RemoteDocumentClient( self.nuxeo_url, self.user_1, u'nxdrive-test-device-1', self.version, password=self.password_1, base_folder=self.workspace, upload_tmp_dir=self.upload_tmp_dir) remote_document_client_2 = RemoteDocumentClient( self.nuxeo_url, self.user_2, u'nxdrive-test-device-2', self.version, password=self.password_2, base_folder=self.workspace, upload_tmp_dir=self.upload_tmp_dir) # File system client to be used to create remote test documents # and folders remote_file_system_client_1 = RemoteFileSystemClient( self.nuxeo_url, self.user_1, u'nxdrive-test-device-1', self.version, password=self.password_1, upload_tmp_dir=self.upload_tmp_dir) remote_file_system_client_2 = RemoteFileSystemClient( self.nuxeo_url, self.user_2, u'nxdrive-test-device-2', self.version, password=self.password_2, upload_tmp_dir=self.upload_tmp_dir) self.root_remote_client = root_remote_client self.remote_document_client_1 = remote_document_client_1 self.remote_document_client_2 = remote_document_client_2 self.remote_file_system_client_1 = remote_file_system_client_1 self.remote_file_system_client_2 = remote_file_system_client_2