| 1 | from django.contrib.auth.models import Group, Permission, User |
| 2 | from django.test import TestCase |
| 3 | |
| 4 | class 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 | |