Ignore:
Timestamp:
13 Jul 2012, 14:42:44 (12 years ago)
Author:
Henrik Bettermann
Message:

Add test_import to TestDepartmentProcessor?.

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

    r8998 r8999  
    4444    '\n')[0].split(',')
    4545
     46DEPARTMENT_SAMPLE_DATA = open(
     47    os.path.join(os.path.dirname(__file__), 'sample_department_data.csv'),
     48    'rb').read()
     49
     50DEPARTMENT_HEADER_FIELDS = DEPARTMENT_SAMPLE_DATA.split(
     51    '\n')[0].split(',')
     52
    4653class UniversityProcessorSetup(FunctionalTestCase):
    4754
     
    5865
    5966        self.app['users'].addUser('bob', 'bobssecret')
     67        self.app['users'].addUser('anne', 'annessecret')
    6068
    6169        # Populate university
     
    211219        self.site3 = dict(faculties=dict(FAC=dict(DPT='pseudo department')))
    212220        self.row = dict(code='DPT', faculty_code='FAC')
     221
     222        self.csv_file_department = os.path.join(self.workdir, 'sample_department_data.csv')
     223        open(self.csv_file_department, 'wb').write(DEPARTMENT_SAMPLE_DATA)
    213224        return
    214225
     
    256267        self.assertTrue('DPT' not in self.site3['faculties']['FAC'].keys())
    257268        return
     269
     270    def test_import(self):
     271        num, num_warns, fin_file, fail_file = self.proc.doImport(
     272            self.csv_file_department, DEPARTMENT_HEADER_FIELDS)
     273        content = open(fail_file).read()
     274        self.assertEqual(num_warns,6)
     275        self.assertEqual(
     276            content,
     277            'faculty_code,code,local_roles,--ERRORS--\r\n'
     278            'FAC1,DEP2,"[{\'user_name\':\'alice\',\'local_role\':\'waeup.local.DepartmentManager\'}]",'
     279            'local_roles: alice does not exist\r\n'
     280            'FAC1,DEP2,"[{\'user_name\':\'anne\',\'local_role\':\'waeup.local.Boss\'}]",'
     281            'local_roles: waeup.local.Boss not allowed\r\n'
     282            'FAC1,DEP2,[(\'anything\')],local_roles: no dicts\r\n'
     283            'FAC1,DEP2,[,local_roles: Error\r\n'
     284            'FAC1,DEP2,"[{\'user\':\'anne\',\'local\':\'waeup.local.DepartmentManager\'}]",'
     285            'local_roles: user_name or local_role missing\r\n'
     286            'FAC11,DEP2,"[{\'user_name\':\'anne\',\'local_role\':\'waeup.local.DepartmentManager\'}]",'
     287            'Not all parents do exist yet. Skipping\r\n'
     288            )
     289        # Bob got a local role in department ABC.
     290        dep = self.app['faculties']['FAC1']['DEP2']
     291        role_map = IPrincipalRoleMap(dep)
     292        local_role, user_name, setting = role_map.getPrincipalsAndRoles()[0]
     293        self.assertEqual(user_name, 'anne')
     294        self.assertEqual(local_role, 'waeup.local.DepartmentManager')
     295        shutil.rmtree(os.path.dirname(fin_file))
    258296
    259297class CourseProcessorTests(UniversityProcessorSetup):
Note: See TracChangeset for help on using the changeset viewer.