2016-10-02 14:19:38 +02:00
|
|
|
from django.contrib.auth.models import User
|
2016-10-17 20:06:00 +02:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django.db.utils import DataError
|
2016-09-30 20:10:35 +02:00
|
|
|
from django.test import TestCase
|
2016-10-03 00:31:21 +02:00
|
|
|
from datetime import timedelta
|
2016-10-02 14:19:38 +02:00
|
|
|
from django.utils import timezone
|
2016-10-13 11:51:41 +02:00
|
|
|
from .models import Event, ActivityTemplate, Activity, Place, \
|
|
|
|
ActivityTag
|
2016-09-30 20:10:35 +02:00
|
|
|
|
2016-10-02 14:19:38 +02:00
|
|
|
|
2016-10-13 11:51:41 +02:00
|
|
|
# TODO: héritage de `event` ?
|
2016-10-02 14:19:38 +02:00
|
|
|
class ActivityInheritanceTest(TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
cls.erkan = User.objects.create(
|
|
|
|
username='enarmanli',
|
|
|
|
email='erkan.narmanli@ens.fr',
|
|
|
|
first_name='Erkan',
|
|
|
|
last_name='Narmanli',
|
|
|
|
)
|
|
|
|
cls.event = Event.objects.create(
|
|
|
|
title='La Nuit 2042',
|
|
|
|
slug='nuit42',
|
|
|
|
created_by=cls.erkan,
|
2016-10-03 00:31:21 +02:00
|
|
|
creation_date=timezone.now(),
|
|
|
|
description="La nuit c'est lol",
|
2016-10-02 14:19:38 +02:00
|
|
|
beginning_date=timezone.now()
|
2016-10-03 00:31:21 +02:00
|
|
|
+ timedelta(days=30),
|
2016-10-02 14:19:38 +02:00
|
|
|
ending_date=timezone.now()
|
2016-10-03 00:31:21 +02:00
|
|
|
+ timedelta(days=31),
|
2016-10-02 14:19:38 +02:00
|
|
|
)
|
2016-10-03 00:31:21 +02:00
|
|
|
cls.loge = Place.objects.create(name="Loge 45")
|
2016-10-13 11:51:41 +02:00
|
|
|
cls.aqua = Place.objects.create(name="Aquarium")
|
|
|
|
cls.tag_foo = ActivityTag.objects.create(
|
|
|
|
name="foo",
|
|
|
|
is_public=True,
|
|
|
|
color="#0F0F0F",
|
2016-10-03 00:31:21 +02:00
|
|
|
)
|
2016-10-13 11:51:41 +02:00
|
|
|
cls.tag_bar = ActivityTag.objects.create(
|
|
|
|
name="bar",
|
2016-10-03 00:31:21 +02:00
|
|
|
is_public=True,
|
2016-10-13 11:51:41 +02:00
|
|
|
color="#0F0F0F",
|
|
|
|
)
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.template_act = ActivityTemplate.objects.create(
|
|
|
|
# title
|
|
|
|
# is_public
|
|
|
|
# has_perm
|
|
|
|
# min_perm
|
|
|
|
# max_perm
|
|
|
|
# description
|
|
|
|
# remarks
|
|
|
|
# tags
|
|
|
|
# place
|
2016-10-03 00:31:21 +02:00
|
|
|
)
|
2016-10-13 11:51:41 +02:00
|
|
|
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"
|
|
|
|
)
|
2016-10-03 00:31:21 +02:00
|
|
|
|
2016-10-13 11:51:41 +02:00
|
|
|
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"
|
|
|
|
)
|
2016-10-17 20:06:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ActivityTagColorTest(TestCase):
|
|
|
|
def test_positive_color_long(self):
|
|
|
|
self.tag = ActivityTag.objects.create(
|
|
|
|
name="bar",
|
|
|
|
is_public=True,
|
|
|
|
color="#0F0F0F",
|
|
|
|
)
|
|
|
|
self.tag.full_clean()
|
|
|
|
|
|
|
|
def test_positive_color_small(self):
|
|
|
|
self.tag = ActivityTag.objects.create(
|
|
|
|
name="bar",
|
|
|
|
is_public=True,
|
|
|
|
color="#0F0",
|
|
|
|
)
|
|
|
|
self.tag.full_clean()
|
|
|
|
|
|
|
|
def test_negative_color_1(self):
|
|
|
|
self.tag = ActivityTag.objects.create(
|
|
|
|
name="bar",
|
|
|
|
is_public=True,
|
|
|
|
color="#ABCDEG",
|
|
|
|
)
|
|
|
|
with self.assertRaises(ValidationError):
|
|
|
|
self.tag.full_clean()
|
|
|
|
|
|
|
|
def test_negative_color_2(self):
|
|
|
|
self.tag = ActivityTag.objects.create(
|
|
|
|
name="bar",
|
|
|
|
is_public=True,
|
|
|
|
color="#ACDE-1",
|
|
|
|
)
|
|
|
|
with self.assertRaises(ValidationError):
|
|
|
|
self.tag.full_clean()
|