From 3f03f5a058755e166ec69d992b012186434caa18 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sat, 11 Feb 2017 12:32:01 +0100 Subject: Ajout de tests unitaires pour les cours --- tests.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests.py b/tests.py index 3c58558..b6b9a70 100644 --- a/tests.py +++ b/tests.py @@ -15,7 +15,41 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from django.test import TestCase -from .models import Timetable, Group +from django.utils import timezone + +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): -- cgit v1.2.1