Ticket #24258: 24258-testcase.diff

File 24258-testcase.diff, 3.8 KB (added by Aymeric Augustin, 10 years ago)
  • tests/admin_changelist/admin.py

    diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
    index b2bd578..2feb4a9 100644
    a b  
    11from django.contrib import admin
    22from django.core.paginator import Paginator
     3from django.core.urlresolvers import reverse
    34from django.contrib.auth.admin import UserAdmin
    45from django.contrib.auth.models import User
     6from django.http import HttpResponseRedirect
    57
    6 from .models import Event, Child, Parent, Swallow
     8from .models import Event, Child, Messenger, Parent, Swallow
    79
    810
    911site = admin.AdminSite(name="admin")
    class DynamicSearchFieldsChildAdmin(admin.ModelAdmin):  
    126128        search_fields = super(DynamicSearchFieldsChildAdmin, self).get_search_fields(request)
    127129        search_fields += ('age',)
    128130        return search_fields
     131
     132
     133class MessengerAdmin(admin.ModelAdmin):
     134    actions = ['show_message']
     135
     136    def show_message(self, request, queryset):
     137        self.message_user(request, "Hey there!")
     138        return HttpResponseRedirect(reverse('admin:admin_changelist_messenger_changelist'))
     139
     140site.register(Messenger, MessengerAdmin)
  • tests/admin_changelist/models.py

    diff --git a/tests/admin_changelist/models.py b/tests/admin_changelist/models.py
    index 76249b2..24ab9fa 100644
    a b class OrderedObject(models.Model):  
    105105
    106106class CustomIdUser(models.Model):
    107107    uuid = models.AutoField(primary_key=True)
     108
     109
     110class Messenger(models.Model):
     111    name = models.CharField(max_length=128)
  • tests/admin_changelist/tests.py

    diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
    index 5ee5a51..13543bc 100644
    a b from __future__ import unicode_literals  
    33import datetime
    44
    55from django.contrib import admin
     6from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
    67from django.contrib.admin.options import IncorrectLookupParameters
    78from django.contrib.admin.templatetags.admin_list import pagination
    89from django.contrib.admin.views.main import ChangeList, SEARCH_VAR, ALL_VAR
    from .admin import (ChildAdmin, QuartetAdmin, BandAdmin, ChordsBandAdmin,  
    2324    DynamicSearchFieldsChildAdmin, NoListDisplayLinksParentAdmin)
    2425from .models import (Event, Child, Parent, Genre, Band, Musician, Group,
    2526    Quartet, Membership, ChordsMusician, ChordsBand, Invitation, Swallow,
    26     UnorderedObject, OrderedObject, CustomIdUser)
     27    UnorderedObject, OrderedObject, CustomIdUser, Messenger)
    2728
    2829
    2930@override_settings(ROOT_URLCONF="admin_changelist.urls")
    class AdminLogNodeTestCase(TestCase):  
    664665        self.assertEqual(template.render(context), '')
    665666
    666667
     668@override_settings(ROOT_URLCONF="admin_changelist.urls")
     669class AdminShowMessageLogsUserOut(TestCase):
     670
     671    def test_show_message_logs_user_out(self):
     672        messenger = Messenger.objects.create(name="Hermès")
     673
     674        self.user = User.objects.create_superuser('user', 'user@website', 'pass')
     675        self.client.login(username='user', password='pass')
     676
     677        response = self.client.get(reverse('admin:admin_changelist_messenger_changelist'))
     678        self.assertEqual(response.status_code, 200)
     679
     680        response = self.client.post(reverse('admin:admin_changelist_messenger_changelist'), {
     681            'action': 'show_message',
     682            ACTION_CHECKBOX_NAME: [str(messenger.pk)],
     683        })
     684        self.assertEqual(response.status_code, 302)
     685
     686        response = self.client.get(reverse('admin:admin_changelist_messenger_changelist'))
     687        self.assertEqual(response.status_code, 200)
     688
     689
    667690@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
    668691                   ROOT_URLCONF="admin_changelist.urls")
    669692class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
Back to Top