From 3a5e355f92881597c22a434ea300175a624586ea Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 18 Jan 2018 13:26:37 +0100 Subject: Adaptation des tests à la nouvelle structure de la base de données --- tests.py | 86 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 40 deletions(-) (limited to 'tests.py') diff --git a/tests.py b/tests.py index 1425a84..ac6bdaf 100644 --- a/tests.py +++ b/tests.py @@ -14,7 +14,7 @@ # along with celcatsanitizer. If not, see . from django.test import TestCase -from .models import Course, Group, Timetable, Year +from .models import Course, Group, Source, Timetable, Year from .utils import tz_now @@ -25,24 +25,27 @@ class CourseTestCase(TestCase): self.year = Year(name="L2", slug="l2") self.year.save() - self.timetable = Timetable(year=self.year, name="Test timetable 2", url="http://example.org/", slug="test-timetable2") + source = Source(url="http://example.org/") + source.save() + + self.timetable = Timetable(year=self.year, name="Test timetable 2", source=source, 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) + cma = Group.objects.create(celcat_name="L1 info s2 CMA", source=source) + tda2 = Group.objects.create(celcat_name="L1 info s2 TDA2", source=source) + self.tpa21 = Group.objects.create(celcat_name="L1 info s2 TPA21", source=source) - 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) + cmb = Group.objects.create(celcat_name="L1 info s2 CMB", source=source) + tdb2 = Group.objects.create(celcat_name="L1 info s2 TDB2", source=source) + self.tpb21 = Group.objects.create(celcat_name="L1 info s2 TPB21", source=source) 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 = Course.objects.create(name="{0} course".format(group.name), type="cours", source=source, 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_courses = Course.objects.get_courses(self.tpa21) + tpb21_courses = Course.objects.get_courses(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"] @@ -58,29 +61,32 @@ class GroupTestCase(TestCase): self.year = Year(name="L1", slug="l1") self.year.save() - self.timetable = Timetable(year=self.year, name="Test timetable", url="http://example.com/", slug="test-timetable") + self.source = Source(url="http://example.org/") + self.source.save() + + self.timetable = Timetable(year=self.year, name="Test timetable", source=self.source, 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 CMA", source=self.source) + Group.objects.create(celcat_name="L1 info s2 TDA2", source=self.source) + Group.objects.create(celcat_name="L1 info s2 TPA21", source=self.source) - 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) + Group.objects.create(celcat_name="L1 info s2 CMB", source=self.source) + Group.objects.create(celcat_name="L1 info s2 TDB2", source=self.source) + Group.objects.create(celcat_name="L1 info s2 TPB21", source=self.source) - Group.objects.create(celcat_name="L1 info (toutes sections et semestres confondus)", timetable=self.timetable) + Group.objects.create(celcat_name="L1 info (toutes sections et semestres confondus)", source=self.source) 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) + cma = Group.objects.get(celcat_name="L1 info s2 CMA", source=self.source) + tda2 = Group.objects.get(celcat_name="L1 info s2 TDA2", source=self.source) + tpa21 = Group.objects.get(celcat_name="L1 info s2 TPA21", source=self.source) - 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) + cmb = Group.objects.get(celcat_name="L1 info s2 CMB", source=self.source) + tdb2 = Group.objects.get(celcat_name="L1 info s2 TDB2", source=self.source) + tpb21 = Group.objects.get(celcat_name="L1 info s2 TPB21", source=self.source) - general = Group.objects.get(celcat_name="L1 info (toutes sections et semestres confondus)", timetable=self.timetable) + general = Group.objects.get(celcat_name="L1 info (toutes sections et semestres confondus)", source=self.source) self.assertFalse(cma.corresponds_to(*tda2.group_info)) self.assertFalse(cma.corresponds_to(*tpa21.group_info)) @@ -121,15 +127,15 @@ class GroupTestCase(TestCase): self.assertTrue(tpb21.corresponds_to(*general.group_info)) 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) + cma = Group.objects.get(name="L1 info s2 CMA", source=self.source) + tda2 = Group.objects.get(name="L1 info s2 TDA2", source=self.source) + tpa21 = Group.objects.get(name="L1 info s2 TPA21", source=self.source) - 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) + cmb = Group.objects.get(name="L1 info s2 CMB", source=self.source) + tdb2 = Group.objects.get(name="L1 info s2 TDB2", source=self.source) + tpb21 = Group.objects.get(name="L1 info s2 TPB21", source=self.source) - general = Group.objects.get(celcat_name="L1 info (toutes sections et semestres confondus)", timetable=self.timetable) + general = Group.objects.get(celcat_name="L1 info (toutes sections et semestres confondus)", source=self.source) self.assertEqual(cma.celcat_name, "L1 info s2 CMA") self.assertEqual(tda2.celcat_name, "L1 info s2 TDA2") @@ -142,15 +148,15 @@ class GroupTestCase(TestCase): self.assertEqual(general.celcat_name, "L1 info (toutes sections et semestres confondus)") 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) + cma = Group.objects.get(celcat_name="L1 info s2 CMA", source=self.source) + tda2 = Group.objects.get(celcat_name="L1 info s2 TDA2", source=self.source) + tpa21 = Group.objects.get(celcat_name="L1 info s2 TPA21", source=self.source) - 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) + cmb = Group.objects.get(celcat_name="L1 info s2 CMB", source=self.source) + tdb2 = Group.objects.get(celcat_name="L1 info s2 TDB2", source=self.source) + tpb21 = Group.objects.get(celcat_name="L1 info s2 TPB21", source=self.source) - general = Group.objects.get(celcat_name="L1 info (toutes sections et semestres confondus)", timetable=self.timetable) + general = Group.objects.get(celcat_name="L1 info (toutes sections et semestres confondus)", source=self.source) self.assertEqual(cma.group_info, ("L1 info", 2, "A")) self.assertEqual(tda2.group_info, ("L1 info", 2, "A2")) -- cgit v1.2.1