예제 #1
0
    def test_branchInRestrictedProduct(self):
        # There are two reasons for a URL not being in the vocabulary. One
        # reason is that it's there's no registered branch with that URL. The
        # other is that the vocabulary on this form is restricted to one
        # product, and there *is* a branch with that URL, but it's registered
        # on a different product.

        # Make a popup restricted to a particular product.
        vocab = BranchRestrictedOnProductVocabulary(self.launch_bag.product)
        self.assertEqual(vocab.product, self.launch_bag.product)
        popup = self.makeBranchPopup(vocab)

        # Make a branch on a different product.
        branch = self.factory.makeProductBranch(
            branch_type=BranchType.MIRRORED)
        self.assertNotEqual(self.launch_bag.product, branch.product)

        # Trying to make a branch with that URL will fail.
        self.assertRaises(ConversionError, popup._toFieldValue, branch.url)
 def setUp(self):
     super(TestRestrictedBranchVocabularyOnProduct, self).setUp()
     self._createBranches()
     self.vocab = BranchRestrictedOnProductVocabulary(
         context=self._getVocabRestriction())
class TestRestrictedBranchVocabularyOnProduct(TestCaseWithFactory):
    """Test the BranchRestrictedOnProductVocabulary behaves as expected.

    When a BranchRestrictedOnProductVocabulary is used with a product the
    product of the branches in the vocabulary match the product given as the
    context.
    """

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestRestrictedBranchVocabularyOnProduct, self).setUp()
        self._createBranches()
        self.vocab = BranchRestrictedOnProductVocabulary(
            context=self._getVocabRestriction())

    def _getVocabRestriction(self):
        """Restrict using the widget product."""
        return getUtility(IProductSet).getByName('widget')

    def _createBranches(self):
        test_product = self.factory.makeProduct(name='widget')
        other_product = self.factory.makeProduct(name='sprocket')
        person = self.factory.makePerson(name='scotty')
        self.factory.makeProductBranch(owner=person,
                                       product=test_product,
                                       name='main')
        self.factory.makeProductBranch(owner=person,
                                       product=test_product,
                                       name='mountain')
        self.factory.makeProductBranch(owner=person,
                                       product=other_product,
                                       name='main')
        person = self.factory.makePerson(name='spotty')
        self.factory.makeProductBranch(owner=person,
                                       product=test_product,
                                       name='hill')
        self.product = test_product

    def test_mainBranches(self):
        """Look for widget's main branch.

        The result set should not show ~scotty/sprocket/main.
        """
        results = self.vocab.searchForTerms('main')
        expected = [u'~scotty/widget/main']
        branch_names = sorted([branch.token for branch in results])
        self.assertEqual(expected, branch_names)

    def test_singleQueryResult(self):
        # If there is a single search result that matches, use that
        # as the result.
        term = self.vocab.getTermByToken('mountain')
        self.assertEqual('~scotty/widget/mountain', term.value.unique_name)

    def test_multipleQueryResult(self):
        # If there are more than one search result, a LookupError is still
        # raised.
        self.assertRaises(LookupError, self.vocab.getTermByToken, 'scotty')

    def test_does_not_contain_inclusive_teams(self):
        open_team = self.factory.makeTeam(
            name='open-team', membership_policy=TeamMembershipPolicy.OPEN)
        delegated_team = self.factory.makeTeam(
            name='delegated-team',
            membership_policy=TeamMembershipPolicy.DELEGATED)
        for team in [open_team, delegated_team]:
            self.factory.makeProductBranch(owner=team,
                                           product=self.product,
                                           name='mountain')
        results = self.vocab.searchForTerms('mountain')
        branch_names = sorted([branch.token for branch in results])
        self.assertEqual(['~scotty/widget/mountain'], branch_names)
 def setUp(self):
     super(TestRestrictedBranchVocabularyOnProduct, self).setUp()
     self._createBranches()
     self.vocab = BranchRestrictedOnProductVocabulary(
         context=self._getVocabRestriction())
class TestRestrictedBranchVocabularyOnProduct(TestCaseWithFactory):
    """Test the BranchRestrictedOnProductVocabulary behaves as expected.

    When a BranchRestrictedOnProductVocabulary is used with a product the
    product of the branches in the vocabulary match the product given as the
    context.
    """

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestRestrictedBranchVocabularyOnProduct, self).setUp()
        self._createBranches()
        self.vocab = BranchRestrictedOnProductVocabulary(
            context=self._getVocabRestriction())

    def _getVocabRestriction(self):
        """Restrict using the widget product."""
        return getUtility(IProductSet).getByName('widget')

    def _createBranches(self):
        test_product = self.factory.makeProduct(name='widget')
        other_product = self.factory.makeProduct(name='sprocket')
        person = self.factory.makePerson(name='scotty')
        self.factory.makeProductBranch(
            owner=person, product=test_product, name='main')
        self.factory.makeProductBranch(
            owner=person, product=test_product, name='mountain')
        self.factory.makeProductBranch(
            owner=person, product=other_product, name='main')
        person = self.factory.makePerson(name='spotty')
        self.factory.makeProductBranch(
            owner=person, product=test_product, name='hill')
        self.product = test_product

    def test_mainBranches(self):
        """Look for widget's main branch.

        The result set should not show ~scotty/sprocket/main.
        """
        results = self.vocab.searchForTerms('main')
        expected = [u'~scotty/widget/main']
        branch_names = sorted([branch.token for branch in results])
        self.assertEqual(expected, branch_names)

    def test_singleQueryResult(self):
        # If there is a single search result that matches, use that
        # as the result.
        term = self.vocab.getTermByToken('mountain')
        self.assertEqual('~scotty/widget/mountain', term.value.unique_name)

    def test_multipleQueryResult(self):
        # If there are more than one search result, a LookupError is still
        # raised.
        self.assertRaises(LookupError, self.vocab.getTermByToken, 'scotty')

    def test_does_not_contain_inclusive_teams(self):
        open_team = self.factory.makeTeam(name='open-team',
            membership_policy=TeamMembershipPolicy.OPEN)
        delegated_team = self.factory.makeTeam(name='delegated-team',
            membership_policy=TeamMembershipPolicy.DELEGATED)
        for team in [open_team, delegated_team]:
            self.factory.makeProductBranch(
                owner=team, product=self.product, name='mountain')
        results = self.vocab.searchForTerms('mountain')
        branch_names = sorted([branch.token for branch in results])
        self.assertEqual(['~scotty/widget/mountain'], branch_names)