def assertResolves(self, lp_url_path, public_branch_path, lp_path=None): """Assert that `lp_url_path` resolves to the specified paths. :param public_branch_path: The path that is accessible over http. :param lp_path: The short branch alias that will be resolved over bzr+ssh. The branch alias prefix is prefixed to this path. If it is not set, the bzr+ssh resolved name will be checked against the public_branch_path instead. """ api = PublicCodehostingAPI(None, None) results = api.resolve_lp_path(lp_url_path) if lp_path is None: ssh_branch_path = public_branch_path else: if lp_path.startswith('~'): ssh_branch_path = lp_path else: ssh_branch_path = '%s/%s' % (BRANCH_ALIAS_PREFIX, lp_path) # This improves the error message if results happens to be a fault. if isinstance(results, LaunchpadFault): raise results for url in results['urls']: uri = URI(url) if uri.scheme == 'http': self.assertEqual('/' + public_branch_path, uri.path) else: self.assertEqual('/' + ssh_branch_path, uri.path)
def test_remote_branch(self): # For remote branches, return results that link to the actual remote # branch URL. branch = self.factory.makeAnyBranch(branch_type=BranchType.REMOTE) api = PublicCodehostingAPI(None, None) result = api.resolve_lp_path(branch.unique_name) self.assertEqual([branch.url], result['urls'])
def test_resultDictForHotProduct(self): # If 'project-name' is in the config.codehosting.hot_products list, # lp:project-name will only resolve to the http url. product, trunk = self.makeProdutWithTrunk() self.pushConfig('codehosting', hot_products=product.name) api = PublicCodehostingAPI(None, None) results = api.resolve_lp_path(product.name) http_url = 'http://bazaar.launchpad.dev/%s' % trunk.unique_name self.assertEqual(dict(urls=[http_url]), results)
def assertFault(self, lp_url_path, expected_fault): """Trying to resolve lp_url_path raises the expected fault.""" api = PublicCodehostingAPI(None, None) fault = api.resolve_lp_path(lp_url_path) self.assertTrue( isinstance(fault, xmlrpclib.Fault), "resolve_lp_path(%r) returned %r, not a Fault." % (lp_url_path, fault)) self.assertEqual(expected_fault.__class__, fault.__class__) self.assertEqual(expected_fault.faultString, fault.faultString) return fault
def test_resultDict(self): # A given lp url path maps to a single branch available from a number # of URLs (mostly varying by scheme). resolve_lp_path returns a dict # containing a list of these URLs, with the faster and more featureful # URLs earlier in the list. We use a dict so we can easily add more # information in the future. product, trunk = self.makeProdutWithTrunk() api = PublicCodehostingAPI(None, None) results = api.resolve_lp_path(product.name) urls = [ 'bzr+ssh://bazaar.launchpad.dev/+branch/%s' % product.name, 'http://bazaar.launchpad.dev/%s' % trunk.unique_name] self.assertEqual(dict(urls=urls), results)
def test_resultDict(self): # A given lp url path maps to a single branch available from a number # of URLs (mostly varying by scheme). resolve_lp_path returns a dict # containing a list of these URLs, with the faster and more featureful # URLs earlier in the list. We use a dict so we can easily add more # information in the future. product, trunk = self.makeProdutWithTrunk() api = PublicCodehostingAPI(None, None) results = api.resolve_lp_path(product.name) urls = [ 'bzr+ssh://bazaar.launchpad.dev/+branch/%s' % product.name, 'http://bazaar.launchpad.dev/%s' % trunk.unique_name ] self.assertEqual(dict(urls=urls), results)