예제 #1
0
    def test_action_get(self):

        request = self.factory.post(self._url,
                {'action': 'mass_update', 'index': 0, 'select_across': 0,
                 '_selected_action': [2, 3, 4]})

        request.user = User.objects.get(pk=1)
        queryset = User.objects.filter(is_superuser=False)
        modeladmin = site._registry[auth.models.User]
        response = mass_update(modeladmin, request, queryset)
        self.assertEqual(response.status_code, 200)
예제 #2
0
    def test_action_post(self):
        target_ids = [2, 3, 4, 7, 10]

        request = self.factory.post(self._url,
                {'action': 'mass_update', 'apply': 'Update records', 'chk_id_is_active': 'on',
                 '_selected_action': target_ids})

        request.user = User.objects.get(pk=1)
        modeladmin = site._registry[auth.models.User]

        # we add is_active=True just as double check
        queryset = User.objects.filter(pk__in=target_ids, is_active=True)
        response = mass_update(modeladmin, request, queryset)

        self.assertEquals(response.status_code, 302)
        self.assertEquals(target_ids, [u.pk for u in User.objects.filter(is_active=False)])
예제 #3
0
    def test_many_to_many(self):

        target_ids = [2, 3, 4, 7, 10]

        request = self.factory.post(self._url,
                {'action': 'mass_update', 'apply': 'Update records', 'chk_id_groups': 'on',
                 'groups': ['2'],'_selected_action': target_ids, '_validate': 'on'})

        request.user = User.objects.get(pk=1)
        request._messages = CookieStorage(request)
        modeladmin = site._registry[auth.models.User]

        # we add is_active=True just as double check
        queryset = User.objects.filter(pk__in=target_ids)
        response = mass_update(modeladmin, request, queryset)

        self.assertEquals(response.status_code, 200)