diff options
author | Alban Gruin | 2017-02-11 12:32:01 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-11 12:32:01 +0100 |
commit | 3f03f5a058755e166ec69d992b012186434caa18 (patch) | |
tree | d6e74c2505e769e45bf0fa3ddb1ba85cd3d6c06b | |
parent | 30dc5ad8b5ae12ef9e7ea1fbb69e2b356dcc97da (diff) |
Ajout de tests unitaires pour les cours
-rw-r--r-- | tests.py | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -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): |