aboutsummaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorAlban Gruin2019-06-09 18:21:51 +0200
committerAlban Gruin2019-06-09 18:21:51 +0200
commitdab185062a58b73c9770a5d474ff3c5cd5ebcebf (patch)
treed6671696feeff23f270e8c67765f4e791f7c5e02 /tests.py
parent2386b8d41d88c1408411b378ce5e2a8c09c382e7 (diff)
parentb9f77648d0fb6897fad180627401c6b9c3e75943 (diff)
Merge branch 'ag/parser' into futur
Diffstat (limited to 'tests.py')
-rw-r--r--tests.py75
1 files changed, 56 insertions, 19 deletions
diff --git a/tests.py b/tests.py
index 627602c..b411db3 100644
--- a/tests.py
+++ b/tests.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017-2018 Alban Gruin
+# Copyright (C) 2017-2019 Alban Gruin
#
# celcatsanitizer is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
@@ -20,7 +20,7 @@ from django.utils import timezone
from .management.parsers.abstractparser import ParserError
from .management.parsers.ups2018 import Parser as UPS2018Parser
-from .models import Course, Group, Room, Source, Timetable, Year
+from .models import Course, Group, Module, Room, Source, Timetable, Year
from .templatetags.rooms import format_rooms
from .utils import tz_now
@@ -84,7 +84,7 @@ class CourseTestCase(TestCase):
for group in (cma, tda2, self.tpa21, cmb, tdb2, self.tpb21,):
course = Course.objects.create(
name="{0} course".format(group.name), type="cours",
- source=source, begin=dt, end=dt)
+ source=source, begin=dt, end=dt, celcat_id=0)
course.groups.add(group)
def test_get_courses_for_group(self):
@@ -359,7 +359,8 @@ class RoomTestCase(TestCase):
end = begin + datetime.timedelta(hours=rn.get("duration", 2))
course = Course.objects.create(source=self.source,
- begin=begin, end=end)
+ begin=begin, end=end,
+ celcat_id=0)
course.groups.add(group)
course.rooms.add(room)
@@ -413,12 +414,14 @@ class UPS2018ParserTestCase(TestCase):
def test_get_event(self):
get_event = self.parser._Parser__get_event
count = Course.objects.count()
+ module_count = Module.objects.count()
event = get_event(
{"start": "2018-09-21T10:00:00", "end": "2018-09-21T12:00:00",
"text": "(10:00-12:00)<br>COURS/TD<br>Cours quelconque;AAA"
"<br>L3 Info s1 CMA;L3 Info s1 TDA2<br>"
- "Salle quelconque;Salle quelconque 2<br>Commentaire"},
+ "Salle quelconque;Salle quelconque 2<br>Commentaire", "id": "0",
+ "tag": ["abc", "def", "AAA"]},
timezone.make_aware(datetime.datetime(2018, 9, 21)),
timezone.make_aware(datetime.datetime(2018, 9, 1)),
timezone.make_aware(datetime.datetime(2018, 10, 1)),
@@ -436,13 +439,18 @@ class UPS2018ParserTestCase(TestCase):
self.assertIn(self.room2, event.rooms.all())
self.assertEqual(event.rooms.count(), 2)
self.assertEqual(event.notes, "Commentaire")
+ self.assertEqual(event.celcat_id, 0)
self.assertEqual(event.begin, timezone.make_aware(
datetime.datetime(2018, 9, 21, 10, 0, 0)))
self.assertEqual(event.end, timezone.make_aware(
datetime.datetime(2018, 9, 21, 12, 0, 0)))
+ self.assertEqual(event.module.name, "AAA")
- self.assertEqual(count, Course.objects.count() - 1)
count += 1
+ module_count += 1
+
+ self.assertEqual(count, Course.objects.count())
+ self.assertEqual(module_count, Module.objects.count())
events = [
{
@@ -451,6 +459,9 @@ class UPS2018ParserTestCase(TestCase):
"name": "Cours quelconque", "type": "COURS/TD",
"group": self.group,
"room": self.room,
+ "id": "1",
+ "tag": ["aaa", "Cours"],
+ "meta": 1
},
{
"text": "(10:00-12:00)<br>COURS/TD<br>Cours quelconque"
@@ -458,7 +469,8 @@ class UPS2018ParserTestCase(TestCase):
"name": "Cours quelconque",
"type": "COURS/TD",
"group": ngroup,
- "notes": "Salle quelconque 3"
+ "notes": "Salle quelconque 3",
+ "id": "2"
},
{
"text": "(10:00-12:00)<br>COURS/TD<br>Cours quelconque"
@@ -467,44 +479,50 @@ class UPS2018ParserTestCase(TestCase):
"type": "COURS/TD",
"group": self.group,
"notes": "Salle quelconque 3\nCommentaire",
+ "id": "3"
},
{
"text": "(10:00-12:00)<br>COURS/TD"
"<br>L3 Info s1 CMA<br>Salle quelconque 3",
"name": "COURS/TD",
"group": self.group,
- "notes": "Salle quelconque 3"
+ "notes": "Salle quelconque 3",
+ "id": "4"
},
{
"text": "COURS/TD<br>L3 Info s1 CMA<br>Salle quelconque 3",
"name": "COURS/TD",
"group": self.group,
- "notes": "Salle quelconque 3"
+ "notes": "Salle quelconque 3",
+ "id": "5"
},
{
"text": "L3 Info s1 CMA<br>Salle quelconque",
"name": "Sans nom",
"group": self.group,
- "room": self.room
+ "room": self.room,
+ "id": "6"
},
{
"text": "L3 Info s1 CMA<br>Salle quelconque 3",
"name": "Sans nom",
"group": self.group,
- "notes": "Salle quelconque 3"
+ "notes": "Salle quelconque 3",
+ "id": "7"
},
{
"text": "(10:00-12:00)<br>L3 Info s1 CMA<br>Salle quelconque",
"name": "Sans nom",
"group": self.group,
- "room": self.room
+ "room": self.room,
+ "id": "8"
}
]
for e in events:
event = get_event(
{"start": "2018-09-21T10:00:00", "end": "2018-09-21T12:00:00",
- "text": e["text"]},
+ "text": e["text"], "id": e["id"], "tag": e.get("tag", [])},
timezone.make_aware(datetime.datetime(2018, 9, 21)),
timezone.make_aware(datetime.datetime(2018, 9, 1)),
timezone.make_aware(datetime.datetime(2018, 10, 1)),
@@ -513,6 +531,7 @@ class UPS2018ParserTestCase(TestCase):
self.assertEqual(event.name, e["name"])
self.assertIn(e["group"], event.groups.all())
self.assertEqual(event.groups.count(), 1)
+ self.assertEqual(str(event.celcat_id), e["id"])
if "type" in e:
self.assertEqual(event.type, e["type"])
@@ -530,9 +549,17 @@ class UPS2018ParserTestCase(TestCase):
else:
self.assertIsNone(event.notes)
- self.assertEqual(count, Course.objects.count() - 1)
+ if "tag" in e:
+ self.assertEqual(event.module.name, e["tag"][e["meta"]])
+ module_count += 1
+ else:
+ self.assertIsNone(event.module)
+
count += 1
+ self.assertEqual(count, Course.objects.count())
+ self.assertEqual(module_count, Module.objects.count())
+
event = get_event(
{"start": "2018-09-21T10:00:00", "end": "2018-09-21T12:00:00",
"text": "Global Event"},
@@ -560,11 +587,13 @@ class UPS2018ParserTestCase(TestCase):
{"begin":
timezone.make_aware(datetime.datetime(2018, 9, 21, 10, 00, 00)),
"end":
- timezone.make_aware(datetime.datetime(2018, 9, 21, 12, 00, 00))},
+ timezone.make_aware(datetime.datetime(2018, 9, 21, 12, 00, 00)),
+ "id": 0},
{"begin":
timezone.make_aware(datetime.datetime(2018, 10, 22, 10, 00, 00)),
"end":
- timezone.make_aware(datetime.datetime(2018, 10, 22, 12, 00, 00))}
+ timezone.make_aware(datetime.datetime(2018, 10, 22, 12, 00, 00)),
+ "id": 2}
]
for i, course in enumerate(self.parser.get_events(
@@ -578,6 +607,8 @@ class UPS2018ParserTestCase(TestCase):
self.assertIsNone(course.notes)
self.assertEqual(course.begin, courses[i]["begin"])
self.assertEqual(course.end, courses[i]["end"])
+ self.assertEqual(course.celcat_id, courses[i]["id"])
+ self.assertEqual(course.module, None)
self.assertEqual(i, len(courses) - 1)
@@ -588,15 +619,21 @@ class UPS2018ParserTestCase(TestCase):
[{
"start": "2018-09-21T10:00:00", "end": "2018-09-21T12:00:00",
"text": "(10:00-12:00)<br>COURS/TD<br>Cours quelconque"
- "<br>L3 Info s1 CMA<br>Salle quelconque"
+ "<br>L3 Info s1 CMA<br>Salle quelconque",
+ "id": "0",
+ "tag": [],
}], [{
"start": "2018-09-21T10:00:00", "end": "2018-09-21T12:00:00",
"text": "(10:00-12:00)<br>COURS/TD<br>Cours quelconque"
- "<br>L3 Info s1 CMA<br>Salle quelconque"
+ "<br>L3 Info s1 CMA<br>Salle quelconque",
+ "id": "1",
+ "tag": [],
}, {
"start": "2018-10-22T10:00:00", "end": "2018-10-22T12:00:00",
"text": "(10:00-12:00)<br>COURS/TD<br>Cours quelconque"
- "<br>L3 Info s1 CMA<br>Salle quelconque"
+ "<br>L3 Info s1 CMA<br>Salle quelconque",
+ "id": "2",
+ "tag": [],
}], [], [], [], [], [], [], [], [], []])
def test_get_update_date(self):