def test_setRenderedValue_product(self):
     # Passing a product branch target will set the widget's render state to
     # 'product'.
     self.widget.setUpSubWidgets()
     target = ProductBranchTarget(self.product)
     self.widget.setRenderedValue(target)
     self.assertEqual('product', self.widget.default_option)
     self.assertEqual(
         self.product, self.widget.product_widget._getCurrentValue())
def fake_product_to_branch_target(fake_product):
    """Adapt a `FakeProduct` to `IBranchTarget`."""
    return ProductBranchTarget(fake_product)
Exemple #3
0
 def test_areBranchesMergeable_different_product(self):
     # Branches of a different product are not mergeable.
     other_target = ProductBranchTarget(self.factory.makeProduct())
     self.assertFalse(self.target.areBranchesMergeable(other_target))
Exemple #4
0
 def test_areBranchesMergeable_same_product(self):
     # Branches of the same product are mergeable.
     same_target = ProductBranchTarget(self.original)
     self.assertTrue(self.target.areBranchesMergeable(same_target))
Exemple #5
0
 def setUp(self):
     TestCaseWithFactory.setUp(self)
     self.original = self.factory.makeProduct()
     self.target = ProductBranchTarget(self.original)
Exemple #6
0
class TestProductBranchTarget(TestCaseWithFactory, BaseBranchTargetTests):

    layer = DatabaseFunctionalLayer

    def setUp(self):
        TestCaseWithFactory.setUp(self)
        self.original = self.factory.makeProduct()
        self.target = ProductBranchTarget(self.original)

    def makeBranchForTarget(self):
        return self.factory.makeBranch(product=self.original)

    def test_name(self):
        self.assertEqual(self.original.name, self.target.name)

    def test_getNamespace(self):
        """Get namespace produces the correct namespace."""
        person = self.factory.makePerson()
        namespace = self.target.getNamespace(person)
        self.assertEqual(namespace.product, self.original)
        self.assertEqual(namespace.owner, person)

    def test_adapter(self):
        target = IBranchTarget(self.original)
        self.assertIsInstance(target, ProductBranchTarget)

    def test_productseries_adapter(self):
        # Adapting a product series will make a product branch target.
        product = self.factory.makeProduct()
        series = self.factory.makeProductSeries(product)
        target = IBranchTarget(series)
        self.assertIsInstance(target, ProductBranchTarget)
        self.assertEqual([product], target.components)

    def test_components(self):
        target = IBranchTarget(self.original)
        self.assertEqual([self.original], list(target.components))

    def test_default_stacked_on_branch_no_dev_focus(self):
        # The default stacked-on branch for a product target that has no
        # development focus is None.
        target = IBranchTarget(self.original)
        self.assertIs(None, target.default_stacked_on_branch)

    def _setDevelopmentFocus(self, product, branch):
        removeSecurityProxy(product).development_focus.branch = branch

    def test_default_stacked_on_branch_unmirrored_dev_focus(self):
        # If the development focus hasn't been mirrored, then don't use it as
        # the default stacked-on branch.
        branch = self.factory.makeProductBranch(product=self.original)
        self._setDevelopmentFocus(self.original, branch)
        target = IBranchTarget(self.original)
        self.assertIs(None, target.default_stacked_on_branch)

    def test_default_stacked_on_branch_has_been_mirrored(self):
        # If the development focus has been mirrored, then use it as the
        # default stacked-on branch.
        branch = self.factory.makeProductBranch(product=self.original)
        self._setDevelopmentFocus(self.original, branch)
        removeSecurityProxy(branch).branchChanged('', 'rev1', None, None, None)
        target = IBranchTarget(self.original)
        self.assertEqual(branch, target.default_stacked_on_branch)

    def test_supports_merge_proposals(self):
        # Product branches do support merge proposals.
        self.assertTrue(self.target.supports_merge_proposals)

    def test_supports_short_identites(self):
        # Product branches do support short bzr identites.
        self.assertTrue(self.target.supports_short_identites)

    def test_displayname(self):
        # The display name of a product branch target is the display name of
        # the product.
        target = IBranchTarget(self.original)
        self.assertEqual(self.original.displayname, target.displayname)

    def test_areBranchesMergeable_same_product(self):
        # Branches of the same product are mergeable.
        same_target = ProductBranchTarget(self.original)
        self.assertTrue(self.target.areBranchesMergeable(same_target))

    def test_areBranchesMergeable_different_product(self):
        # Branches of a different product are not mergeable.
        other_target = ProductBranchTarget(self.factory.makeProduct())
        self.assertFalse(self.target.areBranchesMergeable(other_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_package(self):
        # Package branches are not normally mergeable into products.
        branch = self.factory.makePackageBranch()
        self.assertFalse(self.target.areBranchesMergeable(branch.target))

    def test_areBranchesMergeable_linked_package(self):
        # Packages that are linked to the products are mergeable.
        branch = self.factory.makePackageBranch()
        # Link it up.
        branch.sourcepackage.setPackaging(self.original.development_focus,
                                          branch.owner)
        self.assertTrue(self.target.areBranchesMergeable(branch.target))

    def test_default_merge_target(self):
        # The default merge target is the development focus branch.
        self.assertIs(None, self.target.default_merge_target)
        # Now create and link a branch.
        branch = self.factory.makeProductBranch(product=self.original)
        run_with_login(self.original.owner, setattr,
                       self.original.development_focus, 'branch', branch)
        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.makeRelatedBranchesForProduct(product=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.makeRelatedBranchesForProduct(
                product=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_related_branches_with_limit(self):
        (branch, related_series_branch_info, related_package_branches) = (
            self.factory.makeRelatedBranchesForProduct(product=self.original))
        self.assertEqual(related_series_branch_info[:2],
                         self.target.getRelatedSeriesBranchInfo(branch, 2))
        self.assertEqual(related_package_branches[:2],
                         self.target.getRelatedPackageBranchInfo(branch, 2))
 def setUp(self):
     TestCaseWithFactory.setUp(self)
     self.original = self.factory.makeProduct()
     self.target = ProductBranchTarget(self.original)
class TestProductBranchTarget(TestCaseWithFactory, BaseBranchTargetTests):

    layer = DatabaseFunctionalLayer

    def setUp(self):
        TestCaseWithFactory.setUp(self)
        self.original = self.factory.makeProduct()
        self.target = ProductBranchTarget(self.original)

    def makeBranchForTarget(self):
        return self.factory.makeBranch(product=self.original)

    def test_name(self):
        self.assertEqual(self.original.name, self.target.name)

    def test_getNamespace(self):
        """Get namespace produces the correct namespace."""
        person = self.factory.makePerson()
        namespace = self.target.getNamespace(person)
        self.assertEqual(namespace.product, self.original)
        self.assertEqual(namespace.owner, person)

    def test_adapter(self):
        target = IBranchTarget(self.original)
        self.assertIsInstance(target, ProductBranchTarget)

    def test_productseries_adapter(self):
        # Adapting a product series will make a product branch target.
        product = self.factory.makeProduct()
        series = self.factory.makeProductSeries(product)
        target = IBranchTarget(series)
        self.assertIsInstance(target, ProductBranchTarget)
        self.assertEqual([product], target.components)

    def test_components(self):
        target = IBranchTarget(self.original)
        self.assertEqual([self.original], list(target.components))

    def test_default_stacked_on_branch_no_dev_focus(self):
        # The default stacked-on branch for a product target that has no
        # development focus is None.
        target = IBranchTarget(self.original)
        self.assertIs(None, target.default_stacked_on_branch)

    def _setDevelopmentFocus(self, product, branch):
        removeSecurityProxy(product).development_focus.branch = branch

    def test_default_stacked_on_branch_unmirrored_dev_focus(self):
        # If the development focus hasn't been mirrored, then don't use it as
        # the default stacked-on branch.
        branch = self.factory.makeProductBranch(product=self.original)
        self._setDevelopmentFocus(self.original, branch)
        target = IBranchTarget(self.original)
        self.assertIs(None, target.default_stacked_on_branch)

    def test_default_stacked_on_branch_has_been_mirrored(self):
        # If the development focus has been mirrored, then use it as the
        # default stacked-on branch.
        branch = self.factory.makeProductBranch(product=self.original)
        self._setDevelopmentFocus(self.original, branch)
        removeSecurityProxy(branch).branchChanged("", "rev1", None, None, None)
        target = IBranchTarget(self.original)
        self.assertEqual(branch, target.default_stacked_on_branch)

    def test_supports_merge_proposals(self):
        # Product branches do support merge proposals.
        self.assertTrue(self.target.supports_merge_proposals)

    def test_supports_short_identites(self):
        # Product branches do support short bzr identites.
        self.assertTrue(self.target.supports_short_identites)

    def test_displayname(self):
        # The display name of a product branch target is the display name of
        # the product.
        target = IBranchTarget(self.original)
        self.assertEqual(self.original.displayname, target.displayname)

    def test_areBranchesMergeable_same_product(self):
        # Branches of the same product are mergeable.
        same_target = ProductBranchTarget(self.original)
        self.assertTrue(self.target.areBranchesMergeable(same_target))

    def test_areBranchesMergeable_different_product(self):
        # Branches of a different product are not mergeable.
        other_target = ProductBranchTarget(self.factory.makeProduct())
        self.assertFalse(self.target.areBranchesMergeable(other_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_package(self):
        # Package branches are not normally mergeable into products.
        branch = self.factory.makePackageBranch()
        self.assertFalse(self.target.areBranchesMergeable(branch.target))

    def test_areBranchesMergeable_linked_package(self):
        # Packages that are linked to the products are mergeable.
        branch = self.factory.makePackageBranch()
        # Link it up.
        branch.sourcepackage.setPackaging(self.original.development_focus, branch.owner)
        self.assertTrue(self.target.areBranchesMergeable(branch.target))

    def test_default_merge_target(self):
        # The default merge target is the development focus branch.
        self.assertIs(None, self.target.default_merge_target)
        # Now create and link a branch.
        branch = self.factory.makeProductBranch(product=self.original)
        run_with_login(self.original.owner, setattr, self.original.development_focus, "branch", branch)
        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.makeRelatedBranchesForProduct(
            product=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.makeRelatedBranchesForProduct(
            product=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_related_branches_with_limit(self):
        (branch, related_series_branch_info, related_package_branches) = self.factory.makeRelatedBranchesForProduct(
            product=self.original
        )
        self.assertEqual(related_series_branch_info[:2], self.target.getRelatedSeriesBranchInfo(branch, 2))
        self.assertEqual(related_package_branches[:2], self.target.getRelatedPackageBranchInfo(branch, 2))