def test_distro_package_alias(self): # Traversing to /+branch/<distro>/<sourcepackage package> redirects # to the page for the branch that is the development focus branch # for that package. sourcepackage = self.factory.makeSourcePackage() branch = self.factory.makePackageBranch(sourcepackage=sourcepackage) distro_package = sourcepackage.distribution_sourcepackage registrant = distro_package.distribution.owner target = ICanHasLinkedBranch(distro_package) with person_logged_in(registrant): target.setBranch(branch, registrant) self.assertRedirects("%s" % target.bzr_path, canonical_url(branch))
def test_product_sort(self): # If in the extremely unlikely event we have one branch linked as the # trunk of two or more different products (you never know), then the # sorting reverts to the name of the product. aardvark_link = ICanHasLinkedBranch( self.factory.makeProduct(name='aardvark')) meerkat_link = ICanHasLinkedBranch( self.factory.makeProduct(name='meerkat')) zebra_link = ICanHasLinkedBranch( self.factory.makeProduct(name='zebra')) links = sorted([zebra_link, aardvark_link, meerkat_link]) self.assertIs(aardvark_link, links[0]) self.assertIs(meerkat_link, links[1]) self.assertIs(zebra_link, links[2])
def test_bzr_path(self): # The bzr_path of a product series linked branch is # product/product_series. product_series = self.factory.makeProductSeries() bzr_path = '%s/%s' % (product_series.product.name, product_series.name) self.assertEqual(bzr_path, ICanHasLinkedBranch(product_series).bzr_path)
def test_branch(self): # The linked branch of a product is the linked branch of its # development focus product series. branch = self.factory.makeProductBranch() product = branch.product removeSecurityProxy(product).development_focus.branch = branch self.assertEqual(branch, ICanHasLinkedBranch(product).branch)
def test_setBranch_with_no_series(self): distribution_sourcepackage = ( self.factory.makeDistributionSourcePackage()) linked_branch = ICanHasLinkedBranch(distribution_sourcepackage) registrant = distribution_sourcepackage.distribution.owner self.assertRaises(NoSuchDistroSeries, linked_branch.setBranch, self.factory.makeAnyBranch(), registrant)
def test_product_alias(self): # Traversing to /+branch/<product> redirects to the page for the # branch that is the development focus branch for that product. branch = self.factory.makeProductBranch() naked_product = removeSecurityProxy(branch.product) ICanHasLinkedBranch(naked_product).setBranch(branch) self.assertRedirects(naked_product.name, canonical_url(branch))
def test_private_branch_for_distro_package(self): # If the development focus of a distro package is private, display a # message telling the user there is no linked branch. sourcepackage = self.factory.makeSourcePackage() branch = self.factory.makePackageBranch( sourcepackage=sourcepackage, information_type=InformationType.USERDATA) distro_package = sourcepackage.distribution_sourcepackage registrant = distro_package.distribution.owner with person_logged_in(registrant): ICanHasLinkedBranch(distro_package).setBranch(branch, registrant) login(ANONYMOUS) path = ICanHasLinkedBranch(distro_package).bzr_path requiredMessage = (u"The target %s does not have a linked branch." % path) self.assertDisplaysNotice(path, requiredMessage)
def test_product_series_redirect(self): # Traversing to /+branch/<product>/<series> redirects to the branch # for that series, if there is one. branch = self.factory.makeBranch() series = self.factory.makeProductSeries(branch=branch) self.assertRedirects( ICanHasLinkedBranch(series).bzr_path, canonical_url(branch))
def test_setBranch(self): # setBranch sets the linked branch of the development focus product # series. branch = self.factory.makeProductBranch() product = removeSecurityProxy(branch.product) ICanHasLinkedBranch(product).setBranch(branch) self.assertEqual(branch, product.development_focus.branch)
def test_setBranch(self): # setBranch sets the linked branch of the product series. product_series = self.factory.makeProductSeries() naked_product_series = remove_security_proxy_and_shout_at_engineer( product_series) branch = self.factory.makeProductBranch(product=product_series.product) ICanHasLinkedBranch(naked_product_series).setBranch(branch) self.assertEqual(branch, product_series.branch)
def test_no_branch_for_series(self): # If there's no branch for a product series, display a # message telling the user there is no linked branch. series = self.factory.makeProductSeries() path = ICanHasLinkedBranch(series).bzr_path requiredMessage = ("The target %s does not have a linked branch." % path) self.assertDisplaysNotice(path, requiredMessage)
def setBranch(self, branch, registrant): """See `ICanHasLinkedBranch`.""" development_package = ( self.distribution_sourcepackage.development_version) if development_package is None: raise NoSuchDistroSeries('no current series') suite_sourcepackage = development_package.getSuiteSourcePackage( PackagePublishingPocket.RELEASE) ICanHasLinkedBranch(suite_sourcepackage).setBranch(branch, registrant)
def test_bzr_path(self): # The bzr_path of a distribution source package linked branch is # distro/package. distribution_sourcepackage = ( self.factory.makeDistributionSourcePackage()) self.assertEqual( '%s/%s' % (distribution_sourcepackage.distribution.name, distribution_sourcepackage.sourcepackagename.name), ICanHasLinkedBranch(distribution_sourcepackage).bzr_path)
def test_branch(self): # The linked branch of a product series is its branch attribute. product_series = self.factory.makeProductSeries() naked_product_series = remove_security_proxy_and_shout_at_engineer( product_series) naked_product_series.branch = self.factory.makeProductBranch( product=product_series.product) self.assertEqual(product_series.branch, ICanHasLinkedBranch(product_series).branch)
def test_getByPath(self): branch = self.factory.makeProductBranch() self.assertEqual(branch, BranchSet().getByPath(branch.shortened_path)) product = removeSecurityProxy(branch.product) ICanHasLinkedBranch(product).setBranch(branch) clear_property_cache(branch) self.assertEqual(product.name, branch.shortened_path) self.assertEqual(branch, BranchSet().getByPath(branch.shortened_path)) self.assertIsNone(BranchSet().getByPath('nonexistent'))
def makeProdutWithTrunk(self): """Make a new project with a trunk hosted branch.""" product = self.factory.makeProduct() # BranchType is only signficiant insofar as it is not a REMOTE branch. trunk = self.factory.makeProductBranch(branch_type=BranchType.HOSTED, product=product) with person_logged_in(product.owner): ICanHasLinkedBranch(product).setBranch(trunk) return product, trunk
def branch(self): """See `ICanHasLinkedBranch`.""" development_package = ( self.distribution_sourcepackage.development_version) if development_package is None: return None suite_sourcepackage = development_package.getSuiteSourcePackage( PackagePublishingPocket.RELEASE) return ICanHasLinkedBranch(suite_sourcepackage).branch
def test_product_series_sort(self): # Sorting by product series checks the product name first, then series # name. aardvark = self.factory.makeProduct(name='aardvark') zebra = self.factory.makeProduct(name='zebra') aardvark_devel = ICanHasLinkedBranch( self.factory.makeProductSeries(product=aardvark, name='devel')) aardvark_testing = ICanHasLinkedBranch( self.factory.makeProductSeries(product=aardvark, name='testing')) zebra_devel = ICanHasLinkedBranch( self.factory.makeProductSeries(product=zebra, name='devel')) zebra_mashup = ICanHasLinkedBranch( self.factory.makeProductSeries(product=zebra, name='mashup')) links = sorted( [zebra_mashup, aardvark_testing, zebra_devel, aardvark_devel]) self.assertIs(aardvark_devel, links[0]) self.assertIs(aardvark_testing, links[1]) self.assertIs(zebra_devel, links[2]) self.assertIs(zebra_mashup, links[3])
def test_branch(self): # The linked branch of a suite source package is the official branch # for the pocket of that source package. branch = self.factory.makeAnyBranch() suite_sourcepackage = self.factory.makeSuiteSourcePackage() registrant = suite_sourcepackage.distribution.owner with person_logged_in(registrant): suite_sourcepackage.sourcepackage.setBranch( suite_sourcepackage.pocket, branch, registrant) self.assertEqual(branch, ICanHasLinkedBranch(suite_sourcepackage).branch)
def test_private_without_referer(self): # If the development focus of a product is private and there is no # referer, we will get a 404 error. This happens if the user hacks # the URL rather than navigating via a link branch = self.factory.makeProductBranch() naked_product = removeSecurityProxy(branch.product) ICanHasLinkedBranch(naked_product).setBranch(branch) removeSecurityProxy(branch).information_type = ( InformationType.USERDATA) login(ANONYMOUS) self.assertNotFound(naked_product.name, use_default_referer=False)
def test_private_branch_for_series(self): # If the development focus of a product series is private, display a # message telling the user there is no linked branch. branch = self.factory.makeBranch( information_type=InformationType.USERDATA) series = self.factory.makeProductSeries(branch=branch) login(ANONYMOUS) path = ICanHasLinkedBranch(series).bzr_path requiredMessage = (u"The target %s does not have a linked branch." % path) self.assertDisplaysNotice(path, requiredMessage)
def test_private_branch_for_product(self): # If the development focus of a product is private, display a # message telling the user there is no linked branch. branch = self.factory.makeProductBranch() naked_product = removeSecurityProxy(branch.product) ICanHasLinkedBranch(naked_product).setBranch(branch) removeSecurityProxy(branch).information_type = ( InformationType.USERDATA) login(ANONYMOUS) requiredMessage = (u"The target %s does not have a linked branch." % naked_product.name) self.assertDisplaysNotice(naked_product.name, requiredMessage)
def test_sorting_different_types(self): # The different types can be sorted together, and sort so that the # results are ordered like: # Product Link # Distribution Source Package Link # Product Series Link # Package Link product_link = ICanHasLinkedBranch(self.factory.makeProduct()) product_series_link = ICanHasLinkedBranch( self.factory.makeProductSeries()) distro_sp_link = ICanHasLinkedBranch( self.factory.makeDistributionSourcePackage()) package_link = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage()) links = sorted( [package_link, product_series_link, distro_sp_link, product_link]) self.assertIs(product_link, links[0]) self.assertIs(distro_sp_link, links[1]) self.assertIs(product_series_link, links[2]) self.assertIs(package_link, links[3])
def test_setBranch(self): # setBranch sets the official branch for the appropriate pocket of the # source package. branch = self.factory.makeAnyBranch() suite_sourcepackage = self.factory.makeSuiteSourcePackage() registrant = suite_sourcepackage.distribution.owner run_with_login(registrant, ICanHasLinkedBranch(suite_sourcepackage).setBranch, branch, registrant) self.assertEqual( branch, suite_sourcepackage.sourcepackage.getBranch( suite_sourcepackage.pocket))
def test_resolve_distro_package_branch(self): # getByLPPath returns the branch associated with the distribution # source package referred to by the path. sourcepackage = self.factory.makeSourcePackage() branch = self.factory.makePackageBranch(sourcepackage=sourcepackage) distro_package = sourcepackage.distribution_sourcepackage registrant = sourcepackage.distribution.owner run_with_login(registrant, ICanHasLinkedBranch(distro_package).setBranch, branch, registrant) self.assertEqual( (branch, ''), self.branch_lookup.getByLPPath( '%s/%s' % (distro_package.distribution.name, distro_package.sourcepackagename.name)))
def test_distribution_source_package_sort(self): # Sorting of distribution source packages sorts firstly on the # distribution name, then the package name. aardvark = self.factory.makeDistribution(name='aardvark') zebra = self.factory.makeDistribution(name='zebra') aardvark_devel = ICanHasLinkedBranch( self.factory.makeDistributionSourcePackage( distribution=aardvark, sourcepackagename='devel')) aardvark_testing = ICanHasLinkedBranch( self.factory.makeDistributionSourcePackage( distribution=aardvark, sourcepackagename='testing')) zebra_devel = ICanHasLinkedBranch( self.factory.makeDistributionSourcePackage( distribution=zebra, sourcepackagename='devel')) zebra_mashup = ICanHasLinkedBranch( self.factory.makeDistributionSourcePackage( distribution=zebra, sourcepackagename='mashup')) links = sorted( [zebra_mashup, aardvark_testing, zebra_devel, aardvark_devel]) self.assertIs(aardvark_devel, links[0]) self.assertIs(aardvark_testing, links[1]) self.assertIs(zebra_devel, links[2]) self.assertIs(zebra_mashup, links[3])
def makePackageProposal(self): branch = self.factory.makePackageBranch() # Make sure the (distroseries, pocket) combination used allows us to # upload to it. pocket = PackagePublishingPocket.RELEASE sourcepackage = branch.sourcepackage suite_sourcepackage = sourcepackage.getSuiteSourcePackage(pocket) registrant = self.factory.makePerson() run_with_login(suite_sourcepackage.distribution.owner, ICanHasLinkedBranch(suite_sourcepackage).setBranch, branch, registrant) source_branch = self.factory.makePackageBranch( sourcepackage=branch.sourcepackage) proposal = source_branch.addLandingTarget(source_branch.registrant, branch) return proposal
def test_suite_source_package_sort(self): # The sorting of suite source packages checks the distribution first, # then the distroseries version, followed by the source package name, # and finally the pocket. aardvark = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage( distroseries=self.factory.makeDistroSeries( self.factory.makeDistribution(name='aardvark')))) zebra = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage( distroseries=self.factory.makeDistroSeries( self.factory.makeDistribution(name='zebra')))) meerkat = self.factory.makeDistribution(name='meerkat') meerkat_1 = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage( self.factory.makeDistroSeries(meerkat, "1.0"))) meerkat_2 = self.factory.makeDistroSeries(meerkat, "2.0") meerkat_3 = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage( self.factory.makeDistroSeries(meerkat, "3.0"))) meerkat_2_devel_release = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage( meerkat_2, 'devel', PackagePublishingPocket.RELEASE)) meerkat_2_devel_updates = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage( meerkat_2, 'devel', PackagePublishingPocket.UPDATES)) meerkat_2_devel_backports = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage( meerkat_2, 'devel', PackagePublishingPocket.BACKPORTS)) meerkat_2_apples = ICanHasLinkedBranch( self.factory.makeSuiteSourcePackage(meerkat_2, 'apples')) links = sorted([ meerkat_3, meerkat_2_devel_updates, zebra, meerkat_2_apples, aardvark, meerkat_2_devel_backports, meerkat_1, meerkat_2_devel_release ]) self.assertIs(aardvark, links[0]) self.assertIs(meerkat_3, links[1]) self.assertIs(meerkat_2_apples, links[2]) self.assertIs(meerkat_2_devel_release, links[3]) self.assertIs(meerkat_2_devel_updates, links[4]) self.assertIs(meerkat_2_devel_backports, links[5]) self.assertIs(meerkat_1, links[6]) self.assertIs(zebra, links[7])
def test_branch(self): # The linked branch of a distribution source package is the official # branch for the release pocket of the development focus series for # that package. Phew. branch = self.factory.makeAnyBranch() sourcepackage = self.factory.makeSourcePackage() dev_sourcepackage = sourcepackage.development_version pocket = PackagePublishingPocket.RELEASE registrant = sourcepackage.distribution.owner with person_logged_in(registrant): dev_sourcepackage.setBranch(pocket, branch, registrant) distribution_sourcepackage = sourcepackage.distribution_sourcepackage self.assertEqual( branch, ICanHasLinkedBranch(distribution_sourcepackage).branch)
def test_setBranch(self): # Setting the linked branch for a distribution source package links # the branch to the release pocket of the development focus series for # that package. branch = self.factory.makeAnyBranch() sourcepackage = self.factory.makeSourcePackage() distribution_sourcepackage = sourcepackage.distribution_sourcepackage registrant = sourcepackage.distribution.owner run_with_login( registrant, ICanHasLinkedBranch(distribution_sourcepackage).setBranch, branch, registrant) dev_sourcepackage = sourcepackage.development_version pocket = PackagePublishingPocket.RELEASE self.assertEqual(branch, dev_sourcepackage.getBranch(pocket))
def _createBranch(self, registrant, branch_path): """The guts of the create branch method. Raises exceptions on error conditions. """ to_link = None if branch_path.startswith(BRANCH_ALIAS_PREFIX + '/'): branch_path = branch_path[len(BRANCH_ALIAS_PREFIX) + 1:] if branch_path.startswith('~'): data, branch_name = self._parseUniqueName(branch_path) else: tokens = branch_path.split('/') data = { 'person': registrant.name, 'product': tokens[0], } branch_name = 'trunk' # check the series product = self._product_set.getByName(data['product']) if product is not None: if len(tokens) > 1: series = product.getSeries(tokens[1]) if series is None: raise faults.NotFound( "No such product series: '%s'." % tokens[1]) else: to_link = ICanHasLinkedBranch(series) else: to_link = ICanHasLinkedBranch(product) # don't forget the link. else: data, branch_name = self._parseUniqueName(branch_path) owner = self._person_set.getByName(data['person']) if owner is None: raise faults.NotFound( "User/team '%s' does not exist." % (data['person'],)) # The real code consults the branch creation policy of the product. We # don't need to do so here, since the tests above this layer never # encounter that behaviour. If they *do* change to rely on the branch # creation policy, the observed behaviour will be failure to raise # exceptions. if not registrant.inTeam(owner): raise faults.PermissionDenied( ('%s cannot create branches owned by %s' % (registrant.displayname, owner.displayname))) product = sourcepackage = None if data['product'] == '+junk': product = None elif data['product'] is not None: if not valid_name(data['product']): raise faults.InvalidProductName(escape(data['product'])) product = self._product_set.getByName(data['product']) if product is None: raise faults.NotFound( "Project '%s' does not exist." % (data['product'],)) elif data['distribution'] is not None: distro = self._distribution_set.getByName(data['distribution']) if distro is None: raise faults.NotFound( "No such distribution: '%s'." % (data['distribution'],)) distroseries = self._distroseries_set.getByName( data['distroseries']) if distroseries is None: raise faults.NotFound( "No such distribution series: '%s'." % (data['distroseries'],)) sourcepackagename = self._sourcepackagename_set.getByName( data['sourcepackagename']) if sourcepackagename is None: try: sourcepackagename = self._sourcepackagename_set.new( data['sourcepackagename']) except InvalidName: raise faults.InvalidSourcePackageName( data['sourcepackagename']) sourcepackage = self._factory.makeSourcePackage( distroseries, sourcepackagename) else: raise faults.PermissionDenied( "Cannot create branch at '%s'" % branch_path) branch = self._factory.makeBranch( owner=owner, name=branch_name, product=product, sourcepackage=sourcepackage, registrant=registrant, branch_type=BranchType.HOSTED) if to_link is not None: if registrant.inTeam(to_link.product.owner): to_link.branch = branch else: self._branch_set._delete(branch) raise faults.PermissionDenied( "Cannot create linked branch at '%s'." % branch_path) return branch.id
def __cmp__(self, other): if not ICanHasLinkedBranch.providedBy(other): raise AssertionError("Can't compare with: %r" % other) return cmp(self.sort_order, other.sort_order)
def link_func(new_branch): link = ICanHasLinkedBranch(context) link.setBranch(new_branch, requester)