From aba3214efa86d3631bd74b81be56b60e92de265f Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 20 Sep 2018 23:57:21 +0200 Subject: tests: test du tag format_rooms Signed-off-by: Alban Gruin --- tests.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'tests.py') diff --git a/tests.py b/tests.py index 2568688..fe29232 100644 --- a/tests.py +++ b/tests.py @@ -17,6 +17,7 @@ from django.test import TestCase from django.utils import timezone from .models import Course, Group, Room, Source, Timetable, Year +from .templatetags.rooms import format_rooms from .utils import tz_now import datetime @@ -300,13 +301,13 @@ class RoomTestCase(TestCase): group = Group.objects.create(celcat_name="L1 info s2 CMA", source=self.source) - self.rooms = [Room.objects.create(name="0"), - Room.objects.create(name="1"), - Room.objects.create(name="2"), - Room.objects.create(name="3"), - Room.objects.create(name="4"), - Room.objects.create(name="5"), - Room.objects.create(name="6")] + self.rooms = [ + Room.objects.create(name=str(i)) + for i in range(5) + ] + [ + Room.objects.create(name="Amphi {}".format(i)) + for i in range(5, 7) + ] hours = [({"begin": datetime.time(hour=14, minute=0)},), ({"begin": datetime.time(hour=16, minute=0)},), @@ -330,6 +331,23 @@ class RoomTestCase(TestCase): course.groups.add(group) course.rooms.add(room) + def test_format(self): + amphis = self.rooms[-2:] + + self.assertEqual(format_rooms([]), "") + self.assertEqual(format_rooms(self.rooms[:1]), "Salle 0") + self.assertEqual(format_rooms(self.rooms[:2]), "Salles 0, 1") + self.assertEqual(format_rooms([amphis[0]]), "Amphi 5") + self.assertEqual(format_rooms(amphis), "Amphi 5, Amphi 6") + self.assertEqual(format_rooms([amphis[0]] + self.rooms[:1]), + "Amphi 5, salle 0") + self.assertEqual(format_rooms([amphis[0]] + self.rooms[:2]), + "Amphi 5, salles 0, 1") + self.assertEqual(format_rooms(amphis + self.rooms[:1]), + "Amphi 5, Amphi 6, salle 0") + self.assertEqual(format_rooms(amphis + self.rooms[:2]), + "Amphi 5, Amphi 6, salles 0, 1") + def test_qsjps(self): begin = timezone.make_aware(datetime.datetime.combine( self.day, datetime.time(hour=15, minute=0))) -- cgit v1.2.1