poulpe/event/tests.py

150 lines
5.5 KiB
Python
Raw Normal View History

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.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
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,
creation_date=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):
2016-10-21 18:49:46 +02:00
self.template_act = ActivityTemplate.objects.create()
self.real_act = Activity.objects.create(
parent=self.template_act,
)
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,
2017-02-21 17:25:46 +01:00
self.loge
)
self.real_act.place.add(self.aqua)
self.assertEqual(
self.real_act.get_herited('place').get().name,
2017-02-21 17:25:46 +01:00
self.aqua
)
def test_inherites_tags(self):
self.template_act.tags.add(self.tag_foo)
self.assertEqual(
self.real_act.get_herited('tags').get().name,
2017-02-21 17:25:46 +01:00
self.tag_foo
)
self.real_act.tags.add(self.tag_bar)
self.assertEqual(
self.real_act.get_herited('tags').get().name,
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()