'Ensure that the negative and positive permissions for adding
attachments work.'

def test_permissions(self):

    ct = ContentType.objects.get(app_label='attachments', model='attachment')
    p1 = Permission.objects.get(codename='disallow_add_attachment', content_type=ct)
    p2 = Permission.objects.get(codename='add_attachment', content_type=ct)
    (g1, created) = Group.objects.get_or_create(name='cannot_attach')
    g1.permissions = [p1]
    g1.save()
    (g2, created) = Group.objects.get_or_create(name='can_attach')
    g2.permissions = [p2]
    g2.save()
    u2 = user(username='test_user2', save=True)
    self.assertTrue(allow_add_attachment_by(u2))
    u3 = user(username='test_user3', save=True)
    u3.groups = [g1]
    u3.save()
    self.assertTrue((not allow_add_attachment_by(u3)))
    u1 = user(username='test_super', is_superuser=True, save=True)
    u1.groups = [g1]
    u1.save()
    self.assertTrue(allow_add_attachment_by(u1))
    u4 = user(username='test_user4', save=True)
    u4.user_permissions.add(p1)
    u4.save()
    self.assertTrue((not allow_add_attachment_by(u4)))
    u5 = user(username='test_user5', save=True)
    u5.groups = [g1]
    u5.user_permissions.add(p2)
    u5.save()
    self.assertTrue(allow_add_attachment_by(u5))
    u6 = user(username='test_user6', save=True)
    u6.groups = [g1, g2]
    u6.save()
    self.assertTrue(allow_add_attachment_by(u6))
    u7 = user(username='test_user7', save=True)
    u7.user_permissions.add(p1)
    u7.user_permissions.add(p2)
    u7.save()
    self.assertTrue(allow_add_attachment_by(u7))
