class InstalledRepositoryManagerTestCase(ToolShedRepoBaseTestCase): def setUp(self): super().setUp() self.irm = InstalledRepositoryManager(self.app) def test_uninstall_repository(self): repository = self._setup_repository() assert repository.uninstalled is False self.irm.uninstall_repository(repository=repository, remove_from_disk=True) assert repository.uninstalled is True def test_deactivate_repository(self): self._deactivate_repository() def test_activate_repository(self): repository = self._deactivate_repository() self.irm.activate_repository(repository) assert repository.status == self.app.install_model.ToolShedRepository.installation_status.INSTALLED def test_create_or_update_tool_shed_repository_update(self): repository = self._setup_repository() self._create_or_update_tool_shed_repository(repository=repository, changeset_revision='2') def test_create_or_update_tool_shed_repository_create(self): self._create_or_update_tool_shed_repository(repository=None, changeset_revision='2') def _create_or_update_tool_shed_repository(self, repository=None, changeset_revision='2'): if repository is None: repository = DEFAULT_TEST_REPO new_repository = repository_util.create_or_update_tool_shed_repository( app=self.app, name=repository.name, description=repository.description, installed_changeset_revision=repository.installed_changeset_revision, ctx_rev=repository.changeset_revision, repository_clone_url='https://github.com/galaxyproject/example/test_tool/0.%s' % repository.installed_changeset_revision, # not needed if owner is given status=repository.status, metadata_dict=None, current_changeset_revision=str(int(repository.changeset_revision) + 1), owner=repository.owner, dist_to_shed=False ) assert new_repository.changeset_revision == changeset_revision def _deactivate_repository(self): repository = self._setup_repository() assert repository.uninstalled is False self.irm.uninstall_repository(repository=repository, remove_from_disk=False) assert repository.uninstalled is False assert repository.status == self.app.install_model.ToolShedRepository.installation_status.DEACTIVATED return repository
def uninstall_repository(self, trans, id=None, **kwd): """ DELETE /api/tool_shed_repositories/id DELETE /api/tool_shed_repositories/ :param id: encoded repository id. Either id or name, owner, changeset_revision and tool_shed_url need to be supplied :param kwd: 'remove_from_disk': Remove repository from disk or deactivate repository. Defaults to `True` (= remove repository from disk). 'name': Repository name 'owner': Repository owner 'changeset_revision': Changeset revision to uninstall 'tool_shed_url': Tool Shed URL """ remove_from_disk = util.asbool(kwd.get('remove_from_disk', True)) if id: try: repository = get_tool_shed_repository_by_id(self.app, id) except ValueError: raise HTTPBadRequest( detail="No repository with id '%s' found" % id) else: tsr_arguments = [ 'name', 'owner', 'changeset_revision', 'tool_shed_url' ] try: tsr_arguments = {key: kwd[key] for key in tsr_arguments} except KeyError as e: raise HTTPBadRequest(detail="Missing required parameter '%s'" % e.args[0]) repository = get_installed_repository( app=self.app, tool_shed=tsr_arguments['tool_shed_url'], name=tsr_arguments['name'], owner=tsr_arguments['owner'], changeset_revision=tsr_arguments['changeset_revision']) if not repository: raise HTTPBadRequest(detail="Repository not found") irm = InstalledRepositoryManager(app=self.app) errors = irm.uninstall_repository(repository=repository, remove_from_disk=remove_from_disk) if not errors: action = 'removed' if remove_from_disk else 'deactivated' return { 'message': f'The repository named {repository.name} has been {action}.' } else: raise Exception( f'Attempting to uninstall tool dependencies for repository named {repository.name} resulted in errors: {errors}' )