Esempio n. 1
0
 def test_errors(self):
     not_saved_user = User(username='******')
     codename = get_user_permission_codename('change')
     self.assertRaises(ObjectNotPersisted,
                       UserObjectPermission.objects.assign_perm, codename,
                       self.user, not_saved_user)
     self.assertRaises(ObjectNotPersisted,
                       UserObjectPermission.objects.remove_perm, codename,
                       self.user, not_saved_user)
Esempio n. 2
0
 def test_errors(self):
     not_saved_user = User(username='******')
     codename = get_user_permission_codename('change')
     self.assertRaises(ObjectNotPersisted,
         UserObjectPermission.objects.assign_perm,
         codename, self.user, not_saved_user)
     self.assertRaises(ObjectNotPersisted,
         UserObjectPermission.objects.remove_perm,
             codename, self.user, not_saved_user)
Esempio n. 3
0
    def test_assign_perm_validation(self):
        self.assertRaises(
            Permission.DoesNotExist, UserObjectPermission.objects.assign_perm, "change_group", self.user, self.user
        )

        group = Group.objects.create(name="test_group_assign_perm_validation")
        ctype = ContentType.objects.get_for_model(group)
        user_ctype = ContentType.objects.get_for_model(self.user)
        codename = get_user_permission_codename("change")
        perm = Permission.objects.get(codename=codename, content_type=user_ctype)

        create_info = dict(permission=perm, user=self.user, content_type=ctype, object_pk=group.pk)
        self.assertRaises(ValidationError, UserObjectPermission.objects.create, **create_info)
Esempio n. 4
0
    def test_assign_perm_validation(self):
        self.assertRaises(Permission.DoesNotExist,
                          UserObjectPermission.objects.assign_perm,
                          'change_group', self.user, self.user)

        group = Group.objects.create(name='test_group_assign_perm_validation')
        ctype = ContentType.objects.get_for_model(group)
        codename = codename = get_user_permission_codename('change')
        perm = Permission.objects.get(codename=codename)

        create_info = dict(permission=perm,
                           user=self.user,
                           content_type=ctype,
                           object_pk=group.pk)
        self.assertRaises(ValidationError, UserObjectPermission.objects.create,
                          **create_info)
Esempio n. 5
0
 def test_unicode(self):
     codename = get_user_permission_codename('change')
     obj_perm = UserObjectPermission.objects.assign_perm(
         codename, self.user, self.user)
     self.assertTrue(isinstance(unicode(obj_perm), unicode))
Esempio n. 6
0
 def test_unicode(self):
     codename = get_user_permission_codename('change')
     obj_perm = UserObjectPermission.objects.assign_perm(codename,
         self.user, self.user)
     self.assertTrue(isinstance(obj_perm.__unicode__(), unicode))