source: main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_batching.py @ 6701

Last change on this file since 6701 was 6627, checked in by uli, 13 years ago

Add tests for batching of university-related batches.
Tests cover only pieces left out by other tests. Anyway, coverage at
100% for batching.

File size: 12.2 KB
Line 
1# Tests for university related batching
2import unittest
3
4from zope.interface.verify import verifyClass, verifyObject
5from waeup.sirp.interfaces import IBatchProcessor
6from waeup.sirp.testing import FunctionalTestCase, FunctionalLayer
7from waeup.sirp.university.batching import (
8    FacultyProcessor, DepartmentProcessor, CourseProcessor,
9    CertificateProcessor, CertificateCourseProcessor)
10from waeup.sirp.university.certificate import Certificate, CertificateCourse
11from waeup.sirp.university.course import Course
12from waeup.sirp.university.department import Department
13
14
15class TestFacultyProcessor(unittest.TestCase):
16
17    def setUp(self):
18        self.proc = FacultyProcessor()
19        self.site1 = dict(faculties=dict())
20        self.site2 = dict(faculties=dict(FAC='pseudo faculty'))
21        self.row = dict(code='FAC')
22        return
23
24    def test_ifaces(self):
25        # Make sure we fullfill all interface contracts
26        verifyClass(IBatchProcessor, FacultyProcessor)
27        verifyObject(IBatchProcessor, self.proc)
28        return
29
30    def test_get_entry(self):
31        # if a faculty exists already, we will get it
32        result1 = self.proc.getEntry(self.row, self.site1)
33        result2 = self.proc.getEntry(self.row, self.site2)
34        self.assertTrue(result1 is None)
35        self.assertEqual(result2, 'pseudo faculty')
36        return
37
38    def test_del_entry(self):
39        # make sure we can del entries.
40        self.proc.delEntry(self.row, self.site2)
41        self.assertTrue('FAC' not in self.site2.keys())
42        return
43
44class TestDepartmentProcessors(unittest.TestCase):
45
46    def setUp(self):
47        self.proc = DepartmentProcessor()
48        self.site0 = dict()
49        self.site1 = dict(faculties=dict())
50        self.site2 = dict(faculties=dict(FAC=dict()))
51        self.site3 = dict(faculties=dict(FAC=dict(DPT='pseudo department')))
52        self.row = dict(code='DPT', faculty_code='FAC')
53        return
54
55    def test_ifaces(self):
56        # Make sure we fullfill all interface contracts
57        verifyClass(IBatchProcessor, DepartmentProcessor)
58        verifyObject(IBatchProcessor, self.proc)
59        return
60
61    def test_parents_exist(self):
62        # make sure we lookup parents correctly.
63        result0 = self.proc.parentsExist(self.row, self.site0)
64        result1 = self.proc.parentsExist(self.row, self.site1)
65        result2 = self.proc.parentsExist(self.row, self.site2)
66        result3 = self.proc.parentsExist(self.row, self.site3)
67        self.assertTrue(result0 is False)
68        self.assertTrue(result1 is False)
69        self.assertTrue(result2 is True)
70        self.assertTrue(result3 is True)
71        return
72
73    def test_entry_exists(self):
74        # make sure we lookup entries correctly.
75        result0 = self.proc.entryExists(self.row, dict())
76        result1 = self.proc.entryExists(self.row, self.site1)
77        result2 = self.proc.entryExists(self.row, self.site2)
78        result3 = self.proc.entryExists(self.row, self.site3)
79        self.assertTrue(result0 is False)
80        self.assertTrue(result1 is False)
81        self.assertTrue(result2 is False)
82        self.assertTrue(result3 is True)
83        return
84
85    def test_get_entry(self):
86        # we can get a dept. if it exists
87        result1 = self.proc.getEntry(self.row, self.site2)
88        result2 = self.proc.getEntry(self.row, self.site3)
89        self.assertTrue(result1 is None)
90        self.assertEqual(result2, 'pseudo department')
91        return
92
93    def test_del_entry(self):
94        # we can delete departments
95        self.proc.delEntry(self.row, self.site3)
96        self.assertTrue('DPT' not in self.site3['faculties']['FAC'].keys())
97        return
98
99class CourseProcessorTests(FunctionalTestCase):
100
101    layer = FunctionalLayer
102
103    def setUp(self):
104        super(CourseProcessorTests, self).setUp()
105        self.proc = CourseProcessor()
106        self.site0 = dict()
107        self.site1 = dict(faculties=dict())
108        self.site2 = dict(faculties=dict(FAC=dict()))
109        self.department1 = Department(code='DPT')
110        self.department2 = Department(code='DPT')
111        self.course = Course(code='CRS')
112        self.department2.courses['CRS'] = self.course
113        self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
114        self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
115        self.row = dict(department_code='DPT', faculty_code='FAC', code="CRS")
116        return
117
118    def test_ifaces(self):
119        # Make sure we fullfill all interface contracts
120        verifyClass(IBatchProcessor, CourseProcessor)
121        verifyObject(IBatchProcessor, self.proc)
122        return
123
124    def test_parents_exist(self):
125        # make sure we lookup parents correctly
126        result0 = self.proc.parentsExist(self.row, self.site0)
127        result1 = self.proc.parentsExist(self.row, self.site1)
128        result2 = self.proc.parentsExist(self.row, self.site2)
129        result3 = self.proc.parentsExist(self.row, self.site3)
130        result4 = self.proc.parentsExist(self.row, self.site4)
131        self.assertTrue(result0 is False)
132        self.assertTrue(result1 is False)
133        self.assertTrue(result2 is False)
134        self.assertTrue(result3 is True)
135        self.assertTrue(result4 is True)
136        return
137
138    def test_entry_exists(self):
139        # make sure we find an entry if it exists
140        result0 = self.proc.entryExists(self.row, self.site0)
141        result1 = self.proc.entryExists(self.row, self.site1)
142        result2 = self.proc.entryExists(self.row, self.site2)
143        result3 = self.proc.entryExists(self.row, self.site3)
144        result4 = self.proc.entryExists(self.row, self.site4)
145        self.assertTrue(result0 is False)
146        self.assertTrue(result1 is False)
147        self.assertTrue(result2 is False)
148        self.assertTrue(result3 is False)
149        self.assertTrue(result4 is True)
150        return
151
152    def test_get_entry(self):
153        # make sure we can get an entry if it exists
154        result1 = self.proc.getEntry(self.row, self.site3)
155        result2 = self.proc.getEntry(self.row, self.site4)
156        self.assertTrue(result1 is None)
157        self.assertTrue(result2 is self.course)
158        return
159
160    def test_del_entry(self):
161        # make sure we can delete entries
162        self.assertTrue('CRS' in self.department2.courses.keys())
163        self.proc.delEntry(self.row, self.site4)
164        self.assertTrue('CRS' not in self.department2.courses.keys())
165        return
166
167class CertificateProcessorTests(FunctionalTestCase):
168
169    layer = FunctionalLayer
170
171    def setUp(self):
172        super(CertificateProcessorTests, self).setUp()
173        self.proc = CertificateProcessor()
174        self.site0 = dict()
175        self.site1 = dict(faculties=dict())
176        self.site2 = dict(faculties=dict(FAC=dict()))
177        self.department1 = Department(code='DPT')
178        self.department2 = Department(code='DPT')
179        self.certificate = Certificate(code='CRT')
180        self.department2.certificates['CRT'] = self.certificate
181        self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
182        self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
183        self.row = dict(department_code='DPT', faculty_code='FAC', code="CRT")
184        return
185
186    def test_ifaces(self):
187        # Make sure we fullfill all interface contracts
188        verifyClass(IBatchProcessor, CertificateProcessor)
189        verifyObject(IBatchProcessor, self.proc)
190        return
191
192    def test_parents_exist(self):
193        # make sure we can find all certificate parents
194        result0 = self.proc.parentsExist(self.row, self.site0)
195        result1 = self.proc.parentsExist(self.row, self.site1)
196        result2 = self.proc.parentsExist(self.row, self.site2)
197        result3 = self.proc.parentsExist(self.row, self.site3)
198        result4 = self.proc.parentsExist(self.row, self.site4)
199        self.assertTrue(result0 is False)
200        self.assertTrue(result1 is False)
201        self.assertTrue(result2 is False)
202        self.assertTrue(result3 is True)
203        self.assertTrue(result4 is True)
204        return
205
206    def test_entry_exists(self):
207        # make sure we find an entry if it exists
208        result0 = self.proc.entryExists(self.row, self.site0)
209        result1 = self.proc.entryExists(self.row, self.site1)
210        result2 = self.proc.entryExists(self.row, self.site2)
211        result3 = self.proc.entryExists(self.row, self.site3)
212        result4 = self.proc.entryExists(self.row, self.site4)
213        self.assertTrue(result0 is False)
214        self.assertTrue(result1 is False)
215        self.assertTrue(result2 is False)
216        self.assertTrue(result3 is False)
217        self.assertTrue(result4 is True)
218        return
219
220    def test_get_entry(self):
221        # make sure we can get an entry if it exists
222        result1 = self.proc.getEntry(self.row, self.site3)
223        result2 = self.proc.getEntry(self.row, self.site4)
224        self.assertTrue(result1 is None)
225        self.assertTrue(result2 is self.certificate)
226        return
227
228    def test_del_entry(self):
229        # make sure we can delete entries
230        self.assertTrue('CRT' in self.department2.certificates.keys())
231        self.proc.delEntry(self.row, self.site4)
232        self.assertTrue('CRT' not in self.department2.certificates.keys())
233        return
234
235class CertCourseProcessorTests(FunctionalTestCase):
236
237    layer = FunctionalLayer
238
239    def setUp(self):
240        super(CertCourseProcessorTests, self).setUp()
241        self.proc = CertificateCourseProcessor()
242        self.site0 = dict()
243        self.site1 = dict(faculties=dict())
244        self.site2 = dict(faculties=dict(FAC=dict()))
245        self.department1 = Department(code='DPT')
246        self.department2 = Department(code='DPT')
247        self.certificate = Certificate(code='CRT')
248        self.department2.certificates['CRT'] = self.certificate
249        self.course = Course(code='CRS')
250        self.department2.certificates['CRT'].addCourseRef(self.course)
251        self.cert_course = self.certificate['CRS_100']
252        self.department2.courses['CRS'] = self.course
253        self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
254        self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
255        self.row = dict(
256            department_code='DPT',
257            faculty_code='FAC',
258            certificate_code='CRT',
259            course=self.course, level='100',
260            code='CRS_100')
261        return
262
263    def test_ifaces(self):
264        # Make sure we fullfill all interface contracts
265        verifyClass(IBatchProcessor, CertificateCourseProcessor)
266        verifyObject(IBatchProcessor, self.proc)
267        return
268
269    def test_parents_exist(self):
270        # make sure we can find all certificate parents
271        result0 = self.proc.parentsExist(self.row, self.site0)
272        result1 = self.proc.parentsExist(self.row, self.site1)
273        result2 = self.proc.parentsExist(self.row, self.site2)
274        result3 = self.proc.parentsExist(self.row, self.site3)
275        result4 = self.proc.parentsExist(self.row, self.site4)
276        self.assertTrue(result0 is False)
277        self.assertTrue(result1 is False)
278        self.assertTrue(result2 is False)
279        self.assertTrue(result3 is False)
280        self.assertTrue(result4 is True)
281        return
282
283    def test_entry_exists(self):
284        # make sure we find an entry if it exists
285        result0 = self.proc.entryExists(self.row, self.site0)
286        result1 = self.proc.entryExists(self.row, self.site1)
287        result2 = self.proc.entryExists(self.row, self.site2)
288        result3 = self.proc.entryExists(self.row, self.site3)
289        result4 = self.proc.entryExists(self.row, self.site4)
290        self.assertTrue(result0 is False)
291        self.assertTrue(result1 is False)
292        self.assertTrue(result2 is False)
293        self.assertTrue(result3 is False)
294        self.assertTrue(result4 is True)
295        return
296
297    def test_get_entry(self):
298        # make sure we can get an entry if it exists
299        result1 = self.proc.getEntry(self.row, self.site3)
300        result2 = self.proc.getEntry(self.row, self.site4)
301        self.assertTrue(result1 is None)
302        self.assertTrue(result2 is self.cert_course)
303        return
304
305    def test_del_entry(self):
306        # make sure we can delete entries
307        self.assertTrue('CRS_100' in self.certificate.keys())
308        self.proc.delEntry(self.row, self.site4)
309        self.assertTrue('CRS_100' not in self.certificate.keys())
310        return
Note: See TracBrowser for help on using the repository browser.