- Timestamp:
- 13 Jul 2012, 06:09:32 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/university
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/batching.py
r8920 r8994 33 33 IFacultiesContainer, IFaculty, ICourse, IDepartment, ICertificate, 34 34 ICertificateCourse) 35 from waeup.kofa.university.faculty import Faculty 35 36 from waeup.kofa.utils.batching import BatchProcessor 36 37 … … 46 47 name = u'Faculty Processor' 47 48 iface = IFaculty 49 allowed_roles = Faculty.local_roles 48 50 49 51 location_fields = ['code',] … … 55 57 return 'faculties' in site.keys() 56 58 59 @property 60 def available_fields(self): 61 fields = getFields(self.iface) 62 return sorted(list(set( 63 ['local_roles'] + fields.keys()))) 64 57 65 def entryExists(self, row, site): 58 66 return row['code'] in site['faculties'].keys() … … 76 84 del parent[row['code']] 77 85 pass 86 87 def checkConversion(self, row, mode='create'): 88 """Validates all values in row. 89 """ 90 errs, inv_errs, conv_dict = super( 91 FacultyProcessor, self).checkConversion(row, mode=mode) 92 if row.has_key('local_roles'): 93 try: 94 local_roles = eval(row['local_roles']) 95 except: 96 errs.append(('local_roles','Error')) 97 return errs, inv_errs, conv_dict 98 if not isinstance(local_roles, list): 99 errs.append(('local_roles','no list')) 100 return errs, inv_errs, conv_dict 101 for rolemap in local_roles: 102 if not isinstance(rolemap, dict): 103 errs.append(('local_roles','no dicts')) 104 return errs, inv_errs, conv_dict 105 if not 'user_name' in rolemap.keys() or not \ 106 'local_role' in rolemap.keys(): 107 errs.append(('local_roles','user_name or local_role missing')) 108 return errs, inv_errs, conv_dict 109 local_role = rolemap['local_role'] 110 if not local_role in self.allowed_roles: 111 errs.append(('local_roles','%s not allowed' % local_role)) 112 return errs, inv_errs, conv_dict 113 user = rolemap['user_name'] 114 users = grok.getSite()['users'] 115 if not user in users.keys(): 116 errs.append(('local_roles','%s does not exist' % user)) 117 return errs, inv_errs, conv_dict 118 return errs, inv_errs, conv_dict 78 119 79 120 class DepartmentProcessor(BatchProcessor): -
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py
r8920 r8994 19 19 # Tests for university related batching 20 20 import unittest 21 21 import tempfile 22 import shutil 23 from zope.component.hooks import setSite, clearSite 22 24 from zope.interface.verify import verifyClass, verifyObject 23 25 from waeup.kofa.interfaces import IBatchProcessor 24 26 from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer 27 from waeup.kofa.app import University 25 28 from waeup.kofa.university.batching import ( 26 29 FacultyProcessor, DepartmentProcessor, CourseProcessor, … … 29 32 from waeup.kofa.university.course import Course 30 33 from waeup.kofa.university.department import Department 31 32 33 class TestFacultyProcessor(unittest.TestCase): 34 from waeup.kofa.university.batching import FacultyProcessor 35 36 37 class TestFacultyProcessor(FunctionalTestCase): 38 39 layer = FunctionalLayer 34 40 35 41 def setUp(self): 42 super(TestFacultyProcessor, self).setUp() 43 self.dc_root = tempfile.mkdtemp() 44 self.workdir = tempfile.mkdtemp() 45 app = University() 46 self.getRootFolder()['app'] = app 47 self.app = self.getRootFolder()['app'] 48 setSite(app) 49 50 self.app['users'].addUser('bob', 'bobssecret') 51 36 52 self.proc = FacultyProcessor() 37 53 self.site1 = dict(faculties=dict()) 38 54 self.site2 = dict(faculties=dict(FAC='pseudo faculty')) 39 55 self.row = dict(code='FAC') 56 self.processor = FacultyProcessor() 57 return 58 59 def tearDown(self): 60 super(TestFacultyProcessor, self).tearDown() 61 shutil.rmtree(self.workdir) 62 shutil.rmtree(self.dc_root) 63 clearSite() 40 64 return 41 65 … … 58 82 self.proc.delEntry(self.row, self.site2) 59 83 self.assertTrue('FAC' not in self.site2.keys()) 84 return 85 86 def test_checkConversion(self): 87 # Make sure we can check conversions. 88 errs, inv_errs, conv_dict = self.processor.checkConversion( 89 dict(faculty_code='ABC', local_roles='[]')) 90 self.assertEqual(len(errs),0) 91 92 errs, inv_errs, conv_dict = self.processor.checkConversion( 93 dict(faculty_code='ABC', 94 local_roles="['nonsense'" 95 )) 96 self.assertEqual(len(errs),1) 97 self.assertEqual(errs, [('local_roles', 'Error')]) 98 errs, inv_errs, conv_dict = self.processor.checkConversion( 99 dict(faculty_code='ABC', 100 local_roles="('abc')" 101 )) 102 self.assertEqual(len(errs),1) 103 self.assertEqual(errs, [('local_roles', 'no list')]) 104 errs, inv_errs, conv_dict = self.processor.checkConversion( 105 dict(faculty_code='ABC', 106 local_roles="[('ABC')]" 107 )) 108 self.assertEqual(len(errs),1) 109 self.assertEqual(errs, [('local_roles', 'no dicts')]) 110 errs, inv_errs, conv_dict = self.processor.checkConversion( 111 dict(faculty_code='ABC', 112 local_roles="('abc')" 113 )) 114 self.assertEqual(len(errs),1) 115 self.assertEqual(errs, [('local_roles', 'no list')]) 116 errs, inv_errs, conv_dict = self.processor.checkConversion( 117 dict(faculty_code='ABC', local_roles= 118 "[{'name':'bob','local_role':'waeup.local.DepartmentManager'},]" 119 )) 120 self.assertEqual(len(errs),1) 121 self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')]) 122 errs, inv_errs, conv_dict = self.processor.checkConversion( 123 dict(faculty_code='ABC', local_roles= 124 "[{'user_name':'bob','localrole':'waeup.local.DepartmentManager'},]" 125 )) 126 self.assertEqual(len(errs),1) 127 self.assertEqual(errs, [('local_roles', 'user_name or local_role missing')]) 128 errs, inv_errs, conv_dict = self.processor.checkConversion( 129 dict(faculty_code='ABC', local_roles= 130 "[{'user_name':'bob','local_role':'waeup.local.Boss'},]" 131 )) 132 self.assertEqual(len(errs),1) 133 self.assertEqual(errs, [('local_roles', 'waeup.local.Boss not allowed')]) 134 errs, inv_errs, conv_dict = self.processor.checkConversion( 135 dict(faculty_code='ABC', local_roles= 136 "[{'user_name':'john','local_role':'waeup.local.DepartmentManager'},]" 137 )) 138 self.assertEqual(len(errs),1) 139 self.assertEqual(errs, [('local_roles', 'john does not exist')]) 140 errs, inv_errs, conv_dict = self.processor.checkConversion( 141 dict(faculty_code='ABC', local_roles= 142 "[{'user_name':'bob','local_role':'waeup.local.DepartmentManager'},]" 143 )) 144 self.assertEqual(len(errs),0) 60 145 return 61 146
Note: See TracChangeset for help on using the changeset viewer.