94 lines
3 KiB
Python
94 lines
3 KiB
Python
|
from django.contrib.auth.models import User, Group
|
||
|
from django.core.management import BaseCommand
|
||
|
|
||
|
from gestion.models import (
|
||
|
Association, Club, ClubUser, Event, EventCommentField, EventCommentValue,
|
||
|
EventRegistration, Location,
|
||
|
)
|
||
|
|
||
|
|
||
|
class Command(BaseCommand):
|
||
|
|
||
|
def handle(self, *args, **options):
|
||
|
self.check_cof_assoc()
|
||
|
self.check_users()
|
||
|
self.check_clubs()
|
||
|
self.check_events()
|
||
|
|
||
|
self.stdout.write("All good, gg wp! :-)")
|
||
|
|
||
|
def check_cof_assoc(self):
|
||
|
self.stdout.write("* COF assoc... ", ending='')
|
||
|
|
||
|
self.assoc = Association.objects.get(name='COF')
|
||
|
self.g_staff = Group.objects.get(name='cof_buro')
|
||
|
self.g_members = Group.objects.get(name='cof_members')
|
||
|
assert self.assoc.staff_group == self.g_staff
|
||
|
assert self.assoc.members_group == self.g_members
|
||
|
|
||
|
self.stdout.write("OK")
|
||
|
|
||
|
def check_users(self):
|
||
|
self.stdout.write("* Utilisateurs... ", ending='')
|
||
|
|
||
|
self.u1 = User.objects.get(username='user1')
|
||
|
assert self.u1.profile.login_clipper == 'user1'
|
||
|
assert self.g_staff in self.u1.groups.all()
|
||
|
assert self.g_members in self.u1.groups.all()
|
||
|
assert self.u1.has_perm('cof.buro')
|
||
|
assert self.u1.has_perm('cof.member')
|
||
|
|
||
|
self.u2 = User.objects.get(username='user2')
|
||
|
assert self.u2.profile.login_clipper == 'user2'
|
||
|
assert self.g_staff not in self.u2.groups.all()
|
||
|
assert self.g_members in self.u2.groups.all()
|
||
|
assert not self.u2.has_perm('cof.buro')
|
||
|
assert self.u2.has_perm('cof.member')
|
||
|
|
||
|
self.u3 = User.objects.get(username='user3')
|
||
|
assert self.u3.profile.login_clipper == 'user3'
|
||
|
assert self.g_staff not in self.u3.groups.all()
|
||
|
assert self.g_members not in self.u3.groups.all()
|
||
|
assert not self.u3.has_perm('cof.buro')
|
||
|
assert not self.u3.has_perm('cof.member')
|
||
|
|
||
|
self.stdout.write("OK")
|
||
|
|
||
|
def check_clubs(self):
|
||
|
self.stdout.write("* Clubs... ", ending='')
|
||
|
|
||
|
c1 = Club.objects.get(name='Club 1')
|
||
|
m1_1 = ClubUser.objects.get(user=self.u1, club=c1)
|
||
|
assert not m1_1.is_respo
|
||
|
m1_2 = ClubUser.objects.get(user=self.u2, club=c1)
|
||
|
assert m1_2.is_respo
|
||
|
|
||
|
c2 = Club.objects.get(name='Club 2')
|
||
|
assert c2.members.count() == 0
|
||
|
|
||
|
self.stdout.write("OK")
|
||
|
|
||
|
def check_events(self):
|
||
|
self.stdout.write("* Évènements... ", ending='')
|
||
|
|
||
|
Location.objects.get(name='Location 1')
|
||
|
assert Location.objects.count() == 1
|
||
|
|
||
|
e1 = Event.objects.get(title='Event 1')
|
||
|
|
||
|
assert e1.associations.count() == 1
|
||
|
assert e1.commentfields.count() == 2
|
||
|
|
||
|
er1 = e1.eventregistration_set.all()
|
||
|
assert len(er1) == 2
|
||
|
|
||
|
er1_1 = EventRegistration.objects.get(user=self.u2, event=e1)
|
||
|
assert er1_1.filledcomments.count() == 1
|
||
|
|
||
|
er1_2 = EventRegistration.objects.get(user=self.u3, event=e1)
|
||
|
assert er1_2.filledcomments.count() == 1
|
||
|
|
||
|
Event.objects.get(title='Event 2')
|
||
|
|
||
|
self.stdout.write("OK")
|