Changeset 9001 for main/waeup.kofa/trunk/src/waeup/kofa/university/tests
- Timestamp:
- 13 Jul 2012, 16:17:44 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/university/tests
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_batching.py
r9000 r9001 24 24 from zope.component.hooks import setSite, clearSite 25 25 from zope.component import createObject 26 from zope.securitypolicy.interfaces import IPrincipalRoleMap 26 from zope.securitypolicy.interfaces import ( 27 IPrincipalRoleMap, IPrincipalRoleManager) 27 28 from zope.interface.verify import verifyClass, verifyObject 28 29 from waeup.kofa.interfaces import IBatchProcessor … … 42 43 43 44 FACULTY_HEADER_FIELDS = FACULTY_SAMPLE_DATA.split( 45 '\n')[0].split(',') 46 47 FACULTY_SAMPLE_DATA_UPDATE = open( 48 os.path.join(os.path.dirname(__file__), 'sample_faculty_data_update.csv'), 49 'rb').read() 50 51 FACULTY_HEADER_FIELDS_UPDATE = FACULTY_SAMPLE_DATA_UPDATE.split( 44 52 '\n')[0].split(',') 45 53 … … 108 116 self.csv_file_faculty = os.path.join(self.workdir, 'sample_faculty_data.csv') 109 117 open(self.csv_file_faculty, 'wb').write(FACULTY_SAMPLE_DATA) 118 self.csv_file_faculty_update = os.path.join(self.workdir, 'sample_faculty_data_update.csv') 119 open(self.csv_file_faculty_update, 'wb').write(FACULTY_SAMPLE_DATA_UPDATE) 110 120 return 111 121 … … 214 224 self.assertEqual(user_name, 'bob') 215 225 self.assertEqual(local_role, 'waeup.local.DepartmentManager') 226 shutil.rmtree(os.path.dirname(fin_file)) 227 return 228 229 def test_import_update(self): 230 self.app['faculties']['FAC2'] = Faculty(code='FAC2') 231 self.app['faculties']['FAC3'] = Faculty(code='FAC3') 232 self.app['faculties']['FAC4'] = Faculty(code='FAC4') 233 234 role_manager1 = IPrincipalRoleManager(self.app['faculties']['FAC1']) 235 role_manager1.assignRoleToPrincipal('alfonsrole', 'alfons') 236 role_map1 = IPrincipalRoleMap(self.app['faculties']['FAC1']) 237 self.assertEqual(len(role_map1.getPrincipalsAndRoles()), 1) 238 239 role_manager2 = IPrincipalRoleManager(self.app['faculties']['FAC2']) 240 role_manager2.assignRoleToPrincipal('alfonsrole', 'alfons') 241 role_map2 = IPrincipalRoleMap(self.app['faculties']['FAC2']) 242 self.assertEqual(len(role_map2.getPrincipalsAndRoles()), 1) 243 244 role_manager3 = IPrincipalRoleManager(self.app['faculties']['FAC3']) 245 role_manager3.assignRoleToPrincipal('alfonsrole', 'alfons') 246 role_map3 = IPrincipalRoleMap(self.app['faculties']['FAC3']) 247 self.assertEqual(len(role_map3.getPrincipalsAndRoles()), 1) 248 249 role_manager4 = IPrincipalRoleManager(self.app['faculties']['FAC4']) 250 role_manager4.assignRoleToPrincipal('alfonsrole', 'alfons') 251 role_map4 = IPrincipalRoleMap(self.app['faculties']['FAC4']) 252 self.assertEqual(len(role_map4.getPrincipalsAndRoles()), 1) 253 254 local_role, user_name, setting = role_map2.getPrincipalsAndRoles()[0] 255 self.assertEqual(user_name, 'alfons') 256 self.assertEqual(local_role, 'alfonsrole') 257 258 num, num_warns, fin_file, fail_file = self.proc.doImport( 259 self.csv_file_faculty_update, FACULTY_HEADER_FIELDS_UPDATE, 'update') 260 self.assertEqual(num_warns,0) 261 # Local roles have been removed in FAC1 due to deletion marker. 262 self.assertEqual(len(role_map1.getPrincipalsAndRoles()), 0) 263 # Old local roles have been removed and new roles have been added in FAC2. 264 self.assertEqual(len(role_map2.getPrincipalsAndRoles()), 1) 265 local_role, user_name, setting = role_map2.getPrincipalsAndRoles()[0] 266 self.assertEqual(user_name, 'bob') 267 self.assertEqual(local_role, 'waeup.local.DepartmentManager') 268 # Local roles are not touched in FAC3 due to ignore marker. 269 self.assertEqual(len(role_map3.getPrincipalsAndRoles()), 1) 270 local_role, user_name, setting = role_map3.getPrincipalsAndRoles()[0] 271 self.assertEqual(user_name, 'alfons') 272 self.assertEqual(local_role, 'alfonsrole') 273 # Local roles are not touched in FAC4 due to empty cell. 274 self.assertEqual(len(role_map4.getPrincipalsAndRoles()), 1) 275 local_role, user_name, setting = role_map4.getPrincipalsAndRoles()[0] 276 self.assertEqual(user_name, 'alfons') 277 self.assertEqual(local_role, 'alfonsrole') 216 278 shutil.rmtree(os.path.dirname(fin_file)) 217 279 return
Note: See TracChangeset for help on using the changeset viewer.