Ticket #13743: comments_admin_with_tests.diff

File comments_admin_with_tests.diff, 2.8 KB (added by daniellindsley, 14 years ago)

Patch with tests.

  • django/contrib/comments/admin.py

    diff --git a/django/contrib/comments/admin.py b/django/contrib/comments/admin.py
    index 28678e0..4cb9066 100644
    a b class CommentsAdmin(admin.ModelAdmin):  
    2828    def get_actions(self, request):
    2929        actions = super(CommentsAdmin, self).get_actions(request)
    3030        # Only superusers should be able to delete the comments from the DB.
    31         if not request.user.is_superuser:
     31        if not request.user.is_superuser and 'delete_selected' in actions:
    3232            actions.pop('delete_selected')
    3333        if not request.user.has_perm('comments.can_moderate'):
    34             actions.pop('approve_comments')
    35             actions.pop('remove_comments')
     34            if 'approve_comments' in actions:
     35                actions.pop('approve_comments')
     36            if 'remove_comments' in actions:
     37                actions.pop('remove_comments')
    3638        return actions
    3739
    3840    def flag_comments(self, request, queryset):
  • tests/regressiontests/comment_tests/tests/moderation_view_tests.py

    diff --git a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py
    index ef79b4d..65c9567 100644
    a b class AdminActionsTests(CommentTestCase):  
    190190        self.client.login(username="normaluser", password="normaluser")
    191191        response = self.client.get("/admin/comments/comment/")
    192192        self.assertEquals("approve_comments" in response.content, True)
     193   
     194    def testActionsDisabledDelete(self):
     195        "Tests a CommentAdmin where 'delete_selected' has been disabled."
     196        comments = self.createSomeComments()
     197        self.client.login(username="normaluser", password="normaluser")
     198        response = self.client.get('/admin2/comments/comment/')
     199        self.assertEqual(response.status_code, 200)
     200        self.assert_(
     201            '<option value="delete_selected">' not in response.content,
     202            "Found an unexpected delete_selected in response"
     203        )
  • tests/regressiontests/comment_tests/urls_admin.py

    diff --git a/tests/regressiontests/comment_tests/urls_admin.py b/tests/regressiontests/comment_tests/urls_admin.py
    index 341285d..d7e1a4e 100644
    a b from django.contrib.comments.models import Comment  
    88admin_site = admin.AdminSite()
    99admin_site.register(Comment, CommentsAdmin)
    1010
     11# To demonstrate proper functionality even when ``delete_selected`` is removed.
     12admin_site2 = admin.AdminSite()
     13admin_site2.disable_action('delete_selected')
     14admin_site2.register(Comment, CommentsAdmin)
     15
    1116urlpatterns = patterns('',
    1217    (r'^admin/', include(admin_site.urls)),
     18    (r'^admin2/', include(admin_site2.urls)),
    1319)
Back to Top