def test_resolve_branch_with_no_such_owner(self): # If we try to resolve a branch that refers to a non-existent owner, # then we return a NoSuchPerson fault. nonexistent_owner_branch = "~doesntexist/%s/%s" % ( self.factory.getUniqueString(), self.factory.getUniqueString()) self.assertFault(nonexistent_owner_branch, faults.NoSuchPersonWithName('doesntexist'))
def test_resolve_branch_with_no_such_owner_non_ascii(self): # lp:~<non-ascii-string>/product/name returns NoSuchPersonWithName # with the name escaped. nonexistent_owner_branch = u"~%s/%s/%s" % ( NON_ASCII_NAME, self.factory.getUniqueString(), self.factory.getUniqueString()) self.assertFault( nonexistent_owner_branch, faults.NoSuchPersonWithName(urlutils.escape(NON_ASCII_NAME)))
def getUserAndSSHKeys(self, name): """See `IAuthServer.getUserAndSSHKeys`.""" person = getUtility(IPersonSet).getByName(name) if person is None: return faults.NoSuchPersonWithName(name) return { 'id': person.id, 'name': person.name, 'keys': [(key.keytype.title, key.keytext) for key in person.sshkeys], }
def _getBranchPaths(self, strip_path, supported_schemes): """Get the specific paths for a branch. If the branch is not found, but it looks like a branch name, then we return a writable URL for it. If it doesn't look like a branch name a fault is raised. """ branch_set = getUtility(IBranchLookup) try: branch, suffix = branch_set.getByLPPath(strip_path) except NoSuchBranch: # If the branch isn't found, but it looks like a valid name, then # resolve it anyway, treating the path like a branch's unique # name. This lets people push new branches up to Launchpad using # lp: URL syntax. supported_schemes = ['bzr+ssh'] return self._getUniqueNameResultDict( strip_path, supported_schemes=supported_schemes) # XXX: JonathanLange 2009-03-21 bug=347728: All of this is repetitive # and thus error prone. Alternatives are directly raising faults from # the model code(blech) or some automated way of reraising as faults # or using a narrower range of faults (e.g. only one "NoSuch" fault). except InvalidProductName as e: raise faults.InvalidProductName(urlutils.escape(e.name)) except NoSuchProductSeries as e: raise faults.NoSuchProductSeries(urlutils.escape(e.name), e.product) except NoSuchPerson as e: raise faults.NoSuchPersonWithName(urlutils.escape(e.name)) except NoSuchProduct as e: raise faults.NoSuchProduct(urlutils.escape(e.name)) except NoSuchDistroSeries as e: raise faults.NoSuchDistroSeries(urlutils.escape(e.name)) except NoSuchSourcePackageName as e: raise faults.NoSuchSourcePackageName(urlutils.escape(e.name)) except NoLinkedBranch as e: raise faults.NoLinkedBranch(e.component) except CannotHaveLinkedBranch as e: raise faults.CannotHaveLinkedBranch(e.component) except InvalidNamespace as e: raise faults.InvalidBranchUniqueName(urlutils.escape(e.name)) # Reverse engineer the actual lp_path that is used, so we need to # remove any suffix that may be there from the strip_path. lp_path = strip_path if suffix != '': # E.g. 'project/trunk/filename.txt' the suffix is 'filename.txt' # we want lp_path to be 'project/trunk'. lp_path = lp_path[:-(len(suffix) + 1)] return self._getUrlsForBranch(branch, lp_path, suffix, supported_schemes)
def isTeamPublic(self, team_name): """See `IMailingListAPIView.`.""" team = getUtility(IPersonSet).getByName(team_name) if team is None: return faults.NoSuchPersonWithName(team_name) return team.visibility == PersonVisibility.PUBLIC
def test_user_not_found(self): # getUserAndSSHKeys returns the NoSuchPersonWithName fault if there is # no Person of the given name. self.assertEqual(faults.NoSuchPersonWithName('no-one'), self.authserver.getUserAndSSHKeys('no-one'))