aboutsummaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests.py')
-rw-r--r--tests.py116
1 files changed, 115 insertions, 1 deletions
diff --git a/tests.py b/tests.py
index 42ddd65..b6b9a70 100644
--- a/tests.py
+++ b/tests.py
@@ -15,5 +15,119 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from django.test import TestCase
+from django.utils import timezone
-# Create your tests here.
+from .models import Course, Group, Timetable
+
+
+class CourseTestCase(TestCase):
+ def setUp(self):
+ dt = timezone.now()
+
+ self.timetable = Timetable(name="Test timetable 2", url="http://example.org/", slug="test-timetable2")
+ self.timetable.save()
+
+ cma = Group.objects.create(celcat_name="L1 info s2 - CMA", timetable=self.timetable)
+ tda2 = Group.objects.create(celcat_name="L1 info s2 - TDA2", timetable=self.timetable)
+ self.tpa21 = Group.objects.create(celcat_name="L1 info s2 - TPA21", timetable=self.timetable)
+
+ cmb = Group.objects.create(celcat_name="L1 info s2 - CMB", timetable=self.timetable)
+ tdb2 = Group.objects.create(celcat_name="L1 info s2 - TDB2", timetable=self.timetable)
+ self.tpb21 = Group.objects.create(celcat_name="L1 info s2 - TPB21", timetable=self.timetable)
+
+ for group in (cma, tda2, self.tpa21, cmb, tdb2, self.tpb21,):
+ course = Course.objects.create(name="{0} course".format(group.name), type="cours", timetable=self.timetable, begin=dt, end=dt)
+ course.groups.add(group)
+
+ def test_get_courses_for_group(self):
+ tpa21_courses = Course.objects.get_courses_for_group(self.tpa21)
+ tpb21_courses = Course.objects.get_courses_for_group(self.tpb21)
+
+ tpa21_course_names = ["L1 info s2 - CMA course", "L1 info s2 - TDA2 course", "L1 info s2 - TPA21 course"]
+ tpb21_course_names = ["L1 info s2 - CMB course", "L1 info s2 - TDB2 course", "L1 info s2 - TPB21 course"]
+
+ for courses, names in ((tpa21_courses, tpa21_course_names,), (tpb21_courses, tpb21_course_names,),):
+ for course in courses:
+ self.assertIn(course.name, names)
+ names.remove(course.name)
+
+
+class GroupTestCase(TestCase):
+ def setUp(self):
+ self.timetable = Timetable(name="Test timetable", url="http://example.com/", slug="test-timetable")
+ self.timetable.save()
+
+ Group.objects.create(celcat_name="L1 info s2 - CMA", timetable=self.timetable)
+ Group.objects.create(celcat_name="L1 info s2 - TDA2", timetable=self.timetable)
+ Group.objects.create(celcat_name="L1 info s2 - TPA21", timetable=self.timetable)
+
+ Group.objects.create(celcat_name="L1 info s2 - CMB", timetable=self.timetable)
+ Group.objects.create(celcat_name="L1 info s2 - TDB2", timetable=self.timetable)
+ Group.objects.create(celcat_name="L1 info s2 - TPB21", timetable=self.timetable)
+
+ def test_corresponds(self):
+ cma = Group.objects.get(celcat_name="L1 info s2 - CMA", timetable=self.timetable)
+ tda2 = Group.objects.get(celcat_name="L1 info s2 - TDA2", timetable=self.timetable)
+ tpa21 = Group.objects.get(celcat_name="L1 info s2 - TPA21", timetable=self.timetable)
+
+ cmb = Group.objects.get(celcat_name="L1 info s2 - CMB", timetable=self.timetable)
+ tdb2 = Group.objects.get(celcat_name="L1 info s2 - TDB2", timetable=self.timetable)
+ tpb21 = Group.objects.get(celcat_name="L1 info s2 - TPB21", timetable=self.timetable)
+
+ self.assertTrue(cma.corresponds_to(*tda2.group_info)) # CMA corresponds to TDA2
+ self.assertTrue(cma.corresponds_to(*tpa21.group_info)) # CMA corresponds to TPA21
+ self.assertTrue(tda2.corresponds_to(*tpa21.group_info)) # TDA2 corresponds to TPA21
+
+ self.assertTrue(cmb.corresponds_to(*tdb2.group_info)) # CMB corresponds to TDB2
+ self.assertTrue(cmb.corresponds_to(*tpb21.group_info)) # CMB corresponds to TPB21
+ self.assertTrue(tdb2.corresponds_to(*tpb21.group_info)) # TDB2 corresponds to TPB21
+
+ self.assertFalse(cmb.corresponds_to(*tda2.group_info)) # CMB does not corresponds to TDA2
+ self.assertFalse(cmb.corresponds_to(*tpa21.group_info)) # CMB does not corresponds to TPA21
+ self.assertFalse(tdb2.corresponds_to(*tpa21.group_info)) # TDB2 does not corresponds to TPA21
+
+ self.assertTrue(tda2.corresponds_to(*cma.group_info)) # TDA2 corresponds to CMA
+ self.assertTrue(tpa21.corresponds_to(*cma.group_info)) # TPA21 corresponds to CMA
+ self.assertTrue(tpa21.corresponds_to(*tda2.group_info)) # TPA21 corresponds to TDA2
+
+ self.assertTrue(tdb2.corresponds_to(*cmb.group_info)) # TDB2 corresponds to CMB
+ self.assertTrue(tpb21.corresponds_to(*cmb.group_info)) # TPB21 corresponds to CMB
+ self.assertTrue(tpb21.corresponds_to(*tdb2.group_info)) # TPB21 corresponds to TDB2
+
+ self.assertFalse(tda2.corresponds_to(*cmb.group_info)) # TDA2 does not corresponds to CMB
+ self.assertFalse(tpa21.corresponds_to(*cmb.group_info)) # TPA21 does not corresponds to CMB
+ self.assertFalse(tpa21.corresponds_to(*tdb2.group_info)) # TPA21 does not corresponds to TDB2
+
+ def test_get(self):
+ cma = Group.objects.get(name="L1 info s2 - CMA", timetable=self.timetable)
+ tda2 = Group.objects.get(name="L1 info s2 - TDA2", timetable=self.timetable)
+ tpa21 = Group.objects.get(name="L1 info s2 - TPA21", timetable=self.timetable)
+
+ cmb = Group.objects.get(name="L1 info s2 - CMB", timetable=self.timetable)
+ tdb2 = Group.objects.get(name="L1 info s2 - TDB2", timetable=self.timetable)
+ tpb21 = Group.objects.get(name="L1 info s2 - TPB21", timetable=self.timetable)
+
+ self.assertEqual(cma.celcat_name, "L1 info s2 - CMA")
+ self.assertEqual(tda2.celcat_name, "L1 info s2 - TDA2")
+ self.assertEqual(tpa21.celcat_name, "L1 info s2 - TPA21")
+
+ self.assertEqual(cmb.celcat_name, "L1 info s2 - CMB")
+ self.assertEqual(tdb2.celcat_name, "L1 info s2 - TDB2")
+ self.assertEqual(tpb21.celcat_name, "L1 info s2 - TPB21")
+
+ def test_parse(self):
+ cma = Group.objects.get(celcat_name="L1 info s2 - CMA", timetable=self.timetable)
+ tda2 = Group.objects.get(celcat_name="L1 info s2 - TDA2", timetable=self.timetable)
+ tpa21 = Group.objects.get(celcat_name="L1 info s2 - TPA21", timetable=self.timetable)
+
+ cmb = Group.objects.get(celcat_name="L1 info s2 - CMB", timetable=self.timetable)
+ tdb2 = Group.objects.get(celcat_name="L1 info s2 - TDB2", timetable=self.timetable)
+ tpb21 = Group.objects.get(celcat_name="L1 info s2 - TPB21", timetable=self.timetable)
+
+ self.assertEqual(cma.group_info, (self.timetable.id, "L1 info s2", "A", None, None))
+ self.assertEqual(tda2.group_info, (self.timetable.id, "L1 info s2", "A", 2, None))
+ self.assertEqual(tpa21.group_info, (self.timetable.id, "L1 info s2", "A", 2, 1))
+
+ self.assertEqual(cmb.group_info, (self.timetable.id, "L1 info s2", "B", None, None))
+ self.assertEqual(tdb2.group_info, (self.timetable.id, "L1 info s2", "B", 2, None))
+ self.assertEqual(tpb21.group_info, (self.timetable.id, "L1 info s2", "B", 2, 1))