| 1 |
from django.contrib.auth import get_user_model |
| 2 |
from django.contrib.contenttypes.models import ContentType |
| 3 |
from django.test import TestCase |
| 4 |
|
| 5 |
from guardian.shortcuts import assign_perm, remove_perm |
| 6 |
|
| 7 |
|
| 8 |
class CustomPKModelTest(TestCase): |
| 9 |
""" |
| 10 |
Tests against custom model with primary key other than *standard* |
| 11 |
``id`` integer field. |
| 12 |
""" |
| 13 |
|
| 14 |
def setUp(self): |
| 15 |
self.user = get_user_model().objects.create(username="joe") |
| 16 |
self.ctype = ContentType.objects.create(model="bar", app_label="fake-for-guardian-tests") |
| 17 |
|
| 18 |
def test_assign_perm(self): |
| 19 |
assign_perm("contenttypes.change_contenttype", self.user, self.ctype) |
| 20 |
self.assertTrue(self.user.has_perm("contenttypes.change_contenttype", self.ctype)) |
| 21 |
|
| 22 |
def test_remove_perm(self): |
| 23 |
assign_perm("contenttypes.change_contenttype", self.user, self.ctype) |
| 24 |
self.assertTrue(self.user.has_perm("contenttypes.change_contenttype", self.ctype)) |
| 25 |
remove_perm("contenttypes.change_contenttype", self.user, self.ctype) |
| 26 |
self.assertFalse(self.user.has_perm("contenttypes.change_contenttype", self.ctype)) |