Ejemplo n.º 1
0
    def setUp(self):
        super(ReviewRequestSubmitterChoiceTests, self).setUp()

        self.choice = ReviewRequestSubmitterChoice()
        self.user1 = User.objects.get(username='******')
        self.user2 = User.objects.get(username='******')
        self.user3 = User.objects.get(username='******')
Ejemplo n.º 2
0
    def setUp(self):
        super(ReviewRequestSubmitterChoiceTests, self).setUp()

        self.choice = ReviewRequestSubmitterChoice()
        self.user1 = User.objects.get(username='******')
        self.user2 = User.objects.get(username='******')
        self.user3 = User.objects.get(username='******')
Ejemplo n.º 3
0
class ReviewRequestSubmitterChoiceTests(TestCase):
    """Unit tests for ReviewRequestSubmitterChoice."""

    fixtures = ['test_users']

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

        self.choice = ReviewRequestSubmitterChoice()
        self.user1 = User.objects.get(username='******')
        self.user2 = User.objects.get(username='******')
        self.user3 = User.objects.get(username='******')

    def test_get_queryset(self):
        """Testing ReviewRequestSubmitterChoice.get_queryset"""
        self.assertQuerysetEqual(
            self.choice.get_queryset(),
            User.objects.values_list('pk', flat=True),
            transform=lambda user: user.pk)

    def test_get_queryset_with_local_site(self):
        """Testing ReviewRequestSubmitterChoice.get_queryset with LocalSite"""
        good_site = LocalSite.objects.create(name='good-site')
        good_site.users.add(self.user2)

        bad_site = LocalSite.objects.create(name='bad-site')
        bad_site.users.add(self.user3)

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

        self.assertQuerysetEqual(
            self.choice.get_queryset(),
            [self.user2.pk],
            transform=lambda user: user.pk)

    def test_matches_with_one_of_op(self):
        """Testing ReviewRequestSubmitterChoice.matches with "one-of"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('one-of'),
                      [self.user1, self.user2]),
        ])

        self.assertTrue(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user1)))
        self.assertTrue(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user2)))
        self.assertFalse(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user3)))

    def test_matches_with_not_one_of_op(self):
        """Testing ReviewRequestSubmitterChoice.matches with "not-one-of"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('not-one-of'),
                      [self.user1, self.user2]),
        ])

        self.assertFalse(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user1)))
        self.assertFalse(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user2)))
        self.assertTrue(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user3)))
Ejemplo n.º 4
0
class ReviewRequestSubmitterChoiceTests(TestCase):
    """Unit tests for ReviewRequestSubmitterChoice."""

    fixtures = ['test_users']

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

        self.choice = ReviewRequestSubmitterChoice()
        self.user1 = User.objects.get(username='******')
        self.user2 = User.objects.get(username='******')
        self.user3 = User.objects.get(username='******')

    def test_get_queryset(self):
        """Testing ReviewRequestSubmitterChoice.get_queryset"""
        self.assertQuerysetEqual(self.choice.get_queryset(),
                                 User.objects.values_list('pk', flat=True),
                                 transform=lambda user: user.pk)

    def test_get_queryset_with_local_site(self):
        """Testing ReviewRequestSubmitterChoice.get_queryset with LocalSite"""
        good_site = LocalSite.objects.create(name='good-site')
        good_site.users.add(self.user2)

        bad_site = LocalSite.objects.create(name='bad-site')
        bad_site.users.add(self.user3)

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

        self.assertQuerysetEqual(self.choice.get_queryset(), [self.user2.pk],
                                 transform=lambda user: user.pk)

    def test_matches_with_one_of_op(self):
        """Testing ReviewRequestSubmitterChoice.matches with "one-of"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('one-of'),
                      [self.user1, self.user2]),
        ])

        self.assertTrue(
            condition_set.matches(review_request=self.create_review_request(
                submitter=self.user1)))
        self.assertTrue(
            condition_set.matches(review_request=self.create_review_request(
                submitter=self.user2)))
        self.assertFalse(
            condition_set.matches(review_request=self.create_review_request(
                submitter=self.user3)))

    def test_matches_with_not_one_of_op(self):
        """Testing ReviewRequestSubmitterChoice.matches with "not-one-of"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('not-one-of'),
                      [self.user1, self.user2]),
        ])

        self.assertFalse(
            condition_set.matches(review_request=self.create_review_request(
                submitter=self.user1)))
        self.assertFalse(
            condition_set.matches(review_request=self.create_review_request(
                submitter=self.user2)))
        self.assertTrue(
            condition_set.matches(review_request=self.create_review_request(
                submitter=self.user3)))