Changeset 9918


Ignore:
Timestamp:
28 Jan 2013, 08:51:46 (12 years ago)
Author:
Henrik Bettermann
Message:

Add test to ensure that the importer handles extended ascii properly. Extended ascii is allowed for names but not for reg_numbers or matric_numbers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r9799 r9918  
     1# -*- coding: utf-8 -*-
    12## $Id$
    23##
     
    112113    '\n')[0].split(',')
    113114
     115STUDENT_SAMPLE_DATA_EXTASCII = open(
     116    os.path.join(os.path.dirname(__file__),
     117                 'sample_student_data_extascii.csv'),
     118    'rb').read()
     119
     120STUDENT_HEADER_FIELDS_EXTASCII = STUDENT_SAMPLE_DATA_EXTASCII.split(
     121    '\n')[0].split(',')
     122
    114123STUDYLEVEL_SAMPLE_DATA = open(
    115124    os.path.join(os.path.dirname(__file__), 'sample_studylevel_data.csv'),
     
    299308        self.csv_file_duplicates = os.path.join(
    300309            self.workdir, 'sample_student_data_duplicates.csv')
     310        self.csv_file_extascii = os.path.join(
     311            self.workdir, 'sample_student_data_extascii.csv')
    301312        open(self.csv_file, 'wb').write(STUDENT_SAMPLE_DATA)
    302313        open(self.csv_file_update, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE)
     
    306317        open(self.csv_file_migration, 'wb').write(STUDENT_SAMPLE_DATA_MIGRATION)
    307318        open(self.csv_file_duplicates, 'wb').write(STUDENT_SAMPLE_DATA_DUPLICATES)
     319        open(self.csv_file_extascii, 'wb').write(STUDENT_SAMPLE_DATA_EXTASCII)
    308320
    309321    def test_interface(self):
     
    394406        # Two new student_ids have been created.
    395407        self.assertEqual(self.app['students']._curr_stud_id, 1000003)
     408        shutil.rmtree(os.path.dirname(fin_file))
     409
     410    def test_import_non_ascii(self):
     411        self.assertEqual(self.app['students']._curr_stud_id, 1000001)
     412        num, num_warns, fin_file, fail_file = self.processor.doImport(
     413            self.csv_file_extascii, STUDENT_HEADER_FIELDS_EXTASCII)
     414        # Only the Mr. Müßig has been created. Mr. Kinderman's
     415        # reg_number has been rejected.
     416        self.assertEqual(num_warns,1)
     417        content = open(fail_file).read()
     418        self.assertEqual(
     419            content,
     420            'reg_number,firstname,student_id,email,phone,state,'
     421            'date_of_birth,lastname,sex,matric_number,--ERRORS--'
     422            '\r\n8\xc3\xa4\xc3\xb6\xc3\xbc,Thomas,X222222,aa@aa.ng,'
     423            '1234,courses validated,1990-01-02,Kinderman,m,100007,'
     424            'reg_number: Invalid text data\r\n'
     425            )
     426        self.assertEqual(len(self.app['students']), 1)
     427        self.assertEqual(self.app['students']['X111111'].reg_number,'1')
    396428        shutil.rmtree(os.path.dirname(fin_file))
    397429
Note: See TracChangeset for help on using the changeset viewer.