def test_pagination_exception(self):
        """
        If an error is raised during pagination, then the underlying view
        should be called.

        """
        request = self.factory.get('/', user=self.user)
        tier = self.create_tier(video_limit=0)
        self.create_tier_info(tier)
        with mock.patch('localtv.admin.approve_reject_views.Paginator.page',
                        side_effect=Exception):
            approve_all(request)
        self.approve_all.assert_called_with(request)
    def test_no_limit(self):
        """
        If there's no limit, the underlying view should be called.

        """
        request = self.factory.get('/', user=self.user)
        tier = self.create_tier(video_limit=None)
        self.create_tier_info(tier)

        approve_all(request)
        self.approve_all.assert_called_with(request)
        self.assertEqual(Video.objects.filter(status=Video.UNAPPROVED
                                     ).count(), 3)
    def test_below_limit__exact(self):
        """
        If the number of videos remaining is exactly equal to the space left,
        the underlying view should be called.

        """
        request = self.factory.get('/', user=self.user)
        tier = self.create_tier(video_limit=3)
        self.create_tier_info(tier)

        approve_all(request)
        self.approve_all.assert_called_with(request)
        self.assertEqual(Video.objects.filter(status=Video.UNAPPROVED
                                     ).count(), 3)
    def test_above_limit(self):
        """
        If the limit has been reached, we should get a 402 and the
        underlying view shouldn't be called.

        """
        request = self.factory.get('/', user=self.user)
        tier = self.create_tier(video_limit=0)
        self.create_tier_info(tier)

        response = approve_all(request)
        self.assertFalse(self.approve_all.called)
        self.assertEqual(response.status_code, 402)
        self.assertEqual(Video.objects.filter(status=Video.UNAPPROVED
                                     ).count(), 3)