2017-02-11 18:48:13 +01:00
|
|
|
from django.contrib.auth.models import Group, Permission, User
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2012-06-27 23:28:35 +02:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2017-02-11 18:48:13 +01:00
|
|
|
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):
|
|
|
|
# creates a group of cof members
|
|
|
|
group = Group.objects.create(name='cof_members')
|
|
|
|
|
|
|
|
# create a specific permission for all COF members.
|
|
|
|
ct = ContentType.objects.get(app_label='cof', model='CofProfile')
|
|
|
|
perm = Permission.objects.create(name='Cof Member',
|
|
|
|
codename='member',
|
|
|
|
content_type=ct)
|
|
|
|
|
|
|
|
# bind the two mutherfucker.
|
|
|
|
group.permissions = [perm]
|
|
|
|
|
|
|
|
# now test it for real
|
|
|
|
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
|
|
|
|
cofp.profile.user.groups.add(group)
|
|
|
|
cofp.save()
|
|
|
|
|
|
|
|
cofp = CofProfile.objects.first()
|
|
|
|
self.assertTrue(cofp.profile.user.has_perm('cof.member'))
|