def _removeClicked(self): indexes = self._ui.hostListView.selectedIndexes() rm_index = indexes.pop() item = self._model.itemFromIndex(rm_index) pmr_info = PMR() pmr_info.removeHost(item.text()) self._model.removeRow(rm_index.row())
def setUp(self): self.working_dir = tempfile.mkdtemp() # Because uh, QSettings has very nice API so we need this QSettings.setDefaultFormat(QSettings.Format.IniFormat) # and this line, which include QSettings.setPath( QSettings.Format.IniFormat, # this arg QSettings.Scope.SystemScope, self.working_dir, ) # to have our test settings isolated from the real application. # Insert profanity here: ________________ # now we make our info info = PMR() self.endpoints = [ (info.host() + '/pmr2-dashboard', TestAdapter(stream=workspace_home)), ('http://example.com/dashboard/addworkspace', TestAdapter(stream='', headers={ 'Location': 'http://example.com/w/+/addworkspace', })), ( 'http://example.com/w/+/addworkspace', TestAdapter( # XXX need to make this a real thing when we test that # responses from server matters. stream='', headers={ 'Location': 'http://example.com/w/1', })), ( 'http://example.com/hgrepo', TestAdapter( # XXX need to make this a real thing when we test that # responses from server matters. stream='{"url": "http://example.com/hgrepo", ' '"storage": "git"}', )), ( 'http://example.com/w/1', TestAdapter( # XXX need to make this a real thing when we test that # responses from server matters. stream='{"url": "http://example.com/w/1", ' '"storage": "git"}', )), ('http://example.com/w/1/request_temporary_password', TestAdapter(stream='{"user": "******", "key": "secret"}', )), (info.host() + '/search', TestAdapter(stream='[{"title": "Test Workspace", ' '"target": "http://example.com/w/1"}]', )), ] # and tool, with the end points. self._tool = self.make_tool()
def test_search_failure(self): info = PMR() tool = self.make_tool(endpoints=[ (info.host() + '/search', TestAdapter(stream='Invalid', status=403)), ]) # the private method exposes exceptions self.assertRaises(HTTPError, tool._search, '') # the real method traps all exceptions self.assertRaises(PMRToolError, tool.search, '')
def transferModel(self): """ Transfer the current status of the model into the PMR information object. """ pmr_info = PMR() hosts = pmr_info.hosts() host_names_remove = [name for name in hosts] host_names_new = [] active_host = None index = 0 current_item = self._model.item(index) while current_item: current_host = current_item.text() if current_host in host_names_remove: host_names_remove.remove(current_host) else: host_names_new.append(current_host) if current_item.checkState() == QtCore.Qt.Checked: active_host = current_host index += 1 current_item = self._model.item(index) pmr_info.setActiveHost(active_host) for host in host_names_remove: pmr_info.removeHost(host) for host in host_names_new: pmr_info.addHost(host)
def __init__(self, parent=None): QtWidgets.QDialog.__init__(self, parent) self._ui = Ui_AuthoriseApplicationDialog() self._ui.setupUi(self) pmr_info = PMR() client_tokens = pmr_info.get_client_token_kwargs() self._helper = TokenHelper( client_key=client_tokens['client_key'], client_secret=client_tokens['client_secret'], site_url=pmr_info.host(), )
def configure(self): d = ConfigureDialog(self._state, QtGui.QApplication.activeWindow().currentWidget()) d.setWorkflowLocation(self._location) d.setModal(True) if d.exec_(): self._state = d.getState() # When a PMR location is given we need to translate that into a # local path for passing into the ImageSourceData class local_dir = self._state.location() pmr_location = self._state.pmrLocation() if pmr_location and not len(local_dir): # Get login details: local_dir = self._location if not os.path.exists(local_dir): os.mkdir(local_dir) self._state.setLocation(local_dir) d.setState(self._state) if pmr_location and os.path.exists(local_dir): pmr_info = PMR() pmr_tool = PMRTool(pmr_info) pmr_tool.cloneWorkspace(pmr_location, local_dir) self._configured = d.validate() if self._configuredObserver is not None: self._configuredObserver()
def test_make_session_no_access(self): pmr_info = PMR() tool = PMRTool(pmr_info) session = tool.make_session() self.assertFalse(isinstance(session, OAuth1Session)) # Make sure this really is a requests.Session self.assertTrue(isinstance(session, Session))
def _createNewWorkflow(self, workflow_dir, pmr): m = self._main_window.model().workflowManager() om = self._main_window.model().optionsManager() m.new(workflow_dir) m.setPreviousLocation(workflow_dir) if pmr: pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) if pmr_tool.hasAccess(): dir_name = os.path.basename(workflow_dir) try: repourl = pmr_tool.addWorkspace('Workflow: ' + dir_name, None) pmr_tool.linkWorkspaceDirToUrl(workflow_dir, repourl) except HTTPError as e: logger.exception('Error creating new') self.close() raise ClientRuntimeError( 'Error Creating New', e) else: raise ClientRuntimeError('Error Creating New', "Client doesn't have access to PMR") self._undoStack.clear() self._ui.graphicsView.setLocation(workflow_dir) self._graphicsScene.updateModel() self._update_ui()
def _updateFromPMR(self): m = self._main_window.model().workflowManager() om = self._main_window.model().optionsManager() pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) pmr_tool.pullFromRemote(m.location())
def _commitChanges(self, workflowDir, comment, commit_local=False): committed_changes = False om = self._main_window.model().optionsManager() pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) try: workflow_files = [workflowDir + '/%s' % (DEFAULT_WORKFLOW_PROJECT_FILENAME), workflowDir + '/%s' % (DEFAULT_WORKFLOW_ANNOTATION_FILENAME)] for f in os.listdir(workflowDir): if f.endswith(".conf"): full_filename = os.path.join(workflowDir, f) if full_filename not in workflow_files: workflow_files.append(full_filename) pmr_tool.commitFiles(workflowDir, comment, workflow_files) # [workflowDir + '/%s' % (DEFAULT_WORKFLOW_PROJECT_FILENAME), # workflowDir + '/%s' % (DEFAULT_WORKFLOW_ANNOTATION_FILENAME)]) # XXX make/use file tracker if not commit_local: pmr_tool.pushToRemote(workflowDir) committed_changes = True except ClientRuntimeError: # handler will deal with this. raise except Exception: logger.exception('Error') raise ClientRuntimeError( 'Error Saving', 'The commit to PMR did not succeed') return committed_changes
def __init__(self, use_external_git, parent=None): super(PMRWorkflowWidget, self).__init__(parent) self._ui = Ui_PMRWorkflowWidget() self._ui.setupUi(self) pmr_info = PMR() self._pmrTool = PMRTool(pmr_info, use_external_git) self._termLookUpLimit = 32 self._timer = QtCore.QTimer() self._timer.setInterval(500) self._busy_waiting = False self._ontological_search = False word_list = ['pending ...'] self._list_model = OWLTermsListModel(word_list) # self._client = Client(site=pmr_target, use_default_headers=True) self._makeConnections() self._ui.comboBoxSearch.clear() self._ui.comboBoxSearch.addItems(search_domains) self._updateUi()
def commitChanges(self, workflowDir): om = self._main_window.model().optionsManager() pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) if not pmr_tool.hasDVCS(workflowDir): # nothing to commit. return True return self._commitChanges(workflowDir, 'Workflow saved.')
def _cloneFromPMR(self, workspace_url, workflowDir): om = self._main_window.model().optionsManager() pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) pmr_tool.cloneWorkspace( remote_workspace_url=workspace_url, local_workspace_dir=workflowDir, )
def test_make_session_with_access(self): pmr_info = PMR() tool = PMRTool(pmr_info) info = PMR() info.update_token('test', 'token') session = tool.make_session() self.assertTrue(isinstance(session, OAuth1Session)) info.update_token('', '')
def _updateUi(self): pmr_info = PMR() self._pmr_tool.set_info(pmr_info) if self._pmr_tool.isActive(): if self._pmr_tool.hasAccess(): self._ui.loginStackedWidget.setCurrentIndex(1) else: self._ui.loginStackedWidget.setCurrentIndex(0) else: self._ui.loginStackedWidget.setCurrentIndex(2)
def _register(self): pmr_info = PMR() verifier = self._ui.tokenLineEdit.text() self._helper.set_verifier(verifier) try: token_credentials = self._helper.get_token_credentials() except ValueError: logger.info('Invalid Verifier: Failed to retrieve token access with verification code.') QtWidgets.QMessageBox.information(self, 'Invalid Verifier', 'Failed to retrieve token access with verification code.') return False logger.debug('token: %r', token_credentials) pmr_info.update_token(**token_credentials) return True
def __init__(self, parent=None): super(SearchWidget, self).__init__(parent) self._ui = Ui_SearchWidget() self._ui.setupUi(self) pmr_info = PMR() self._pmrTool = PMRTool(pmr_info) self._annotationTool = AnnotationTool() self._makeConnections()
def testPMR(self): info = PMR() host = info.host() self.assertIsInstance(host, unicode) self.assertTrue(info.addHost('garbage')) self.assertIn('garbage', info._instances) self.assertFalse(info.setActiveHost('rubbish')) self.assertTrue(info.setActiveHost('garbage')) self.assertTrue(info.removeHost('garbage')) self.assertTrue(info.host() is None) self.assertFalse(info.removeHost('garbage'))
def __init__(self, external_git, parent=None): super(PMRRegisterDialog, self).__init__(parent) self._ui = Ui_RegisterDialog() self._ui.setupUi(self) pmr_info = PMR() self._pmr_tool = PMRTool(pmr_info, external_git) self._makeConnections() self._updateUi()
def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) self._ui = Ui_PMRSearchDialog() self._ui.setupUi(self) pmr_info = PMR() self._pmrTool = PMRTool(pmr_info) self._annotationTool = AnnotationTool() self._makeConnections() self._updateUi()
def _updateUi(self): pmr_info = PMR() self._pmr_tool.set_info(pmr_info) if self._pmr_tool.isActive(): self._ui.pushButtonRegister.setEnabled(True) if self._pmr_tool.hasAccess(): self._ui.stackedWidgetRegister.setCurrentIndex(1) else: self._ui.stackedWidgetRegister.setCurrentIndex(0) else: self._ui.pushButtonRegister.setEnabled(False) self._ui.stackedWidgetRegister.setCurrentIndex(0)
def __init__(self, use_external_git, parent=None): super(PMRDialog, self).__init__(parent) self._ui = Ui_PMRDialog() self._ui.setupUi(self) self._ui.searchWidget.setUseExternalGit(use_external_git) self._ui.settingsWidget.setUseExternalGit(use_external_git) pmr_info = PMR() self._pmr_tool = PMRTool(pmr_info, use_external_git) self._makeConnections() self._updateUi()
def _setIndexerFile(self, workflow_dir): om = self._main_window.model().optionsManager() pmr_info = PMR() pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT)) if not pmr_tool.hasDVCS(workflow_dir): return try: pmr_tool.addFileToIndexer(workflow_dir, DEFAULT_WORKFLOW_ANNOTATION_FILENAME) # pmr_tool.commitFiles(local_workspace_dir, message, files) except ClientRuntimeError: # handler will deal with this. raise
def make_tool(self, endpoints=None): if endpoints is None: endpoints = self.endpoints def make_session(pmr_info=None): session = TestSession() for url, adapter in endpoints: session.mount(url, adapter) return session pmr_info = PMR() tool = PMRTool(pmr_info) tool.make_session = make_session return tool
def test_requestTemporaryPassword(self): # Available with access info = PMR() info.update_token('test', 'token') result = self._tool.requestTemporaryPassword('http://example.com/w/1') self.assertEqual(result['user'], 'tester') self.assertEqual(result['key'], 'secret') info.update_token('', '') result = self._tool.requestTemporaryPassword('http://example.com/w/1') self.assertTrue(result is None)
def test_hasAccess(self): # update tokens using another instance info = PMR() t = PMRTool(info) # Fresh token should have no access self.assertFalse(t.hasAccess()) info.update_token('test', 'token') # Now it's true self.assertTrue(t.hasAccess()) # revoke access again. info.update_token('', '') # Now it's false again. self.assertFalse(t.hasAccess())
def _hostChanged(self, item): pmr_info = PMR() if not item.checkState(): pmr_info.setActiveHost(None) self.hostChanged.emit(item.row()) return index = 0 current_item = self._model.item(index) self.blockSignals(True) while current_item: if current_item.checkState() and (current_item.row() != item.row()): current_item.setCheckState(QtCore.Qt.Unchecked) index += 1 current_item = self._model.item(index) self.blockSignals(False) pmr_info.setActiveHost(item.text()) self.hostChanged.emit(item.row())
def _updateModel(self): pmr_info = PMR() for instance in pmr_info.hosts(): self.addHost(instance, instance == pmr_info.activeHost())
def deregister(self): pmr_info = PMR() self._pmr_tool.set_info(pmr_info) self._pmr_tool.deregister() self._updateUi()