Changeset 9000 for main/waeup.kofa/trunk


Ignore:
Timestamp:
13 Jul 2012, 15:07:19 (12 years ago)
Author:
Henrik Bettermann
Message:

Add test_import to CertificateProcessorTests?.

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

    r8999 r9000  
    4949
    5050DEPARTMENT_HEADER_FIELDS = DEPARTMENT_SAMPLE_DATA.split(
     51    '\n')[0].split(',')
     52
     53CERTIFICATE_SAMPLE_DATA = open(
     54    os.path.join(os.path.dirname(__file__), 'sample_certificate_data.csv'),
     55    'rb').read()
     56
     57CERTIFICATE_HEADER_FIELDS = CERTIFICATE_SAMPLE_DATA.split(
    5158    '\n')[0].split(',')
    5259
     
    208215        self.assertEqual(local_role, 'waeup.local.DepartmentManager')
    209216        shutil.rmtree(os.path.dirname(fin_file))
     217        return
    210218
    211219class TestDepartmentProcessor(UniversityProcessorSetup):
     
    287295            'Not all parents do exist yet. Skipping\r\n'
    288296            )
    289         # Bob got a local role in department ABC.
     297        # Anne got a local role in department ABC.
    290298        dep = self.app['faculties']['FAC1']['DEP2']
    291299        role_map = IPrincipalRoleMap(dep)
     
    294302        self.assertEqual(local_role, 'waeup.local.DepartmentManager')
    295303        shutil.rmtree(os.path.dirname(fin_file))
     304        return
    296305
    297306class CourseProcessorTests(UniversityProcessorSetup):
     
    358367        self.row3 = dict(department_code='DEP1', faculty_code='FAC1', code="CRT2")
    359368        self.row4 = dict(department_code='DEP1', faculty_code='FAC1', code="CRT1")
     369
     370        self.csv_file_certificate = os.path.join(self.workdir, 'sample_certificate_data.csv')
     371        open(self.csv_file_certificate, 'wb').write(CERTIFICATE_SAMPLE_DATA)
    360372        return
    361373
     
    401413        self.proc.delEntry(self.row4, self.app)
    402414        self.assertTrue('CRT1' not in self.app['faculties']['FAC1']['DEP1'].certificates.keys())
     415        return
     416
     417    def test_import(self):
     418        num, num_warns, fin_file, fail_file = self.proc.doImport(
     419            self.csv_file_certificate, CERTIFICATE_HEADER_FIELDS)
     420        content = open(fail_file).read()
     421        self.assertEqual(num_warns,6)
     422        self.assertEqual(
     423            content,
     424            'faculty_code,department_code,code,local_roles,--ERRORS--\r\n'
     425            'FAC1,DEP1,CRT2,"[{\'user_name\':\'alice\',\'local_role\':\'waeup.local.CourseAdviser100\'}]",'
     426            'local_roles: alice does not exist\r\n'
     427            'FAC1,DEP1,CRT2,"[{\'user_name\':\'anne\',\'local_role\':\'waeup.local.Boss\'}]",'
     428            'local_roles: waeup.local.Boss not allowed\r\n'
     429            'FAC1,DEP1,CRT2,[(\'anything\')],local_roles: no dicts\r\n'
     430            'FAC1,DEP1,CRT2,[,local_roles: Error\r\n'
     431            'FAC1,DEP1,CRT2,"[{\'user\':\'anne\',\'local\':\'waeup.local.CourseAdviser100\'}]",'
     432            'local_roles: user_name or local_role missing\r\n'
     433            'FAC11,DEP2,CRT2,"[{\'user_name\':\'anne\',\'local_role\':\'waeup.local.CourseAdviser100\'}]",'
     434            'Not all parents do exist yet. Skipping\r\n'
     435            )
     436        # Anne got a local role in certificate ABC.
     437        dep = self.app['faculties']['FAC1']['DEP1'].certificates['CRT2']
     438        role_map = IPrincipalRoleMap(dep)
     439        local_role, user_name, setting = role_map.getPrincipalsAndRoles()[0]
     440        self.assertEqual(user_name, 'anne')
     441        self.assertEqual(local_role, 'waeup.local.CourseAdviser100')
     442        shutil.rmtree(os.path.dirname(fin_file))
    403443        return
    404444
Note: See TracChangeset for help on using the changeset viewer.