示例#1
0
文件: tests.py 项目: magatz/pybbm-1
    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))
示例#2
0
    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))
示例#3
0
文件: tests.py 项目: magatz/pybbm-1
    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()]))
示例#4
0
    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()]))
示例#5
0
    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)
示例#6
0
    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)