gestioCOF/cof/tests.py
Michele Orrù ee1f29b17d Make is_cof a property and start developing permissions.
Rmeove the is_cof flag to check permission and start implementing
a group and a permission for the respective cof members.
XXX. note: migrations do NOT add old is_cof members to the new group
(as actually they're just on the tests…)
2017-02-11 18:48:13 +01:00

37 lines
1.3 KiB
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):
# 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'))