kpsul/cof/tests.py

27 lines
892 B
Python

from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from cof.models import CofProfile
from gestion.tests import create_profile
def create_cofprofile(username):
p = create_profile(username)
return CofProfile.objects.create(profile=p)
class TestCofProfile(TestCase):
def test_str(self):
cofp = create_cofprofile('foo')
# XXX. should by default new CofProfiles be COF members?
self.assertFalse(cofp.profile.user.has_perm('cof.member'))
# adding/removing a user from the group should impact the
# permission
group = Group.objects.get(name='cof_members')
cofp.profile.user.groups.add(group)
cofp.save()
cofp = CofProfile.objects.first()
self.assertTrue(cofp.profile.user.has_perm('cof.member'))