def test_moderation_form_with_obj(self): data = dict((codename, 1) for codename in self.codenames) form = ModerationForm(permissions=self.permissions, data=data) self.failUnless(form.is_valid()) form.save(self.user, self.forum) self.assertTrue(self.user.has_perms(self.codenames, self.forum))
def test_moderation_form_with_obj(self): data = dict((codename, 1) for codename in self.codenames) form = ModerationForm(permissions=self.permissions, data=data) self.assertTrue(form.is_valid()) form.save(self.user, self.forum) self.assertTrue(self.user.has_perms(self.codenames, self.forum))
def test_moderation_form_without_obj(self): data = dict((codename, 1) for codename in defaults.PYBB_USER_PERMISSIONS) permissions = Permission.objects.filter(codename__in=data.keys()) form = ModerationForm(permissions=permissions, data=data) self.failUnless(form.is_valid()) form.save(self.user) self.assertTrue(self.user.has_perms(['pybb.' + value for value in data.keys()]))
def test_moderation_form_without_obj(self): data = dict( (codename, 1) for codename in defaults.PYBB_USER_PERMISSIONS) permissions = Permission.objects.filter(codename__in=data.keys()) form = ModerationForm(permissions=permissions, data=data) self.assertTrue(form.is_valid()) form.save(self.user) self.assertTrue( self.user.has_perms(['pybb.' + value for value in data.keys()]))
def test_moderation_form_with_existing_permissions_and_with_obj(self): for permission in self.permissions: UserObjectPermission.objects.assign_perm(user=self.user, permission=permission, obj=self.forum) form = ModerationForm(permissions=self.permissions, user=self.user, obj=self.forum) for permission in self.permissions: self.assertEqual(form.fields[permission.codename].initial, 1)
def test_moderation_form_with_existing_permissions_and_without_obj(self): data = dict( (codename, 1) for codename in defaults.PYBB_USER_PERMISSIONS) permissions = Permission.objects.filter(codename__in=data.keys()) for permission in permissions: self.user.user_permissions.add(permission) form = ModerationForm(permissions=permissions, data=data, user=self.user) for permission in permissions: self.assertEqual(form.fields[permission.codename].initial, 1)