def setUp(self): TestCaseWithFactory.setUp(self) self.original = self.factory.makeSourcePackage() self.target = PackageBranchTarget(self.original)
def fake_source_package_to_branch_target(fake_package): return PackageBranchTarget(fake_package)
class TestPackageBranchTarget(TestCaseWithFactory, BaseBranchTargetTests): layer = DatabaseFunctionalLayer def setUp(self): TestCaseWithFactory.setUp(self) self.original = self.factory.makeSourcePackage() self.target = PackageBranchTarget(self.original) def makeBranchForTarget(self): return self.factory.makePackageBranch(sourcepackage=self.original) def test_name(self): # The name of a package context is distro/series/sourcepackage self.assertEqual(self.original.path, self.target.name) def test_getNamespace(self): """Get namespace produces the correct namespace.""" person = self.factory.makePerson() namespace = self.target.getNamespace(person) self.assertEqual(person, namespace.owner) self.assertEqual(self.original, namespace.sourcepackage) def test_adapter(self): target = IBranchTarget(self.original) self.assertIsInstance(target, PackageBranchTarget) def test_distrosourcepackage_adapter(self): # Adapting a distrosourcepackage will make a branch target with the # current series of the distro as the distroseries. distro = self.original.distribution distro_sourcepackage = distro.getSourcePackage( self.original.sourcepackagename) target = IBranchTarget(distro_sourcepackage) self.assertIsInstance(target, PackageBranchTarget) self.assertEqual([distro, distro.currentseries], target.components[:2]) self.assertEqual(self.original.sourcepackagename, target.components[2].sourcepackagename) def test_components(self): target = IBranchTarget(self.original) self.assertEqual([ self.original.distribution, self.original.distroseries, self.original ], list(target.components)) def test_default_stacked_on_branch(self): # The default stacked-on branch for a source package is the branch # linked to the release pocket of the current series of that package. target = IBranchTarget(self.original) development_package = self.original.development_version default_branch = self.factory.makePackageBranch( sourcepackage=development_package) removeSecurityProxy(default_branch).branchChanged( '', self.factory.getUniqueString(), None, None, None) registrant = development_package.distribution.owner with person_logged_in(registrant): development_package.setBranch(PackagePublishingPocket.RELEASE, default_branch, registrant) self.assertEqual(default_branch, target.default_stacked_on_branch) def test_supports_merge_proposals(self): # Package branches do support merge proposals. self.assertTrue(self.target.supports_merge_proposals) def test_supports_short_identites(self): # Package branches do support short bzr identites. self.assertTrue(self.target.supports_short_identites) def test_displayname(self): # The display name of a source package target is the display name of # the source package. target = IBranchTarget(self.original) self.assertEqual(self.original.displayname, target.displayname) def test_areBranchesMergeable_same_sourcepackage(self): # Branches of the same sourcepackage are mergeable. same_target = PackageBranchTarget(self.original) self.assertTrue(self.target.areBranchesMergeable(same_target)) def test_areBranchesMergeable_same_sourcepackagename(self): # Branches with the same sourcepackagename are mergeable. sourcepackage = self.factory.makeSourcePackage( self.original.sourcepackagename) same_name = PackageBranchTarget(sourcepackage) self.assertTrue(self.target.areBranchesMergeable(same_name)) def test_areBranchesMergeable_different_sourcepackage(self): # Package branches for a different sorucepackagename are not # mergeable. branch = self.factory.makePackageBranch() self.assertFalse(self.target.areBranchesMergeable(branch.target)) def test_areBranchesMergeable_personal_branches(self): # Personal branches are not mergeable. branch = self.factory.makePersonalBranch() self.assertFalse(self.target.areBranchesMergeable(branch.target)) def test_areBranchesMergeable_unlinked_product(self): # Product branches are not normally mergeable into package branches. branch = self.factory.makeProductBranch() self.assertFalse(self.target.areBranchesMergeable(branch.target)) def test_areBranchesMergeable_linked_product(self): # Products that are linked to the packages are mergeable. branch = self.factory.makeProductBranch() # Link it up. self.original.setPackaging(branch.product.development_focus, branch.owner) self.assertTrue(self.target.areBranchesMergeable(branch.target)) def test_default_merge_target(self): # The default merge target is official release branch. self.assertIs(None, self.target.default_merge_target) # Now create and link a branch. branch = self.factory.makePackageBranch(sourcepackage=self.original) with person_logged_in(self.original.distribution.owner): self.original.setBranch(PackagePublishingPocket.RELEASE, branch, self.original.distribution.owner) self.assertEqual(branch, self.target.default_merge_target) def test_supports_code_imports(self): self.assertTrue(self.target.supports_code_imports) def test_creating_code_import_succeeds(self): target_url = self.factory.getUniqueURL() branch_name = self.factory.getUniqueString("name-") owner = self.factory.makePerson() code_import = self.target.newCodeImport(owner, branch_name, RevisionControlSystems.GIT, url=target_url) code_import = removeSecurityProxy(code_import) self.assertProvides(code_import, ICodeImport) self.assertEqual(target_url, code_import.url) self.assertEqual(branch_name, code_import.branch.name) self.assertEqual(owner, code_import.registrant) self.assertEqual(owner, code_import.branch.owner) self.assertEqual(self.target, code_import.branch.target) def test_related_branches(self): (branch, related_series_branch_info, related_package_branches) = ( self.factory.makeRelatedBranchesForSourcePackage( sourcepackage=self.original)) self.assertEqual(related_series_branch_info, self.target.getRelatedSeriesBranchInfo(branch)) self.assertEqual(related_package_branches, self.target.getRelatedPackageBranchInfo(branch)) def test_related_branches_with_private_branch(self): (branch, related_series_branch_info, related_package_branches) = ( self.factory.makeRelatedBranchesForSourcePackage( sourcepackage=self.original, with_private_branches=True)) self.assertEqual(related_series_branch_info, self.target.getRelatedSeriesBranchInfo(branch)) self.assertEqual(related_package_branches, self.target.getRelatedPackageBranchInfo(branch))
def test_areBranchesMergeable_same_sourcepackagename(self): # Branches with the same sourcepackagename are mergeable. sourcepackage = self.factory.makeSourcePackage( self.original.sourcepackagename) same_name = PackageBranchTarget(sourcepackage) self.assertTrue(self.target.areBranchesMergeable(same_name))
def test_areBranchesMergeable_same_sourcepackage(self): # Branches of the same sourcepackage are mergeable. same_target = PackageBranchTarget(self.original) self.assertTrue(self.target.areBranchesMergeable(same_target))
class TestPackageBranchTarget(TestCaseWithFactory, BaseBranchTargetTests): layer = DatabaseFunctionalLayer def setUp(self): TestCaseWithFactory.setUp(self) self.original = self.factory.makeSourcePackage() self.target = PackageBranchTarget(self.original) def makeBranchForTarget(self): return self.factory.makePackageBranch(sourcepackage=self.original) def test_name(self): # The name of a package context is distro/series/sourcepackage self.assertEqual(self.original.path, self.target.name) def test_getNamespace(self): """Get namespace produces the correct namespace.""" person = self.factory.makePerson() namespace = self.target.getNamespace(person) self.assertEqual(person, namespace.owner) self.assertEqual(self.original, namespace.sourcepackage) def test_adapter(self): target = IBranchTarget(self.original) self.assertIsInstance(target, PackageBranchTarget) def test_distrosourcepackage_adapter(self): # Adapting a distrosourcepackage will make a branch target with the # current series of the distro as the distroseries. distro = self.original.distribution distro_sourcepackage = distro.getSourcePackage(self.original.sourcepackagename) target = IBranchTarget(distro_sourcepackage) self.assertIsInstance(target, PackageBranchTarget) self.assertEqual([distro, distro.currentseries], target.components[:2]) self.assertEqual(self.original.sourcepackagename, target.components[2].sourcepackagename) def test_components(self): target = IBranchTarget(self.original) self.assertEqual( [self.original.distribution, self.original.distroseries, self.original], list(target.components) ) def test_default_stacked_on_branch(self): # The default stacked-on branch for a source package is the branch # linked to the release pocket of the current series of that package. target = IBranchTarget(self.original) development_package = self.original.development_version default_branch = self.factory.makePackageBranch(sourcepackage=development_package) removeSecurityProxy(default_branch).branchChanged("", self.factory.getUniqueString(), None, None, None) registrant = development_package.distribution.owner with person_logged_in(registrant): development_package.setBranch(PackagePublishingPocket.RELEASE, default_branch, registrant) self.assertEqual(default_branch, target.default_stacked_on_branch) def test_supports_merge_proposals(self): # Package branches do support merge proposals. self.assertTrue(self.target.supports_merge_proposals) def test_supports_short_identites(self): # Package branches do support short bzr identites. self.assertTrue(self.target.supports_short_identites) def test_displayname(self): # The display name of a source package target is the display name of # the source package. target = IBranchTarget(self.original) self.assertEqual(self.original.displayname, target.displayname) def test_areBranchesMergeable_same_sourcepackage(self): # Branches of the same sourcepackage are mergeable. same_target = PackageBranchTarget(self.original) self.assertTrue(self.target.areBranchesMergeable(same_target)) def test_areBranchesMergeable_same_sourcepackagename(self): # Branches with the same sourcepackagename are mergeable. sourcepackage = self.factory.makeSourcePackage(self.original.sourcepackagename) same_name = PackageBranchTarget(sourcepackage) self.assertTrue(self.target.areBranchesMergeable(same_name)) def test_areBranchesMergeable_different_sourcepackage(self): # Package branches for a different sorucepackagename are not # mergeable. branch = self.factory.makePackageBranch() self.assertFalse(self.target.areBranchesMergeable(branch.target)) def test_areBranchesMergeable_personal_branches(self): # Personal branches are not mergeable. branch = self.factory.makePersonalBranch() self.assertFalse(self.target.areBranchesMergeable(branch.target)) def test_areBranchesMergeable_unlinked_product(self): # Product branches are not normally mergeable into package branches. branch = self.factory.makeProductBranch() self.assertFalse(self.target.areBranchesMergeable(branch.target)) def test_areBranchesMergeable_linked_product(self): # Products that are linked to the packages are mergeable. branch = self.factory.makeProductBranch() # Link it up. self.original.setPackaging(branch.product.development_focus, branch.owner) self.assertTrue(self.target.areBranchesMergeable(branch.target)) def test_default_merge_target(self): # The default merge target is official release branch. self.assertIs(None, self.target.default_merge_target) # Now create and link a branch. branch = self.factory.makePackageBranch(sourcepackage=self.original) with person_logged_in(self.original.distribution.owner): self.original.setBranch(PackagePublishingPocket.RELEASE, branch, self.original.distribution.owner) self.assertEqual(branch, self.target.default_merge_target) def test_supports_code_imports(self): self.assertTrue(self.target.supports_code_imports) def test_creating_code_import_succeeds(self): target_url = self.factory.getUniqueURL() branch_name = self.factory.getUniqueString("name-") owner = self.factory.makePerson() code_import = self.target.newCodeImport(owner, branch_name, RevisionControlSystems.GIT, url=target_url) code_import = removeSecurityProxy(code_import) self.assertProvides(code_import, ICodeImport) self.assertEqual(target_url, code_import.url) self.assertEqual(branch_name, code_import.branch.name) self.assertEqual(owner, code_import.registrant) self.assertEqual(owner, code_import.branch.owner) self.assertEqual(self.target, code_import.branch.target) def test_related_branches(self): ( branch, related_series_branch_info, related_package_branches, ) = self.factory.makeRelatedBranchesForSourcePackage(sourcepackage=self.original) self.assertEqual(related_series_branch_info, self.target.getRelatedSeriesBranchInfo(branch)) self.assertEqual(related_package_branches, self.target.getRelatedPackageBranchInfo(branch)) def test_related_branches_with_private_branch(self): ( branch, related_series_branch_info, related_package_branches, ) = self.factory.makeRelatedBranchesForSourcePackage(sourcepackage=self.original, with_private_branches=True) self.assertEqual(related_series_branch_info, self.target.getRelatedSeriesBranchInfo(branch)) self.assertEqual(related_package_branches, self.target.getRelatedPackageBranchInfo(branch))