models & tests de event
normalement c'est fini
This commit is contained in:
parent
d4b96f0567
commit
6365704d2d
2 changed files with 138 additions and 40 deletions
|
@ -42,8 +42,8 @@ class Event(models.Model):
|
||||||
ending_date = models.DateTimeField(_('Date de fin'))
|
ending_date = models.DateTimeField(_('Date de fin'))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Évènement")
|
verbose_name = _("évènement")
|
||||||
verbose_name_plural = _("Évènements")
|
verbose_name_plural = _("évènements")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
@ -57,8 +57,8 @@ class Place(models.Model):
|
||||||
description = models.TextField(blank=True)
|
description = models.TextField(blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Lieu")
|
verbose_name = _("lieu")
|
||||||
verbose_name_plural = _("Lieux")
|
verbose_name_plural = _("lieux")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -79,8 +79,8 @@ class ActivityTag(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Tag")
|
verbose_name = _("tag")
|
||||||
verbose_name_plural = _("Tags")
|
verbose_name_plural = _("tags")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -93,6 +93,13 @@ class ActivityTemplate(models.Model):
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
|
# FIXME: voir comment on traite l'héritage de `event`
|
||||||
|
event = models.ForeignKey(
|
||||||
|
Event,
|
||||||
|
related_name="activities",
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
)
|
||||||
is_public = models.NullBooleanField(
|
is_public = models.NullBooleanField(
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
|
@ -125,18 +132,16 @@ class ActivityTemplate(models.Model):
|
||||||
ActivityTag,
|
ActivityTag,
|
||||||
related_name="activities",
|
related_name="activities",
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
|
||||||
)
|
)
|
||||||
place = models.ManyToManyField(
|
place = models.ManyToManyField(
|
||||||
Place,
|
Place,
|
||||||
related_name="activities",
|
related_name="activities",
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("Template activité")
|
verbose_name = _("template activité")
|
||||||
verbose_name_plural = _("Templates activité")
|
verbose_name_plural = _("templates activité")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
@ -152,22 +157,40 @@ class Activity(ActivityTemplate):
|
||||||
related_name="in_perm_activities",
|
related_name="in_perm_activities",
|
||||||
blank=True,
|
blank=True,
|
||||||
)
|
)
|
||||||
# TODO : Utiliser db_constraint ou through
|
|
||||||
# equipement = models.ManyToManyField(Equipement)
|
# equipement = models.ManyToManyField(Equipement)
|
||||||
|
|
||||||
class Meta:
|
def get_herited(self, attrname):
|
||||||
verbose_name = _("Activité")
|
attr = super(Activity, self).__getattribute__(attrname)
|
||||||
verbose_name_plural = _("Activités")
|
|
||||||
|
|
||||||
# Si le champ de l'activité n'est pas spécifié
|
|
||||||
# alors on va chercher celui de self.parent
|
|
||||||
def __getattr__(self, attrname):
|
|
||||||
attr = super(Activity, self).__getattr__(attrname)
|
|
||||||
if (attrname == 'parent'
|
if (attrname == 'parent'
|
||||||
or attrname == 'staff'
|
or attrname == 'staff'
|
||||||
or attrname == 'equipement'):
|
or attrname == 'equipement'):
|
||||||
return attr
|
return attr
|
||||||
|
elif (attrname == 'place' or attrname == 'tags'):
|
||||||
|
if attr.exists():
|
||||||
|
return attr
|
||||||
|
else:
|
||||||
|
return self.parent.__getattribute__(attrname)
|
||||||
elif attr is None:
|
elif attr is None:
|
||||||
return self.parent.__getattr__(attrname)
|
return self.parent.__getattribute__(attrname)
|
||||||
else:
|
else:
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _("activité")
|
||||||
|
verbose_name_plural = _("activités")
|
||||||
|
|
||||||
|
# Si le champ de l'activité n'est pas spécifié
|
||||||
|
# alors on va chercher celui de self.parent
|
||||||
|
# def __getattribute__(self, attrname):
|
||||||
|
# attr = super(Activity, self).__getattribute__(attrname)
|
||||||
|
# if (attrname == 'parent'
|
||||||
|
# or attrname == 'staff'
|
||||||
|
# or attrname == 'equipement'):
|
||||||
|
# return attr
|
||||||
|
# elif attr is None:
|
||||||
|
# return self.parent.__getattribute__(attrname)
|
||||||
|
# else:
|
||||||
|
# return attr
|
||||||
|
|
||||||
|
# def __setattr__(self, name, value):
|
||||||
|
# self.__dict__[name] = value
|
||||||
|
|
115
event/tests.py
115
event/tests.py
|
@ -2,9 +2,11 @@ from django.contrib.auth.models import User
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from .models import Event, ActivityTemplate, Activity, Place
|
from .models import Event, ActivityTemplate, Activity, Place, \
|
||||||
|
ActivityTag
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: héritage de `event` ?
|
||||||
class ActivityInheritanceTest(TestCase):
|
class ActivityInheritanceTest(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
@ -26,25 +28,98 @@ class ActivityInheritanceTest(TestCase):
|
||||||
+ timedelta(days=31),
|
+ timedelta(days=31),
|
||||||
)
|
)
|
||||||
cls.loge = Place.objects.create(name="Loge 45")
|
cls.loge = Place.objects.create(name="Loge 45")
|
||||||
cls.permtemp = ActivityTemplate.objects.create(
|
cls.aqua = Place.objects.create(name="Aquarium")
|
||||||
title="Permanence loge",
|
cls.tag_foo = ActivityTag.objects.create(
|
||||||
# is_public non spécifié
|
name="foo",
|
||||||
has_perm=False,
|
|
||||||
description="Les perms c'est lol",
|
|
||||||
# remark non spécifié
|
|
||||||
)
|
|
||||||
cls.permtemp.place.add(cls.loge)
|
|
||||||
cls.perm = Activity.objects.create(
|
|
||||||
parent=cls.permtemp,
|
|
||||||
# title non spécifié
|
|
||||||
is_public=True,
|
is_public=True,
|
||||||
# has_perm non spécifié
|
color="#0F0F0F",
|
||||||
# description non spécifiée
|
)
|
||||||
remarks="lol",
|
cls.tag_bar = ActivityTag.objects.create(
|
||||||
|
name="bar",
|
||||||
|
is_public=True,
|
||||||
|
color="#0F0F0F",
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_event_name(self):
|
def setUp(self):
|
||||||
self.assertEqual(self.event.title, 'La Nuit 2042')
|
self.template_act = ActivityTemplate.objects.create(
|
||||||
self.assertEqual(self.loge.name, 'Loge 45')
|
# title
|
||||||
self.assertEqual(self.permtemp.title, 'Permanence loge')
|
# is_public
|
||||||
self.assertEqual(self.permtemp.place.name, 'Loge 45')
|
# has_perm
|
||||||
|
# min_perm
|
||||||
|
# max_perm
|
||||||
|
# description
|
||||||
|
# remarks
|
||||||
|
# tags
|
||||||
|
# place
|
||||||
|
)
|
||||||
|
self.real_act = Activity.objects.create(
|
||||||
|
# les mêmes plus :
|
||||||
|
parent=self.template_act,
|
||||||
|
# staff
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_inherites_title(self):
|
||||||
|
self.template_act.title = "parent"
|
||||||
|
self.assertEqual(self.real_act.get_herited('title'), "parent")
|
||||||
|
self.real_act.title = "enfant"
|
||||||
|
self.assertEqual(self.real_act.get_herited('title'), "enfant")
|
||||||
|
|
||||||
|
def test_inherites_description(self):
|
||||||
|
self.template_act.description = "parent"
|
||||||
|
self.assertEqual(self.real_act.get_herited('description'), "parent")
|
||||||
|
self.real_act.description = "enfant"
|
||||||
|
self.assertEqual(self.real_act.get_herited('description'), "enfant")
|
||||||
|
|
||||||
|
def test_inherites_remarks(self):
|
||||||
|
self.template_act.remarks = "parent"
|
||||||
|
self.assertEqual(self.real_act.get_herited('remarks'), "parent")
|
||||||
|
self.real_act.remarks = "enfant"
|
||||||
|
self.assertEqual(self.real_act.get_herited('remarks'), "enfant")
|
||||||
|
|
||||||
|
def test_inherites_is_public(self):
|
||||||
|
self.template_act.is_public = True
|
||||||
|
self.assertEqual(self.real_act.get_herited('is_public'), True)
|
||||||
|
self.real_act.is_public = False
|
||||||
|
self.assertEqual(self.real_act.get_herited('is_public'), False)
|
||||||
|
|
||||||
|
def test_inherites_has_perm(self):
|
||||||
|
self.template_act.has_perm = True
|
||||||
|
self.assertEqual(self.real_act.get_herited('has_perm'), True)
|
||||||
|
self.real_act.has_perm = False
|
||||||
|
self.assertEqual(self.real_act.get_herited('has_perm'), False)
|
||||||
|
|
||||||
|
def test_inherites_min_perm(self):
|
||||||
|
self.template_act.min_perm = 42
|
||||||
|
self.assertEqual(self.real_act.get_herited('min_perm'), 42)
|
||||||
|
self.real_act.min_perm = 1
|
||||||
|
self.assertEqual(self.real_act.get_herited('min_perm'), 1)
|
||||||
|
|
||||||
|
def test_inherites_max_perm(self):
|
||||||
|
self.template_act.max_perm = 42
|
||||||
|
self.assertEqual(self.real_act.get_herited('max_perm'), 42)
|
||||||
|
self.real_act.max_perm = 1
|
||||||
|
self.assertEqual(self.real_act.get_herited('max_perm'), 1)
|
||||||
|
|
||||||
|
def test_inherites_place(self):
|
||||||
|
self.template_act.place.add(self.loge)
|
||||||
|
self.assertEqual(
|
||||||
|
self.real_act.get_herited('place').get().name,
|
||||||
|
"Loge 45"
|
||||||
|
)
|
||||||
|
self.real_act.place.add(self.aqua)
|
||||||
|
self.assertEqual(
|
||||||
|
self.real_act.get_herited('place').get().name,
|
||||||
|
"Aquarium"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_inherites_tags(self):
|
||||||
|
self.template_act.tags.add(self.tag_foo)
|
||||||
|
self.assertEqual(
|
||||||
|
self.real_act.get_herited('tags').get().name,
|
||||||
|
"foo"
|
||||||
|
)
|
||||||
|
self.real_act.tags.add(self.tag_bar)
|
||||||
|
self.assertEqual(
|
||||||
|
self.real_act.get_herited('tags').get().name,
|
||||||
|
"bar"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue