Ignore:
Timestamp:
30 Jan 2012, 07:41:17 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement study level importer.

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

Legend:

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

    r7534 r7536  
    3131from waeup.sirp.university.department import Department
    3232from waeup.sirp.students.batching import (
    33     StudentProcessor, StudentStudyCourseProcessor)
     33    StudentProcessor, StudentStudyCourseProcessor,
     34    StudentStudyLevelProcessor)
    3435from waeup.sirp.students.student import Student
    3536from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
     
    6970
    7071STUDENT_HEADER_FIELDS_MIGRATION = STUDENT_SAMPLE_DATA_MIGRATION.split(
     72    '\n')[0].split(',')
     73
     74STUDYLEVEL_SAMPLE_DATA = open(
     75    os.path.join(os.path.dirname(__file__), 'sample_studylevel_data.csv'),
     76    'rb').read()
     77
     78STUDYLEVEL_HEADER_FIELDS = STUDYLEVEL_SAMPLE_DATA.split(
    7179    '\n')[0].split(',')
    7280
     
    212220        shutil.rmtree(os.path.dirname(fin_file))
    213221
     222
    214223class StudentStudyCourseImporterTest(FunctionalTestCase):
    215224
     
    218227    def setUp(self):
    219228        super(StudentStudyCourseImporterTest, self).setUp()
     229        self.dc_root = tempfile.mkdtemp()
     230        self.workdir = tempfile.mkdtemp()
    220231        app = University()
    221         self.dc_root = tempfile.mkdtemp()
    222232        app['datacenter'].setStoragePath(self.dc_root)
    223 
    224233        self.getRootFolder()['app'] = app
    225234        self.app = self.getRootFolder()['app']
    226235        setSite(app)
    227 
    228         self.workdir = tempfile.mkdtemp()
    229         self.importer = StudentStudyCourseProcessor()
    230         self.csv_file = os.path.join(
    231             self.workdir, 'sample_studycourse_data.csv')
    232         open(self.csv_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA)
    233236
    234237        # Import students with subobjects
     
    249252        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
    250253            self.certificate)
     254
     255        self.importer = StudentStudyCourseProcessor()
     256        self.csv_file = os.path.join(
     257            self.workdir, 'sample_studycourse_data.csv')
     258        open(self.csv_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA)
    251259        return
    252260
     
    283291        shutil.rmtree(os.path.dirname(fin_file))
    284292
     293class StudentStudyLevelImporterTest(FunctionalTestCase):
     294
     295    layer = FunctionalLayer
     296
     297    def setUp(self):
     298        super(StudentStudyLevelImporterTest, self).setUp()
     299        self.dc_root = tempfile.mkdtemp()
     300        self.workdir = tempfile.mkdtemp()
     301        app = University()
     302        app['datacenter'].setStoragePath(self.dc_root)
     303        self.getRootFolder()['app'] = app
     304        self.app = self.getRootFolder()['app']
     305        setSite(app)
     306
     307        # Import students with subobjects
     308        student_file = os.path.join(self.workdir, 'sample_student_data.csv')
     309        open(student_file, 'wb').write(STUDENT_SAMPLE_DATA)
     310        num, num_warns, fin_file, fail_file = StudentProcessor().doImport(
     311            student_file, STUDENT_HEADER_FIELDS)
     312        shutil.rmtree(os.path.dirname(fin_file))
     313
     314        # Populate university
     315        self.certificate = createObject('waeup.Certificate')
     316        self.certificate.code = 'CERT1'
     317        self.certificate.application_category = 'basic'
     318        self.certificate.start_level = 200
     319        self.certificate.end_level = 500
     320        self.app['faculties']['fac1'] = Faculty()
     321        self.app['faculties']['fac1']['dep1'] = Department()
     322        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     323            self.certificate)
     324
     325        # Update study courses
     326        studycourse_file = os.path.join(
     327            self.workdir, 'sample_studycourse_data.csv')
     328        open(studycourse_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA)
     329        importer = StudentStudyCourseProcessor()
     330        num, num_warns, fin_file, fail_file = importer.doImport(
     331            studycourse_file, STUDYCOURSE_HEADER_FIELDS,'update')
     332        shutil.rmtree(os.path.dirname(fin_file))
     333
     334        self.importer = StudentStudyLevelProcessor()
     335        self.csv_file = os.path.join(
     336            self.workdir, 'sample_studylevel_data.csv')
     337        open(self.csv_file, 'wb').write(STUDYLEVEL_SAMPLE_DATA)
     338
     339    def tearDown(self):
     340        super(StudentStudyLevelImporterTest, self).tearDown()
     341        shutil.rmtree(self.workdir)
     342        shutil.rmtree(self.dc_root)
     343        clearSite()
     344        return
     345
     346    def test_interface(self):
     347        # Make sure we fulfill the interface contracts.
     348        assert verifyObject(IBatchProcessor, self.importer) is True
     349        assert verifyClass(
     350            IBatchProcessor, StudentStudyLevelProcessor) is True
     351
     352    def test_import(self):
     353        num, num_warns, fin_file, fail_file = self.importer.doImport(
     354            self.csv_file, STUDYLEVEL_HEADER_FIELDS,'create')
     355        self.assertEqual(num_warns,2)
     356        assert self.importer.entryExists(
     357            dict(reg_number='1', level='100'), self.app) is True
     358        studylevel = self.importer.getEntry(
     359            dict(reg_number='1', level='100'), self.app)
     360        self.assertEqual(studylevel.__parent__.certificate.code, u'CERT1')
     361        self.assertEqual(studylevel.level_session, 2008)
     362        self.assertEqual(studylevel.level_verdict, 'A')
     363        self.assertEqual(studylevel.level, 100)
     364        shutil.rmtree(os.path.dirname(fin_file))
     365       
     366
    285367def test_suite():
    286368    suite = unittest.TestSuite()
    287369    for testcase in [
    288370        StudentImporterTest,StudentStudyCourseImporterTest,
    289         ]:
     371        StudentStudyLevelImporterTest,]:
    290372        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
    291373                testcase
     
    293375        )
    294376    return suite
     377
     378
Note: See TracChangeset for help on using the changeset viewer.