Ignore:
Timestamp:
29 Apr 2012, 12:55:52 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement import of student transitions.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students/tests
Files:
2 added
1 edited

Legend:

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

    r8289 r8309  
    3737from waeup.kofa.students.student import Student
    3838from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
    39 from waeup.kofa.interfaces import IBatchProcessor
     39from waeup.kofa.interfaces import IBatchProcessor, FatalCSVError
    4040
    4141STUDENT_SAMPLE_DATA = open(
     
    5858
    5959STUDENT_HEADER_FIELDS_UPDATE2 = STUDENT_SAMPLE_DATA_UPDATE2.split(
     60    '\n')[0].split(',')
     61
     62STUDENT_SAMPLE_DATA_UPDATE3 = open(
     63    os.path.join(os.path.dirname(__file__), 'sample_student_data_update3.csv'),
     64    'rb').read()
     65
     66STUDENT_HEADER_FIELDS_UPDATE3 = STUDENT_SAMPLE_DATA_UPDATE3.split(
     67    '\n')[0].split(',')
     68
     69STUDENT_SAMPLE_DATA_UPDATE4 = open(
     70    os.path.join(os.path.dirname(__file__), 'sample_student_data_update4.csv'),
     71    'rb').read()
     72
     73STUDENT_HEADER_FIELDS_UPDATE4 = STUDENT_SAMPLE_DATA_UPDATE4.split(
    6074    '\n')[0].split(',')
    6175
     
    179193        self.csv_file_update2 = os.path.join(
    180194            self.workdir, 'sample_student_data_update2.csv')
     195        self.csv_file_update3 = os.path.join(
     196            self.workdir, 'sample_student_data_update3.csv')
     197        self.csv_file_update4 = os.path.join(
     198            self.workdir, 'sample_student_data_update4.csv')
    181199        self.csv_file_migration = os.path.join(
    182200            self.workdir, 'sample_student_data_migration.csv')
     
    186204        open(self.csv_file_update, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE)
    187205        open(self.csv_file_update2, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE2)
     206        open(self.csv_file_update3, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE3)
     207        open(self.csv_file_update4, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE4)
    188208        open(self.csv_file_migration, 'wb').write(STUDENT_SAMPLE_DATA_MIGRATION)
    189209        open(self.csv_file_duplicates, 'wb').write(STUDENT_SAMPLE_DATA_DUPLICATES)
     
    293313        assert claus.phone is None
    294314        shutil.rmtree(os.path.dirname(fin_file))
     315
     316    def test_import_update3(self):
     317        num, num_warns, fin_file, fail_file = self.processor.doImport(
     318            self.csv_file, STUDENT_HEADER_FIELDS)
     319        shutil.rmtree(os.path.dirname(fin_file))
     320        num, num_warns, fin_file, fail_file = self.processor.doImport(
     321            self.csv_file_update3, STUDENT_HEADER_FIELDS_UPDATE3, 'update')
     322        content = open(fail_file).read()
     323        self.assertEqual(
     324            content,
     325            'reg_number,student_id,transition,--ERRORS--\r\n'
     326            '<IGNORE>,X666666,request_clearance,Transition not allowed.\r\n'
     327            )
     328        self.assertEqual(num_warns,1)
     329        self.assertEqual(self.app['students']['Y777777'].state,'returning')
     330
     331    def test_import_update4(self):
     332        num, num_warns, fin_file, fail_file = self.processor.doImport(
     333            self.csv_file, STUDENT_HEADER_FIELDS)
     334        shutil.rmtree(os.path.dirname(fin_file))
     335        self.assertRaises(
     336            FatalCSVError, self.processor.doImport, self.csv_file_update4,
     337            STUDENT_HEADER_FIELDS_UPDATE4, 'update')
    295338
    296339    def test_import_remove(self):
Note: See TracChangeset for help on using the changeset viewer.