Changeset 8995 for main/waeup.kofa
- Timestamp:
- 13 Jul 2012, 08:18:02 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py
r8942 r8995 223 223 parent = self.getParent(row, site) 224 224 if hasattr(obj,'student_id'): 225 # Update mode: the student exists and we can get the student_id 225 # Update mode: the student exists and we can get the student_id. 226 # Create mode: the record contains the student_id 226 227 parent.logger.info( 227 228 '%s - Student record updated: %s' -
main/waeup.kofa/trunk/src/waeup/kofa/university/batching.py
r8994 r8995 29 29 from zope.schema import getFields 30 30 from zope.catalog.interfaces import ICatalog 31 from zope.event import notify 32 from zope.securitypolicy.interfaces import IPrincipalRoleManager 33 from waeup.kofa.authentication import LocalRoleSetEvent 31 34 from waeup.kofa.interfaces import IBatchProcessor, IGNORE_MARKER, FatalCSVError 32 35 from waeup.kofa.university.interfaces import ( … … 84 87 del parent[row['code']] 85 88 pass 89 90 def updateEntry(self, obj, row, site): 91 """Update obj to the values given in row. 92 """ 93 items_changed = '' 94 95 if row.has_key('local_roles'): 96 local_roles = eval(row['local_roles']) 97 for rolemap in local_roles: 98 user = rolemap['user_name'] 99 local_role = rolemap['local_role'] 100 role_manager = IPrincipalRoleManager(obj) 101 role_manager.assignRoleToPrincipal(local_role, user) 102 notify(LocalRoleSetEvent(obj, local_role, user, granted=True)) 103 items_changed += ( 104 '%s=%s, ' % ('local_roles', '%s|%s' % (user,local_role))) 105 row.pop('local_roles') 106 107 # apply other values... 108 items_changed += super(FacultyProcessor, self).updateEntry( 109 obj, row, site) 110 111 # Log actions... 112 grok.getSite().logger.info('%s - %s - Record updated: %s' 113 % (self.name, self.location_fields[0], items_changed)) 114 return items_changed 86 115 87 116 def checkConversion(self, row, mode='create'): -
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py
r8994 r8995 21 21 import tempfile 22 22 import shutil 23 import os 23 24 from zope.component.hooks import setSite, clearSite 25 from zope.securitypolicy.interfaces import IPrincipalRoleMap 24 26 from zope.interface.verify import verifyClass, verifyObject 25 27 from waeup.kofa.interfaces import IBatchProcessor … … 34 36 from waeup.kofa.university.batching import FacultyProcessor 35 37 38 FACULTY_SAMPLE_DATA = open( 39 os.path.join(os.path.dirname(__file__), 'sample_faculty_data.csv'), 40 'rb').read() 41 42 FACULTY_HEADER_FIELDS = FACULTY_SAMPLE_DATA.split( 43 '\n')[0].split(',') 36 44 37 45 class TestFacultyProcessor(FunctionalTestCase): … … 54 62 self.site2 = dict(faculties=dict(FAC='pseudo faculty')) 55 63 self.row = dict(code='FAC') 64 56 65 self.processor = FacultyProcessor() 66 self.csv_file_faculty = os.path.join(self.workdir, 'sample_faculty_data.csv') 67 open(self.csv_file_faculty, 'wb').write(FACULTY_SAMPLE_DATA) 57 68 return 58 69 … … 144 155 self.assertEqual(len(errs),0) 145 156 return 157 158 def test_import(self): 159 num, num_warns, fin_file, fail_file = self.processor.doImport( 160 self.csv_file_faculty, FACULTY_HEADER_FIELDS) 161 content = open(fail_file).read() 162 self.assertEqual(num_warns,5) 163 self.assertEqual( 164 content, 165 'code,local_roles,--ERRORS--\r\n' 166 'CDE,"[{\'user_name\':\'alice\',\'local_role\':\'waeup.local.DepartmentManager\'}]",' 167 'local_roles: alice does not exist\r\n' 168 'DEF,"[{\'user_name\':\'bob\',\'local_role\':\'waeup.local.Boss\'}]",' 169 'local_roles: waeup.local.Boss not allowed\r\n' 170 'EFG,[(\'anything\')],local_roles: no dicts\r\n' 171 'FGH,[,local_roles: Error\r\n' 172 'GHI,"[{\'user\':\'bob\',\'local\':\'waeup.local.DepartmentManager\'}]",' 173 'local_roles: user_name or local_role missing\r\n' 174 ) 175 # Bob got a local role in faculty ABC. 176 abc = self.app['faculties']['ABC'] 177 role_map = IPrincipalRoleMap(abc) 178 local_role, user_name, setting = role_map.getPrincipalsAndRoles()[0] 179 self.assertEqual(user_name, 'bob') 180 self.assertEqual(local_role, 'waeup.local.DepartmentManager') 181 shutil.rmtree(os.path.dirname(fin_file)) 146 182 147 183 class TestDepartmentProcessors(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.