Ticket #17097: tests.patch

File tests.patch, 1.4 KB (added by George Hickman <george@…>, 13 years ago)

tests for the comments permissions

  • new file django/contrib/comments/tests.py

    diff --git a/django/contrib/comments/tests.py b/django/contrib/comments/tests.py
    new file mode 100644
    index 0000000..8d55267
    - +  
     1from django.contrib.auth.models import Group, Permission, User
     2from django.test import TestCase
     3
     4class CommentsAdminTest(TestCase):
     5    def setUp(self):
     6        self.permissions = Permission.objects.filter(content_type__model='comment')
     7        self.group = Group.objects.create(name='test_group')
     8        self.user1 = User.objects.create(username='test1', password='test1', is_staff=True)
     9        self.user2 = User.objects.create(username='test2', password='test2', is_staff=True)
     10
     11    def tearDown(self):
     12        self.user1.delete()
     13        self.user2.delete()
     14        self.group.delete()
     15
     16    def test_delete_permissions(self):
     17        self.group.permissions.add(self.permissions.get(codename='delete_comment'))
     18        self.user1.groups.add(self.group)
     19        self.assertTrue(self.user1.has_perm('comments.delete_comment'))
     20        self.assertFalse(self.user2.has_perm('comments.delete_comment'))
     21
     22    def test_moderate_permissions(self):
     23        self.group.permissions.add(self.permissions.get(codename='can_moderate'))
     24        self.user1.groups.add(self.group)
     25        self.assertTrue(self.user1.has_perm('comments.can_moderate'))
     26        self.assertFalse(self.user2.has_perm('comments.can_moderate'))
     27
Back to Top