Beispiel #1
0
    def setUp(self):
        super(ReviewGroupsChoiceTests, self).setUp()

        self.request = RequestFactory().request()
        self.request.user = User.objects.create(username='******')

        self.choice = ReviewGroupsChoice(request=self.request)
Beispiel #2
0
    def setUp(self):
        super(ReviewGroupsChoiceTests, self).setUp()

        self.request = RequestFactory().request()
        self.request.user = User.objects.create(username='******')

        self.choice = ReviewGroupsChoice(request=self.request)
Beispiel #3
0
class ReviewGroupsChoiceTests(TestCase):
    """Unit tests for reviewboard.reviews.conditions.ReviewGroupsChoice."""
    def setUp(self):
        super(ReviewGroupsChoiceTests, self).setUp()

        self.request = RequestFactory().request()
        self.request.user = User.objects.create(username='******')

        self.choice = ReviewGroupsChoice(request=self.request)

    def test_get_queryset(self):
        """Testing ReviewGroupsChoice.get_queryset"""
        # These should match.
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')

        # These should not match.
        self.create_review_group(name='group3', visible=False)

        self.assertQuerysetEqual(self.choice.get_queryset(),
                                 [group1.pk, group2.pk],
                                 transform=lambda group: group.pk)

    def test_get_queryset_with_local_site(self):
        """Testing ReviewGroupsChoice.get_queryset with LocalSite"""
        good_site = LocalSite.objects.create(name='good-site')
        bad_site = LocalSite.objects.create(name='bad-site')

        # These should match.
        group1 = self.create_review_group(name='group1', local_site=good_site)
        group2 = self.create_review_group(name='group2', local_site=good_site)

        # These should not match.
        self.create_review_group(name='group3')
        self.create_review_group(name='group4', local_site=bad_site)
        self.create_review_group(name='group5',
                                 local_site=good_site,
                                 visible=False)

        self.choice.extra_state['local_site'] = good_site

        self.assertQuerysetEqual(self.choice.get_queryset(),
                                 [group1.pk, group2.pk],
                                 transform=lambda group: group.pk)

    def test_get_queryset_with_matching(self):
        """Testing ReviewGroupsChoice.get_queryset with matching=True"""
        local_site = LocalSite.objects.create(name='site1')

        # These should match.
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')
        group3 = self.create_review_group(name='group3', visible=False)
        group4 = self.create_review_group(name='group4', invite_only=True)

        # These should not match.
        self.create_review_group(name='group5',
                                 visible=False,
                                 local_site=local_site)

        self.choice.extra_state.update({
            'local_site': None,
            'matching': True,
        })

        self.assertQuerysetEqual(self.choice.get_queryset(),
                                 [group1.pk, group2.pk, group3.pk, group4.pk],
                                 transform=lambda group: group.pk)

    def test_get_queryset_with_matching_and_local_site(self):
        """Testing ReviewGroupsChoice.get_queryset with matching=True and
        LocalSite
        """
        good_site = LocalSite.objects.create(name='good-site')
        bad_site = LocalSite.objects.create(name='bad-site')

        # These should match.
        group1 = self.create_review_group(name='group1', local_site=good_site)
        group2 = self.create_review_group(name='group2', local_site=good_site)
        group3 = self.create_review_group(name='group3',
                                          local_site=good_site,
                                          visible=False)
        group4 = self.create_review_group(name='group4',
                                          local_site=good_site,
                                          invite_only=True)

        # These should not match.
        self.create_review_group(name='group5')
        self.create_review_group(name='group6', local_site=bad_site)

        self.choice.extra_state.update({
            'local_site': good_site,
            'matching': True,
        })

        self.assertQuerysetEqual(self.choice.get_queryset(),
                                 [group1.pk, group2.pk, group3.pk, group4.pk],
                                 transform=lambda group: group.pk)

    def test_matches_with_any_op(self):
        """Testing ReviewGroupsChoice.matches with "any" operator"""
        self.create_review_group(name='group1', invite_only=False)
        self.create_review_group(name='group2', invite_only=True)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('any')),
        ])

        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.all()))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.none()))

    def test_matches_with_none_op(self):
        """Testing ReviewGroupsChoice.matches with "none" operator"""
        self.create_review_group(name='group1')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('none')),
        ])

        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.none()))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.all()))

    def test_matches_with_contains_any_op(self):
        """Testing ReviewGroupsChoice.matches with "contains-any" operator"""
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')
        group3 = self.create_review_group(name='group3')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains-any'),
                      [group1, group2])
        ])

        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group1.pk)))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group3.pk)))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.none()))

    def test_matches_with_does_not_contain_any_op(self):
        """Testing ReviewGroupsChoice.matches with "does-not-contain-any"
        operator
        """
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')
        group3 = self.create_review_group(name='group3')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-contain-any'),
                      [group1, group2])
        ])

        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group1.pk)))
        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group3.pk)))
        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.none()))

    def test_matches_with_any_public_op(self):
        """Testing ReviewGroupsChoice.matches with "any-public" operator"""
        group1 = self.create_review_group(name='group1', invite_only=False)
        group2 = self.create_review_group(name='group2', invite_only=True)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('any-public')),
        ])

        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group1.pk)))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group2.pk)))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.none()))

    def test_matches_with_all_invite_only_op(self):
        """Testing ReviewGroupsChoice.matches with "all-invite-only" operator
        """
        group1 = self.create_review_group(name='group1', invite_only=True)
        group2 = self.create_review_group(name='group2', invite_only=False)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('all-invite-only')),
        ])

        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group1.pk)))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.filter(
                pk=group2.pk)))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.none()))
Beispiel #4
0
    def setUp(self):
        super(ReviewGroupsChoiceTests, self).setUp()

        self.choice = ReviewGroupsChoice()
Beispiel #5
0
class ReviewGroupsChoiceTests(TestCase):
    """Unit tests for reviewboard.reviews.conditions.ReviewGroupsChoice."""

    def setUp(self):
        super(ReviewGroupsChoiceTests, self).setUp()

        self.choice = ReviewGroupsChoice()

    def test_get_queryset(self):
        """Testing ReviewGroupsChoice.get_queryset"""
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')

        self.assertQuerysetEqual(
            self.choice.get_queryset(),
            [group1.pk, group2.pk],
            transform=lambda group: group.pk)

    def test_get_queryset_with_local_site(self):
        """Testing ReviewGroupsChoice.get_queryset with LocalSite"""
        good_site = LocalSite.objects.create(name='good-site')
        bad_site = LocalSite.objects.create(name='bad-site')

        # These should match.
        group1 = self.create_review_group(name='group1',
                                          local_site=good_site)
        group2 = self.create_review_group(name='group2',
                                          local_site=good_site)

        # These should not match.
        self.create_review_group(name='group3')
        self.create_review_group(name='group4', local_site=bad_site)

        self.choice.extra_state['local_site'] = good_site

        self.assertQuerysetEqual(
            self.choice.get_queryset(),
            [group1.pk, group2.pk],
            transform=lambda group: group.pk)

    def test_matches_with_any_op(self):
        """Testing ReviewGroupsChoice.matches with "any" operator"""
        self.create_review_group(name='group1', invite_only=False)
        self.create_review_group(name='group2', invite_only=True)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('any')),
        ])

        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.all()))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.none()))

    def test_matches_with_none_op(self):
        """Testing ReviewGroupsChoice.matches with "none" operator"""
        self.create_review_group(name='group1')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('none')),
        ])

        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.none()))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.all()))

    def test_matches_with_contains_any_op(self):
        """Testing ReviewGroupsChoice.matches with "contains-any" operator"""
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')
        group3 = self.create_review_group(name='group3')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains-any'),
                      [group1, group2])
        ])

        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.filter(pk=group1.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.filter(pk=group3.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.none()))

    def test_matches_with_does_not_contain_any_op(self):
        """Testing ReviewGroupsChoice.matches with "does-not-contain-any"
        operator
        """
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')
        group3 = self.create_review_group(name='group3')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-contain-any'),
                      [group1, group2])
        ])

        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.filter(pk=group1.pk)))
        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.filter(pk=group3.pk)))
        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.none()))

    def test_matches_with_any_public_op(self):
        """Testing ReviewGroupsChoice.matches with "any-public" operator"""
        group1 = self.create_review_group(name='group1', invite_only=False)
        group2 = self.create_review_group(name='group2', invite_only=True)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('any-public')),
        ])

        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.filter(pk=group1.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.filter(pk=group2.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.none()))

    def test_matches_with_all_invite_only_op(self):
        """Testing ReviewGroupsChoice.matches with "all-invite-only" operator
        """
        group1 = self.create_review_group(name='group1', invite_only=True)
        group2 = self.create_review_group(name='group2', invite_only=False)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('all-invite-only')),
        ])

        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.filter(pk=group1.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.filter(pk=group2.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.none()))
Beispiel #6
0
    def setUp(self):
        super(ReviewGroupsChoiceTests, self).setUp()

        self.choice = ReviewGroupsChoice()