Changeset 8997 for main/waeup.kofa/trunk/src
- Timestamp:
- 13 Jul 2012, 10:54:40 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py
r8995 r8997 23 23 import os 24 24 from zope.component.hooks import setSite, clearSite 25 from zope.component import createObject 25 26 from zope.securitypolicy.interfaces import IPrincipalRoleMap 26 27 from zope.interface.verify import verifyClass, verifyObject … … 33 34 from waeup.kofa.university.certificate import Certificate, CertificateCourse 34 35 from waeup.kofa.university.course import Course 35 from waeup.kofa.university .department importDepartment36 from waeup.kofa.university import Faculty, Department 36 37 from waeup.kofa.university.batching import FacultyProcessor 37 38 … … 43 44 '\n')[0].split(',') 44 45 45 class TestFacultyProcessor(FunctionalTestCase):46 class UniversityProcessorSetup(FunctionalTestCase): 46 47 47 48 layer = FunctionalLayer 48 49 49 50 def setUp(self): 50 super( TestFacultyProcessor, self).setUp()51 super(UniversityProcessorSetup, self).setUp() 51 52 self.dc_root = tempfile.mkdtemp() 52 53 self.workdir = tempfile.mkdtemp() … … 58 59 self.app['users'].addUser('bob', 'bobssecret') 59 60 61 # Populate university 62 self.certificate = createObject('waeup.Certificate') 63 self.certificate.code = 'CERT1' 64 self.app['faculties']['FAC1'] = Faculty(code='FAC1') 65 self.app['faculties']['FAC1']['DEP1'] = Department(code='DEP1') 66 self.app['faculties']['FAC1']['DEP1'].certificates.addCertificate( 67 self.certificate) 68 self.course = createObject('waeup.Course') 69 self.course.code = 'CRS1' 70 self.app['faculties']['FAC1']['DEP1'].courses.addCourse( 71 self.course) 72 #self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse( 73 # self.course, level=100) 74 return 75 76 def tearDown(self): 77 super(UniversityProcessorSetup, self).tearDown() 78 shutil.rmtree(self.workdir) 79 shutil.rmtree(self.dc_root) 80 clearSite() 81 return 82 83 class TestFacultyProcessor(UniversityProcessorSetup): 84 85 def setUp(self): 86 super(TestFacultyProcessor, self).setUp() 87 60 88 self.proc = FacultyProcessor() 61 89 self.site1 = dict(faculties=dict()) … … 63 91 self.row = dict(code='FAC') 64 92 65 self.processor = FacultyProcessor()66 93 self.csv_file_faculty = os.path.join(self.workdir, 'sample_faculty_data.csv') 67 94 open(self.csv_file_faculty, 'wb').write(FACULTY_SAMPLE_DATA) 68 return69 70 def tearDown(self):71 super(TestFacultyProcessor, self).tearDown()72 shutil.rmtree(self.workdir)73 shutil.rmtree(self.dc_root)74 clearSite()75 95 return 76 96 … … 97 117 def test_checkConversion(self): 98 118 # Make sure we can check conversions. 99 errs, inv_errs, conv_dict = self.proc essor.checkConversion(119 errs, inv_errs, conv_dict = self.proc.checkConversion( 100 120 dict(faculty_code='ABC', local_roles='[]')) 101 121 self.assertEqual(len(errs),0) 102 122 103 errs, inv_errs, conv_dict = self.proc essor.checkConversion(123 errs, inv_errs, conv_dict = self.proc.checkConversion( 104 124 dict(faculty_code='ABC', 105 125 local_roles="['nonsense'" … … 107 127 self.assertEqual(len(errs),1) 108 128 self.assertEqual(errs, [('local_roles', 'Error')]) 109 errs, inv_errs, conv_dict = self.proc essor.checkConversion(129 errs, inv_errs, conv_dict = self.proc.checkConversion( 110 130 dict(faculty_code='ABC', 111 131 local_roles="('abc')" … … 113 133 self.assertEqual(len(errs),1) 114 134 self.assertEqual(errs, [('local_roles', 'no list')]) 115 errs, inv_errs, conv_dict = self.proc essor.checkConversion(135 errs, inv_errs, conv_dict = self.proc.checkConversion( 116 136 dict(faculty_code='ABC', 117 137 local_roles="[('ABC')]" … … 119 139 self.assertEqual(len(errs),1) 120 140 self.assertEqual(errs, [('local_roles', 'no dicts')]) 121 errs, inv_errs, conv_dict = self.proc essor.checkConversion(141 errs, inv_errs, conv_dict = self.proc.checkConversion( 122 142 dict(faculty_code='ABC', 123 143 local_roles="('abc')" … … 125 145 self.assertEqual(len(errs),1) 126 146 self.assertEqual(errs, [('local_roles', 'no list')]) 127 errs, inv_errs, conv_dict = self.proc essor.checkConversion(147 errs, inv_errs, conv_dict = self.proc.checkConversion( 128 148 dict(faculty_code='ABC', local_roles= 129 149 "[{'name':'bob','local_role':'waeup.local.DepartmentManager'},]" … … 131 151 self.assertEqual(len(errs),1) 132 152 self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')]) 133 errs, inv_errs, conv_dict = self.proc essor.checkConversion(153 errs, inv_errs, conv_dict = self.proc.checkConversion( 134 154 dict(faculty_code='ABC', local_roles= 135 155 "[{'user_name':'bob','localrole':'waeup.local.DepartmentManager'},]" … … 137 157 self.assertEqual(len(errs),1) 138 158 self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')]) 139 errs, inv_errs, conv_dict = self.proc essor.checkConversion(159 errs, inv_errs, conv_dict = self.proc.checkConversion( 140 160 dict(faculty_code='ABC', local_roles= 141 161 "[{'user_name':'bob','local_role':'waeup.local.Boss'},]" … … 143 163 self.assertEqual(len(errs),1) 144 164 self.assertEqual(errs, [('local_roles', 'waeup.local.Boss not allowed')]) 145 errs, inv_errs, conv_dict = self.proc essor.checkConversion(165 errs, inv_errs, conv_dict = self.proc.checkConversion( 146 166 dict(faculty_code='ABC', local_roles= 147 167 "[{'user_name':'john','local_role':'waeup.local.DepartmentManager'},]" … … 149 169 self.assertEqual(len(errs),1) 150 170 self.assertEqual(errs, [('local_roles', 'john does not exist')]) 151 errs, inv_errs, conv_dict = self.proc essor.checkConversion(171 errs, inv_errs, conv_dict = self.proc.checkConversion( 152 172 dict(faculty_code='ABC', local_roles= 153 173 "[{'user_name':'bob','local_role':'waeup.local.DepartmentManager'},]" … … 157 177 158 178 def test_import(self): 159 num, num_warns, fin_file, fail_file = self.proc essor.doImport(179 num, num_warns, fin_file, fail_file = self.proc.doImport( 160 180 self.csv_file_faculty, FACULTY_HEADER_FIELDS) 161 181 content = open(fail_file).read() … … 181 201 shutil.rmtree(os.path.dirname(fin_file)) 182 202 183 class TestDepartmentProcessors(unittest.TestCase): 184 185 def setUp(self): 203 class TestDepartmentProcessor(UniversityProcessorSetup): 204 205 def setUp(self): 206 super(TestDepartmentProcessor, self).setUp() 186 207 self.proc = DepartmentProcessor() 187 208 self.site0 = dict() … … 236 257 return 237 258 238 class CourseProcessorTests( FunctionalTestCase):239 240 layer = FunctionalLayer259 class CourseProcessorTests(UniversityProcessorSetup): 260 261 #layer = FunctionalLayer 241 262 242 263 def setUp(self): 243 264 super(CourseProcessorTests, self).setUp() 244 265 self.proc = CourseProcessor() 245 self.site0 = dict() 246 self.site1 = dict(faculties=dict()) 247 self.site2 = dict(faculties=dict(FAC=dict())) 248 self.department1 = Department(code='DPT') 249 self.department2 = Department(code='DPT') 250 self.course = Course(code='CRS') 251 self.department2.courses['CRS'] = self.course 252 self.site3 = dict(faculties=dict(FAC=dict(DPT=self.department1))) 253 self.site4 = dict(faculties=dict(FAC=dict(DPT=self.department2))) 254 self.row = dict(department_code='DPT', faculty_code='FAC', code="CRS") 266 self.row1 = dict(department_code='DEP2', faculty_code='FAC1', code="CRS1") 267 self.row2 = dict(department_code='DEP1', faculty_code='FAC2', code="CRS1") 268 self.row3 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS2") 269 self.row4 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS1") 255 270 return 256 271 … … 263 278 def test_parents_exist(self): 264 279 # make sure we lookup parents correctly 265 result0 = self.proc.parentsExist(self.row, self.site0) 266 result1 = self.proc.parentsExist(self.row, self.site1) 267 result2 = self.proc.parentsExist(self.row, self.site2) 268 result3 = self.proc.parentsExist(self.row, self.site3) 269 result4 = self.proc.parentsExist(self.row, self.site4) 270 self.assertTrue(result0 is False) 280 result1 = self.proc.parentsExist(self.row1, self.app) 281 result2 = self.proc.parentsExist(self.row2, self.app) 282 result3 = self.proc.parentsExist(self.row3, self.app) 271 283 self.assertTrue(result1 is False) 272 284 self.assertTrue(result2 is False) 273 285 self.assertTrue(result3 is True) 274 self.assertTrue(result4 is True)275 286 return 276 287 277 288 def test_entry_exists(self): 278 289 # make sure we find an entry if it exists 279 result0 = self.proc.entryExists(self.row, self.site0) 280 result1 = self.proc.entryExists(self.row, self.site1) 281 result2 = self.proc.entryExists(self.row, self.site2) 282 result3 = self.proc.entryExists(self.row, self.site3) 283 result4 = self.proc.entryExists(self.row, self.site4) 284 self.assertTrue(result0 is False) 290 result1 = self.proc.entryExists(self.row1, self.app) 291 result2 = self.proc.entryExists(self.row2, self.app) 292 result3 = self.proc.entryExists(self.row3, self.app) 293 result4 = self.proc.entryExists(self.row4, self.app) 285 294 self.assertTrue(result1 is False) 286 295 self.assertTrue(result2 is False) … … 291 300 def test_get_entry(self): 292 301 # make sure we can get an entry if it exists 293 result1 = self.proc.getEntry(self.row , self.site3)294 result2 = self.proc.getEntry(self.row , self.site4)302 result1 = self.proc.getEntry(self.row1, self.app) 303 result2 = self.proc.getEntry(self.row4, self.app) 295 304 self.assertTrue(result1 is None) 296 305 self.assertTrue(result2 is self.course) … … 299 308 def test_del_entry(self): 300 309 # make sure we can delete entries 301 self.assertTrue('CRS ' in self.department2.courses.keys())302 self.proc.delEntry(self.row , self.site4)303 self.assertTrue('CRS' not in self. department2.courses.keys())310 self.assertTrue('CRS1' in self.app['faculties']['FAC1']['DEP1'].courses.keys()) 311 self.proc.delEntry(self.row4, self.app) 312 self.assertTrue('CRS' not in self.app['faculties']['FAC1']['DEP1'].courses.keys()) 304 313 return 305 314
Note: See TracChangeset for help on using the changeset viewer.