Ignore:
Timestamp:
13 Jul 2012, 16:36:21 (12 years ago)
Author:
Henrik Bettermann
Message:

Add lecturer local role which has no dynamic role assignment yet.

Add test_import to CourseProcessorTests?.

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

    r9001 r9002  
    6464
    6565CERTIFICATE_HEADER_FIELDS = CERTIFICATE_SAMPLE_DATA.split(
     66    '\n')[0].split(',')
     67
     68COURSE_SAMPLE_DATA = open(
     69    os.path.join(os.path.dirname(__file__), 'sample_course_data.csv'),
     70    'rb').read()
     71
     72COURSE_HEADER_FIELDS = COURSE_SAMPLE_DATA.split(
    6673    '\n')[0].split(',')
    6774
     
    375382        self.row3 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS2")
    376383        self.row4 = dict(department_code='DEP1', faculty_code='FAC1', code="CRS1")
     384
     385        self.csv_file_course = os.path.join(self.workdir, 'sample_course_data.csv')
     386        open(self.csv_file_course, 'wb').write(COURSE_SAMPLE_DATA)
    377387        return
    378388
     
    419429        self.assertTrue('CRS1' not in self.app['faculties']['FAC1']['DEP1'].courses.keys())
    420430        return
     431
     432    def test_import(self):
     433        num, num_warns, fin_file, fail_file = self.proc.doImport(
     434            self.csv_file_course, COURSE_HEADER_FIELDS)
     435        content = open(fail_file).read()
     436        self.assertEqual(num_warns,6)
     437        self.assertEqual(
     438            content,
     439            'faculty_code,department_code,code,local_roles,--ERRORS--\r\n'
     440            'FAC1,DEP1,CRS2,"[{\'user_name\':\'alice\',\'local_role\':\'waeup.local.Lecturer\'}]",'
     441            'local_roles: alice does not exist\r\n'
     442            'FAC1,DEP1,CRS2,"[{\'user_name\':\'anne\',\'local_role\':\'waeup.local.Boss\'}]",'
     443            'local_roles: waeup.local.Boss not allowed\r\n'
     444            'FAC1,DEP1,CRS2,[(\'anything\')],local_roles: no dicts\r\n'
     445            'FAC1,DEP1,CRS2,[,local_roles: Error\r\n'
     446            'FAC1,DEP1,CRS2,"[{\'user\':\'anne\',\'local\':\'waeup.local.Lecturer\'}]",'
     447            'local_roles: user_name or local_role missing\r\n'
     448            'FAC11,DEP2,CRS2,"[{\'user_name\':\'anne\',\'local_role\':\'waeup.local.Lecturer\'}]",'
     449            'Not all parents do exist yet. Skipping\r\n'
     450            )
     451        # Anne got a local role in course ABC.
     452        dep = self.app['faculties']['FAC1']['DEP1'].courses['CRS2']
     453        role_map = IPrincipalRoleMap(dep)
     454        local_role, user_name, setting = role_map.getPrincipalsAndRoles()[0]
     455        self.assertEqual(user_name, 'anne')
     456        self.assertEqual(local_role, 'waeup.local.Lecturer')
     457        shutil.rmtree(os.path.dirname(fin_file))
     458        return
     459
    421460
    422461class CertificateProcessorTests(UniversityProcessorSetup):
Note: See TracChangeset for help on using the changeset viewer.