Index: /main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py	(revision 8996)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py	(revision 8997)
@@ -23,4 +23,5 @@
 import os
 from zope.component.hooks import setSite, clearSite
+from zope.component import createObject
 from zope.securitypolicy.interfaces import IPrincipalRoleMap
 from zope.interface.verify import verifyClass, verifyObject
@@ -33,5 +34,5 @@
 from waeup.kofa.university.certificate import Certificate, CertificateCourse
 from waeup.kofa.university.course import Course
-from waeup.kofa.university.department import Department
+from waeup.kofa.university import Faculty, Department
 from waeup.kofa.university.batching import FacultyProcessor
 
@@ -43,10 +44,10 @@
     '\n')[0].split(',')
 
-class TestFacultyProcessor(FunctionalTestCase):
+class UniversityProcessorSetup(FunctionalTestCase):
 
     layer = FunctionalLayer
 
     def setUp(self):
-        super(TestFacultyProcessor, self).setUp()
+        super(UniversityProcessorSetup, self).setUp()
         self.dc_root = tempfile.mkdtemp()
         self.workdir = tempfile.mkdtemp()
@@ -58,4 +59,31 @@
         self.app['users'].addUser('bob', 'bobssecret')
 
+        # Populate university
+        self.certificate = createObject('waeup.Certificate')
+        self.certificate.code = 'CERT1'
+        self.app['faculties']['FAC1'] = Faculty(code='FAC1')
+        self.app['faculties']['FAC1']['DEP1'] = Department(code='DEP1')
+        self.app['faculties']['FAC1']['DEP1'].certificates.addCertificate(
+            self.certificate)
+        self.course = createObject('waeup.Course')
+        self.course.code = 'CRS1'
+        self.app['faculties']['FAC1']['DEP1'].courses.addCourse(
+            self.course)
+        #self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
+        #    self.course, level=100)
+        return
+
+    def tearDown(self):
+        super(UniversityProcessorSetup, self).tearDown()
+        shutil.rmtree(self.workdir)
+        shutil.rmtree(self.dc_root)
+        clearSite()
+        return
+
+class TestFacultyProcessor(UniversityProcessorSetup):
+
+    def setUp(self):
+        super(TestFacultyProcessor, self).setUp()
+
         self.proc = FacultyProcessor()
         self.site1 = dict(faculties=dict())
@@ -63,14 +91,6 @@
         self.row = dict(code='FAC')
 
-        self.processor = FacultyProcessor()
         self.csv_file_faculty = os.path.join(self.workdir, 'sample_faculty_data.csv')
         open(self.csv_file_faculty, 'wb').write(FACULTY_SAMPLE_DATA)
-        return
-
-    def tearDown(self):
-        super(TestFacultyProcessor, self).tearDown()
-        shutil.rmtree(self.workdir)
-        shutil.rmtree(self.dc_root)
-        clearSite()
         return
 
@@ -97,9 +117,9 @@
     def test_checkConversion(self):
         # Make sure we can check conversions.
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC', local_roles='[]'))
         self.assertEqual(len(errs),0)
 
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC',
             local_roles="['nonsense'"
@@ -107,5 +127,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'Error')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC',
             local_roles="('abc')"
@@ -113,5 +133,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'no list')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC',
             local_roles="[('ABC')]"
@@ -119,5 +139,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'no dicts')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC',
             local_roles="('abc')"
@@ -125,5 +145,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'no list')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC', local_roles=
             "[{'name':'bob','local_role':'waeup.local.DepartmentManager'},]"
@@ -131,5 +151,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC', local_roles=
             "[{'user_name':'bob','localrole':'waeup.local.DepartmentManager'},]"
@@ -137,5 +157,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC', local_roles=
             "[{'user_name':'bob','local_role':'waeup.local.Boss'},]"
@@ -143,5 +163,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'waeup.local.Boss not allowed')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC', local_roles=
             "[{'user_name':'john','local_role':'waeup.local.DepartmentManager'},]"
@@ -149,5 +169,5 @@
         self.assertEqual(len(errs),1)
         self.assertEqual(errs, [('local_roles', 'john does not exist')])
-        errs, inv_errs, conv_dict = self.processor.checkConversion(
+        errs, inv_errs, conv_dict = self.proc.checkConversion(
             dict(faculty_code='ABC', local_roles=
             "[{'user_name':'bob','local_role':'waeup.local.DepartmentManager'},]"
@@ -157,5 +177,5 @@
 
     def test_import(self):
-        num, num_warns, fin_file, fail_file = self.processor.doImport(
+        num, num_warns, fin_file, fail_file = self.proc.doImport(
             self.csv_file_faculty, FACULTY_HEADER_FIELDS)
         content = open(fail_file).read()
@@ -181,7 +201,8 @@
         shutil.rmtree(os.path.dirname(fin_file))
 
-class TestDepartmentProcessors(unittest.TestCase):
-
-    def setUp(self):
+class TestDepartmentProcessor(UniversityProcessorSetup):
+
+    def setUp(self):
+        super(TestDepartmentProcessor, self).setUp()
         self.proc = DepartmentProcessor()
         self.site0 = dict()
@@ -236,21 +257,15 @@
         return
 
-class CourseProcessorTests(FunctionalTestCase):
-
-    layer = FunctionalLayer
+class CourseProcessorTests(UniversityProcessorSetup):
+
+    #layer = FunctionalLayer
 
     def setUp(self):
         super(CourseProcessorTests, self).setUp()
         self.proc = CourseProcessor()
-        self.site0 = dict()
-        self.site1 = dict(faculties=dict())
-        self.site2 = dict(faculties=dict(FAC=dict()))
-        self.department1 = Department(code='DPT')
-        self.department2 = Department(code='DPT')
-        self.course = Course(code='CRS')
-        self.department2.courses['CRS'] = self.course
-        self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1)))
-        self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2)))
-        self.row = dict(department_code='DPT', faculty_code='FAC', code="CRS")
+        self.row1 = dict(department_code='DEP2', faculty_code='FAC1', code="CRS1")
+        self.row2 = dict(department_code='DEP1', faculty_code='FAC2', code="CRS1")
+        self.row3 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS2")
+        self.row4 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS1")
         return
 
@@ -263,24 +278,18 @@
     def test_parents_exist(self):
         # make sure we lookup parents correctly
-        result0 = self.proc.parentsExist(self.row, self.site0)
-        result1 = self.proc.parentsExist(self.row, self.site1)
-        result2 = self.proc.parentsExist(self.row, self.site2)
-        result3 = self.proc.parentsExist(self.row, self.site3)
-        result4 = self.proc.parentsExist(self.row, self.site4)
-        self.assertTrue(result0 is False)
+        result1 = self.proc.parentsExist(self.row1, self.app)
+        result2 = self.proc.parentsExist(self.row2, self.app)
+        result3 = self.proc.parentsExist(self.row3, self.app)
         self.assertTrue(result1 is False)
         self.assertTrue(result2 is False)
         self.assertTrue(result3 is True)
-        self.assertTrue(result4 is True)
         return
 
     def test_entry_exists(self):
         # make sure we find an entry if it exists
-        result0 = self.proc.entryExists(self.row, self.site0)
-        result1 = self.proc.entryExists(self.row, self.site1)
-        result2 = self.proc.entryExists(self.row, self.site2)
-        result3 = self.proc.entryExists(self.row, self.site3)
-        result4 = self.proc.entryExists(self.row, self.site4)
-        self.assertTrue(result0 is False)
+        result1 = self.proc.entryExists(self.row1, self.app)
+        result2 = self.proc.entryExists(self.row2, self.app)
+        result3 = self.proc.entryExists(self.row3, self.app)
+        result4 = self.proc.entryExists(self.row4, self.app)
         self.assertTrue(result1 is False)
         self.assertTrue(result2 is False)
@@ -291,6 +300,6 @@
     def test_get_entry(self):
         # make sure we can get an entry if it exists
-        result1 = self.proc.getEntry(self.row, self.site3)
-        result2 = self.proc.getEntry(self.row, self.site4)
+        result1 = self.proc.getEntry(self.row1, self.app)
+        result2 = self.proc.getEntry(self.row4, self.app)
         self.assertTrue(result1 is None)
         self.assertTrue(result2 is self.course)
@@ -299,7 +308,7 @@
     def test_del_entry(self):
         # make sure we can delete entries
-        self.assertTrue('CRS' in self.department2.courses.keys())
-        self.proc.delEntry(self.row, self.site4)
-        self.assertTrue('CRS' not in self.department2.courses.keys())
+        self.assertTrue('CRS1' in self.app['faculties']['FAC1']['DEP1'].courses.keys())
+        self.proc.delEntry(self.row4, self.app)
+        self.assertTrue('CRS' not in self.app['faculties']['FAC1']['DEP1'].courses.keys())
         return
 
