source: main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py @ 8975

Last change on this file since 8975 was 8920, checked in by Henrik Bettermann, 12 years ago

Rename course referrers to certificate courses (according to the discussion long time ago).

Edit some button labels and titles.

Move code from view to content components.

  • Property svn:keywords set to Id
File size: 12.9 KB
Line 
1## $Id: test_batching.py 8920 2012-07-05 14:48:51Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18
19# Tests for university related batching
20import unittest
21
22from zope.interface.verify import verifyClass, verifyObject
23from waeup.kofa.interfaces import IBatchProcessor
24from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer
25from waeup.kofa.university.batching import (
26    FacultyProcessor, DepartmentProcessor, CourseProcessor,
27    CertificateProcessor, CertificateCourseProcessor)
28from waeup.kofa.university.certificate import Certificate, CertificateCourse
29from waeup.kofa.university.course import Course
30from waeup.kofa.university.department import Department
31
32
33class TestFacultyProcessor(unittest.TestCase):
34
35    def setUp(self):
36        self.proc = FacultyProcessor()
37        self.site1 = dict(faculties=dict())
38        self.site2 = dict(faculties=dict(FAC='pseudo faculty'))
39        self.row = dict(code='FAC')
40        return
41
42    def test_ifaces(self):
43        # Make sure we fullfill all interface contracts
44        verifyClass(IBatchProcessor, FacultyProcessor)
45        verifyObject(IBatchProcessor, self.proc)
46        return
47
48    def test_get_entry(self):
49        # if a faculty exists already, we will get it
50        result1 = self.proc.getEntry(self.row, self.site1)
51        result2 = self.proc.getEntry(self.row, self.site2)
52        self.assertTrue(result1 is None)
53        self.assertEqual(result2, 'pseudo faculty')
54        return
55
56    def test_del_entry(self):
57        # make sure we can del entries.
58        self.proc.delEntry(self.row, self.site2)
59        self.assertTrue('FAC' not in self.site2.keys())
60        return
61
62class TestDepartmentProcessors(unittest.TestCase):
63
64    def setUp(self):
65        self.proc = DepartmentProcessor()
66        self.site0 = dict()
67        self.site1 = dict(faculties=dict())
68        self.site2 = dict(faculties=dict(FAC=dict()))
69        self.site3 = dict(faculties=dict(FAC=dict(DPT='pseudo department')))
70        self.row = dict(code='DPT', faculty_code='FAC')
71        return
72
73    def test_ifaces(self):
74        # Make sure we fullfill all interface contracts
75        verifyClass(IBatchProcessor, DepartmentProcessor)
76        verifyObject(IBatchProcessor, self.proc)
77        return
78
79    def test_parents_exist(self):
80        # make sure we lookup parents correctly.
81        result0 = self.proc.parentsExist(self.row, self.site0)
82        result1 = self.proc.parentsExist(self.row, self.site1)
83        result2 = self.proc.parentsExist(self.row, self.site2)
84        result3 = self.proc.parentsExist(self.row, self.site3)
85        self.assertTrue(result0 is False)
86        self.assertTrue(result1 is False)
87        self.assertTrue(result2 is True)
88        self.assertTrue(result3 is True)
89        return
90
91    def test_entry_exists(self):
92        # make sure we lookup entries correctly.
93        result0 = self.proc.entryExists(self.row, dict())
94        result1 = self.proc.entryExists(self.row, self.site1)
95        result2 = self.proc.entryExists(self.row, self.site2)
96        result3 = self.proc.entryExists(self.row, self.site3)
97        self.assertTrue(result0 is False)
98        self.assertTrue(result1 is False)
99        self.assertTrue(result2 is False)
100        self.assertTrue(result3 is True)
101        return
102
103    def test_get_entry(self):
104        # we can get a dept. if it exists
105        result1 = self.proc.getEntry(self.row, self.site2)
106        result2 = self.proc.getEntry(self.row, self.site3)
107        self.assertTrue(result1 is None)
108        self.assertEqual(result2, 'pseudo department')
109        return
110
111    def test_del_entry(self):
112        # we can delete departments
113        self.proc.delEntry(self.row, self.site3)
114        self.assertTrue('DPT' not in self.site3['faculties']['FAC'].keys())
115        return
116
117class CourseProcessorTests(FunctionalTestCase):
118
119    layer = FunctionalLayer
120
121    def setUp(self):
122        super(CourseProcessorTests, self).setUp()
123        self.proc = CourseProcessor()
124        self.site0 = dict()
125        self.site1 = dict(faculties=dict())
126        self.site2 = dict(faculties=dict(FAC=dict()))
127        self.department1 = Department(code='DPT')
128        self.department2 = Department(code='DPT')
129        self.course = Course(code='CRS')
130        self.department2.courses['CRS'] = self.course
131        self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
132        self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
133        self.row = dict(department_code='DPT', faculty_code='FAC', code="CRS")
134        return
135
136    def test_ifaces(self):
137        # Make sure we fullfill all interface contracts
138        verifyClass(IBatchProcessor, CourseProcessor)
139        verifyObject(IBatchProcessor, self.proc)
140        return
141
142    def test_parents_exist(self):
143        # make sure we lookup parents correctly
144        result0 = self.proc.parentsExist(self.row, self.site0)
145        result1 = self.proc.parentsExist(self.row, self.site1)
146        result2 = self.proc.parentsExist(self.row, self.site2)
147        result3 = self.proc.parentsExist(self.row, self.site3)
148        result4 = self.proc.parentsExist(self.row, self.site4)
149        self.assertTrue(result0 is False)
150        self.assertTrue(result1 is False)
151        self.assertTrue(result2 is False)
152        self.assertTrue(result3 is True)
153        self.assertTrue(result4 is True)
154        return
155
156    def test_entry_exists(self):
157        # make sure we find an entry if it exists
158        result0 = self.proc.entryExists(self.row, self.site0)
159        result1 = self.proc.entryExists(self.row, self.site1)
160        result2 = self.proc.entryExists(self.row, self.site2)
161        result3 = self.proc.entryExists(self.row, self.site3)
162        result4 = self.proc.entryExists(self.row, self.site4)
163        self.assertTrue(result0 is False)
164        self.assertTrue(result1 is False)
165        self.assertTrue(result2 is False)
166        self.assertTrue(result3 is False)
167        self.assertTrue(result4 is True)
168        return
169
170    def test_get_entry(self):
171        # make sure we can get an entry if it exists
172        result1 = self.proc.getEntry(self.row, self.site3)
173        result2 = self.proc.getEntry(self.row, self.site4)
174        self.assertTrue(result1 is None)
175        self.assertTrue(result2 is self.course)
176        return
177
178    def test_del_entry(self):
179        # make sure we can delete entries
180        self.assertTrue('CRS' in self.department2.courses.keys())
181        self.proc.delEntry(self.row, self.site4)
182        self.assertTrue('CRS' not in self.department2.courses.keys())
183        return
184
185class CertificateProcessorTests(FunctionalTestCase):
186
187    layer = FunctionalLayer
188
189    def setUp(self):
190        super(CertificateProcessorTests, self).setUp()
191        self.proc = CertificateProcessor()
192        self.site0 = dict()
193        self.site1 = dict(faculties=dict())
194        self.site2 = dict(faculties=dict(FAC=dict()))
195        self.department1 = Department(code='DPT')
196        self.department2 = Department(code='DPT')
197        self.certificate = Certificate(code='CRT')
198        self.department2.certificates['CRT'] = self.certificate
199        self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
200        self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
201        self.row = dict(department_code='DPT', faculty_code='FAC', code="CRT")
202        return
203
204    def test_ifaces(self):
205        # Make sure we fullfill all interface contracts
206        verifyClass(IBatchProcessor, CertificateProcessor)
207        verifyObject(IBatchProcessor, self.proc)
208        return
209
210    def test_parents_exist(self):
211        # make sure we can find all certificate parents
212        result0 = self.proc.parentsExist(self.row, self.site0)
213        result1 = self.proc.parentsExist(self.row, self.site1)
214        result2 = self.proc.parentsExist(self.row, self.site2)
215        result3 = self.proc.parentsExist(self.row, self.site3)
216        result4 = self.proc.parentsExist(self.row, self.site4)
217        self.assertTrue(result0 is False)
218        self.assertTrue(result1 is False)
219        self.assertTrue(result2 is False)
220        self.assertTrue(result3 is True)
221        self.assertTrue(result4 is True)
222        return
223
224    def test_entry_exists(self):
225        # make sure we find an entry if it exists
226        result0 = self.proc.entryExists(self.row, self.site0)
227        result1 = self.proc.entryExists(self.row, self.site1)
228        result2 = self.proc.entryExists(self.row, self.site2)
229        result3 = self.proc.entryExists(self.row, self.site3)
230        result4 = self.proc.entryExists(self.row, self.site4)
231        self.assertTrue(result0 is False)
232        self.assertTrue(result1 is False)
233        self.assertTrue(result2 is False)
234        self.assertTrue(result3 is False)
235        self.assertTrue(result4 is True)
236        return
237
238    def test_get_entry(self):
239        # make sure we can get an entry if it exists
240        result1 = self.proc.getEntry(self.row, self.site3)
241        result2 = self.proc.getEntry(self.row, self.site4)
242        self.assertTrue(result1 is None)
243        self.assertTrue(result2 is self.certificate)
244        return
245
246    def test_del_entry(self):
247        # make sure we can delete entries
248        self.assertTrue('CRT' in self.department2.certificates.keys())
249        self.proc.delEntry(self.row, self.site4)
250        self.assertTrue('CRT' not in self.department2.certificates.keys())
251        return
252
253class CertCourseProcessorTests(FunctionalTestCase):
254
255    layer = FunctionalLayer
256
257    def setUp(self):
258        super(CertCourseProcessorTests, self).setUp()
259        self.proc = CertificateCourseProcessor()
260        self.site0 = dict()
261        self.site1 = dict(faculties=dict())
262        self.site2 = dict(faculties=dict(FAC=dict()))
263        self.department1 = Department(code='DPT')
264        self.department2 = Department(code='DPT')
265        self.certificate = Certificate(code='CRT')
266        self.department2.certificates['CRT'] = self.certificate
267        self.course = Course(code='CRS')
268        self.department2.certificates['CRT'].addCertCourse(self.course)
269        self.cert_course = self.certificate['CRS_100']
270        self.department2.courses['CRS'] = self.course
271        self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
272        self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
273        self.row = dict(
274            department_code='DPT',
275            faculty_code='FAC',
276            certificate_code='CRT',
277            course=self.course, level='100',
278            code='CRS_100')
279        return
280
281    def test_ifaces(self):
282        # Make sure we fullfill all interface contracts
283        verifyClass(IBatchProcessor, CertificateCourseProcessor)
284        verifyObject(IBatchProcessor, self.proc)
285        return
286
287    def test_parents_exist(self):
288        # make sure we can find all certificate parents
289        result0 = self.proc.parentsExist(self.row, self.site0)
290        result1 = self.proc.parentsExist(self.row, self.site1)
291        result2 = self.proc.parentsExist(self.row, self.site2)
292        result3 = self.proc.parentsExist(self.row, self.site3)
293        result4 = self.proc.parentsExist(self.row, self.site4)
294        self.assertTrue(result0 is False)
295        self.assertTrue(result1 is False)
296        self.assertTrue(result2 is False)
297        self.assertTrue(result3 is False)
298        self.assertTrue(result4 is True)
299        return
300
301    def test_entry_exists(self):
302        # make sure we find an entry if it exists
303        result0 = self.proc.entryExists(self.row, self.site0)
304        result1 = self.proc.entryExists(self.row, self.site1)
305        result2 = self.proc.entryExists(self.row, self.site2)
306        result3 = self.proc.entryExists(self.row, self.site3)
307        result4 = self.proc.entryExists(self.row, self.site4)
308        self.assertTrue(result0 is False)
309        self.assertTrue(result1 is False)
310        self.assertTrue(result2 is False)
311        self.assertTrue(result3 is False)
312        self.assertTrue(result4 is True)
313        return
314
315    def test_get_entry(self):
316        # make sure we can get an entry if it exists
317        result1 = self.proc.getEntry(self.row, self.site3)
318        result2 = self.proc.getEntry(self.row, self.site4)
319        self.assertTrue(result1 is None)
320        self.assertTrue(result2 is self.cert_course)
321        return
322
323    def test_del_entry(self):
324        # make sure we can delete entries
325        self.assertTrue('CRS_100' in self.certificate.keys())
326        self.proc.delEntry(self.row, self.site4)
327        self.assertTrue('CRS_100' not in self.certificate.keys())
328        return
Note: See TracBrowser for help on using the repository browser.