poulpe/event/tests.py

158 lines
5.8 KiB
Python
Raw Permalink Normal View History

2017-07-18 17:18:54 +02:00
from django.contrib.auth import get_user_model
2016-10-17 20:06:00 +02:00
from django.core.exceptions import ValidationError
from django.test import TestCase
from datetime import timedelta
2016-10-02 14:19:38 +02:00
from django.utils import timezone
from .models import Event, ActivityTemplate, Activity, Place, \
ActivityTag
2017-07-18 17:18:54 +02:00
User = get_user_model()
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,
2017-07-26 13:48:12 +02:00
created_at=timezone.now(),
description="La nuit c'est lol",
2016-10-02 14:19:38 +02:00
beginning_date=timezone.now()
+ timedelta(days=30),
2016-10-02 14:19:38 +02:00
ending_date=timezone.now()
+ timedelta(days=31),
2016-10-02 14:19:38 +02:00
)
cls.loge = Place.objects.create(name="Loge 45")
cls.aqua = Place.objects.create(name="Aquarium")
cls.tag_foo = ActivityTag.objects.create(
name="foo",
is_public=True,
color="#0F0F0F",
)
cls.tag_bar = ActivityTag.objects.create(
name="bar",
is_public=True,
color="#0F0F0F",
)
def setUp(self):
self.template_act = ActivityTemplate.objects.create(event=self.event)
self.real_act = Activity.objects.create(
parent=self.template_act,
event=self.event,
2017-07-18 15:37:13 +02:00
beginning=timezone.now()
+ timedelta(days=30),
end=timezone.now()
+ timedelta(days=30)
+ timedelta(hours=2),
)
2017-07-18 15:37:13 +02:00
def test_inherits_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")
2017-07-18 15:37:13 +02:00
def test_inherits_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")
2017-07-18 15:37:13 +02:00
def test_inherits_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")
2017-07-18 15:37:13 +02:00
def test_inherits_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)
2017-07-18 15:37:13 +02:00
def test_inherits_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)
2017-07-18 15:37:13 +02:00
def test_inherits_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)
2017-07-18 15:37:13 +02:00
def test_inherits_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)
2017-07-18 15:37:13 +02:00
def test_inherits_place(self):
2017-08-03 12:14:15 +02:00
self.template_act.places.add(self.loge)
self.assertEqual(
2017-08-03 12:14:15 +02:00
self.real_act.get_herited('places').get(),
2017-02-21 17:25:46 +01:00
self.loge
)
2017-08-03 12:14:15 +02:00
self.real_act.places.add(self.aqua)
self.assertEqual(
2017-08-03 12:14:15 +02:00
self.real_act.get_herited('places').get(),
2017-02-21 17:25:46 +01:00
self.aqua
)
2017-07-18 15:37:13 +02:00
def test_inherits_tags(self):
self.template_act.tags.add(self.tag_foo)
self.assertEqual(
2017-03-05 13:25:04 +01:00
self.real_act.get_herited('tags').get(),
2017-02-21 17:25:46 +01:00
self.tag_foo
)
self.real_act.tags.add(self.tag_bar)
self.assertEqual(
2017-03-05 13:25:04 +01:00
self.real_act.get_herited('tags').get(),
2017-02-21 17:25:46 +01:00
self.tag_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()