Ignore:
Timestamp:
13 Jul 2012, 08:18:02 (12 years ago)
Author:
Henrik Bettermann
Message:

Customize updateEntry method of FacultyProcessor? to import local_roles.

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

    r8994 r8995  
    2121import tempfile
    2222import shutil
     23import os
    2324from zope.component.hooks import setSite, clearSite
     25from zope.securitypolicy.interfaces import IPrincipalRoleMap
    2426from zope.interface.verify import verifyClass, verifyObject
    2527from waeup.kofa.interfaces import IBatchProcessor
     
    3436from waeup.kofa.university.batching import FacultyProcessor
    3537
     38FACULTY_SAMPLE_DATA = open(
     39    os.path.join(os.path.dirname(__file__), 'sample_faculty_data.csv'),
     40    'rb').read()
     41
     42FACULTY_HEADER_FIELDS = FACULTY_SAMPLE_DATA.split(
     43    '\n')[0].split(',')
    3644
    3745class TestFacultyProcessor(FunctionalTestCase):
     
    5462        self.site2 = dict(faculties=dict(FAC='pseudo faculty'))
    5563        self.row = dict(code='FAC')
     64
    5665        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)
    5768        return
    5869
     
    144155        self.assertEqual(len(errs),0)
    145156        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))
    146182
    147183class TestDepartmentProcessors(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.