diff options
-rw-r--r-- | models.py | 7 | ||||
-rw-r--r-- | tests.py | 65 |
2 files changed, 71 insertions, 1 deletions
@@ -160,7 +160,14 @@ class Group(SlugModel): verbose_name_plural = "groupes" +class RoomManager(Manager): + def qsjps(self, begin, end): + return None + + class Room(SlugModel): + objects = RoomManager() + name = models.CharField(max_length=255, unique=True, verbose_name="nom") slug = models.SlugField(max_length=64, default="", unique=True) @@ -14,9 +14,13 @@ # along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>. from django.test import TestCase -from .models import Course, Group, Source, Timetable, Year +from django.utils import timezone + +from .models import Course, Group, Room, Source, Timetable, Year from .utils import tz_now +import datetime + class CourseTestCase(TestCase): def setUp(self): @@ -200,3 +204,62 @@ class GroupTestCase(TestCase): self.assertEqual(tpb21.group_info, ("L1 info", 2, "B21")) self.assertEqual(general.group_info, ("L1 info", None, "")) + + +class RoomTestCase(TestCase): + def setUp(self): + self.day = datetime.datetime(year=2018, month=1, day=27) + + self.year = Year.objects.create(name="L1") + self.source = Source.objects.create(url="http://example.org/") + + # Pas besoin de créer plus de groupes que ça, ni de le rendre + # global + 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")] + + hours = [({"begin": datetime.time(hour=14, minute=0)},), + ({"begin": datetime.time(hour=16, minute=0)},), + ({"begin": datetime.time(hour=13, minute=30)}, + {"begin": datetime.time(hour=16, minute=0)}), + ({"begin": datetime.time(hour=14, minute=0), "duration": 4},), + ({"begin": datetime.time(hour=15, minute=30), + "duration": 1},), + ({"begin": datetime.time(hour=13, minute=0)}, + {"begin": datetime.time(hour=17, minute=0)}), + ()] + + for i, room in enumerate(self.rooms): + for rn in hours[i]: + begin = timezone.make_aware( + datetime.datetime.combine(self.day, rn["begin"])) + end = begin + datetime.timedelta(hours=rn.get("duration", 2)) + + course = Course.objects.create(source=self.source, + begin=begin, end=end) + course.groups.add(group) + course.rooms.add(room) + + def test_qsjps(self): + begin = timezone.make_aware(datetime.datetime.combine( + self.day, datetime.time(hour=15, minute=0))) + end = begin + datetime.timedelta(hours=2) + + rooms = Room.objects.qsjps(begin, end) + self.assertEqual(rooms.count(), 2) + + self.assertNotIn(self.rooms[0], rooms) + self.assertNotIn(self.rooms[1], rooms) + self.assertNotIn(self.rooms[2], rooms) + self.assertNotIn(self.rooms[3], rooms) + self.assertNotIn(self.rooms[4], rooms) + self.assertIn(self.rooms[5], rooms) + self.assertIn(self.rooms[6], rooms) |