1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# Copyright (C) 2017 Alban Gruin
#
# celcatsanitizer is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# celcatsanitizer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with celcatsanitizer; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from django.test import TestCase
from .models import Timetable, Group
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_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))
|