Ignore:
Timestamp:
22 Mar 2012, 07:21:20 (13 years ago)
Author:
Henrik Bettermann
Message:

Add verdict processor.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/sample_student_data.csv

    r7643 r7951  
    1 student_id,firstname,lastname,reg_number,date_of_birth,matric_number,email,phone
    2 X666666,Aaren,Pieri,1,1990-01-02,100000,aa@aa.ng,1234
    3 ,Aaren,Finau,2,1990-01-03,100001,aa@aa.ng,1234
    4 ,Aaren,Berson,3,1990-01-04,100002,aa@aa.ng,1234
     1student_id,firstname,lastname,reg_number,date_of_birth,matric_number,email,phone,reg_state
     2X666666,Aaren,Pieri,1,1990-01-02,100000,aa@aa.ng,1234,courses validated
     3,Aaren,Finau,2,1990-01-03,100001,aa@aa.ng,1234,courses validated
     4,Aaren,Berson,3,1990-01-04,100002,aa@aa.ng,1234,courses validated
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r7947 r7951  
    3434    StudentProcessor, StudentStudyCourseProcessor,
    3535    StudentStudyLevelProcessor, CourseTicketProcessor,
    36     StudentOnlinePaymentProcessor)
     36    StudentOnlinePaymentProcessor, StudentVerdictProcessor)
    3737from waeup.kofa.students.student import Student
    3838from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase
     
    6565
    6666STUDYCOURSE_HEADER_FIELDS = STUDYCOURSE_SAMPLE_DATA.split(
     67    '\n')[0].split(',')
     68
     69VERDICT_SAMPLE_DATA = open(
     70    os.path.join(os.path.dirname(__file__), 'sample_verdict_data.csv'),
     71    'rb').read()
     72
     73VERDICT_HEADER_FIELDS = VERDICT_SAMPLE_DATA.split(
    6774    '\n')[0].split(',')
    6875
     
    108115        self.app = self.getRootFolder()['app']
    109116        setSite(app)
    110 
    111         # Import students with subobjects
    112         #student_file = os.path.join(self.workdir, 'sample_student_data.csv')
    113         #open(student_file, 'wb').write(STUDENT_SAMPLE_DATA)
    114         #num, num_warns, fin_file, fail_file = StudentProcessor().doImport(
    115         #    student_file, STUDENT_HEADER_FIELDS)
    116         #shutil.rmtree(os.path.dirname(fin_file))
    117117
    118118        # Populate university
     
    126126        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
    127127            self.certificate)
    128 
    129         self.importer = StudentStudyCourseProcessor()
    130         self.csv_file = os.path.join(
    131             self.workdir, 'sample_studycourse_data.csv')
    132         open(self.csv_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA)
    133128        return
    134129
     
    297292
    298293
    299 class StudentStudyCourseProcessorTest(FunctionalTestCase):
    300 
    301     layer = FunctionalLayer
     294class StudentStudyCourseProcessorTest(StudentImportExportSetup):
    302295
    303296    def setUp(self):
    304297        super(StudentStudyCourseProcessorTest, self).setUp()
    305         self.dc_root = tempfile.mkdtemp()
    306         self.workdir = tempfile.mkdtemp()
    307         app = University()
    308         app['datacenter'].setStoragePath(self.dc_root)
    309         self.getRootFolder()['app'] = app
    310         self.app = self.getRootFolder()['app']
    311         setSite(app)
    312298
    313299        # Import students with subobjects
     
    318304        shutil.rmtree(os.path.dirname(fin_file))
    319305
    320         # Populate university
    321         self.certificate = createObject('waeup.Certificate')
    322         self.certificate.code = 'CERT1'
    323         self.certificate.application_category = 'basic'
    324         self.certificate.start_level = 200
    325         self.certificate.end_level = 500
    326         self.app['faculties']['fac1'] = Faculty()
    327         self.app['faculties']['fac1']['dep1'] = Department()
    328         self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
    329             self.certificate)
    330 
    331306        self.processor = StudentStudyCourseProcessor()
    332307        self.csv_file = os.path.join(
     
    335310        return
    336311
    337     def tearDown(self):
    338         super(StudentStudyCourseProcessorTest, self).tearDown()
    339         shutil.rmtree(self.workdir)
    340         shutil.rmtree(self.dc_root)
    341         clearSite()
    342         return
    343 
    344312    def test_interface(self):
    345313        # Make sure we fulfill the interface contracts.
     
    384352        shutil.rmtree(os.path.dirname(fin_file))
    385353
    386 class StudentStudyLevelProcessorTest(FunctionalTestCase):
    387 
    388     layer = FunctionalLayer
     354class StudentVerdictProcessorTest(StudentImportExportSetup):
     355
    389356
    390357    def setUp(self):
    391         super(StudentStudyLevelProcessorTest, self).setUp()
    392         self.dc_root = tempfile.mkdtemp()
    393         self.workdir = tempfile.mkdtemp()
    394         app = University()
    395         app['datacenter'].setStoragePath(self.dc_root)
    396         self.getRootFolder()['app'] = app
    397         self.app = self.getRootFolder()['app']
    398         setSite(app)
     358        super(StudentVerdictProcessorTest, self).setUp()
    399359
    400360        # Import students with subobjects
     
    404364            student_file, STUDENT_HEADER_FIELDS)
    405365        shutil.rmtree(os.path.dirname(fin_file))
    406 
    407         # Populate university
    408         self.certificate = createObject('waeup.Certificate')
    409         self.certificate.code = 'CERT1'
    410         self.certificate.application_category = 'basic'
    411         self.certificate.start_level = 200
    412         self.certificate.end_level = 500
    413         self.app['faculties']['fac1'] = Faculty()
    414         self.app['faculties']['fac1']['dep1'] = Department()
    415         self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
    416             self.certificate)
    417366
    418367        # Update study courses
     
    425374        shutil.rmtree(os.path.dirname(fin_file))
    426375
     376        self.processor = StudentVerdictProcessor()
     377        self.csv_file = os.path.join(
     378            self.workdir, 'sample_verdict_data.csv')
     379        open(self.csv_file, 'wb').write(VERDICT_SAMPLE_DATA)
     380        return
     381
     382    def test_import(self):
     383        num, num_warns, fin_file, fail_file = self.processor.doImport(
     384            self.csv_file, VERDICT_HEADER_FIELDS,'update')
     385        self.assertEqual(num_warns,0)
     386        studycourse = self.processor.getEntry(dict(reg_number='1'), self.app)
     387        self.assertEqual(studycourse.certificate.code, u'CERT1')
     388        shutil.rmtree(os.path.dirname(fin_file))
     389
     390
     391class StudentStudyLevelProcessorTest(StudentImportExportSetup):
     392
     393    def setUp(self):
     394        super(StudentStudyLevelProcessorTest, self).setUp()
     395
     396        # Import students with subobjects
     397        student_file = os.path.join(self.workdir, 'sample_student_data.csv')
     398        open(student_file, 'wb').write(STUDENT_SAMPLE_DATA)
     399        num, num_warns, fin_file, fail_file = StudentProcessor().doImport(
     400            student_file, STUDENT_HEADER_FIELDS)
     401        shutil.rmtree(os.path.dirname(fin_file))
     402
     403        # Update study courses
     404        studycourse_file = os.path.join(
     405            self.workdir, 'sample_studycourse_data.csv')
     406        open(studycourse_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA)
     407        processor = StudentStudyCourseProcessor()
     408        num, num_warns, fin_file, fail_file = processor.doImport(
     409            studycourse_file, STUDYCOURSE_HEADER_FIELDS,'update')
     410        shutil.rmtree(os.path.dirname(fin_file))
     411
    427412        self.processor = StudentStudyLevelProcessor()
    428413        self.csv_file = os.path.join(
    429414            self.workdir, 'sample_studylevel_data.csv')
    430415        open(self.csv_file, 'wb').write(STUDYLEVEL_SAMPLE_DATA)
    431 
    432     def tearDown(self):
    433         super(StudentStudyLevelProcessorTest, self).tearDown()
    434         shutil.rmtree(self.workdir)
    435         shutil.rmtree(self.dc_root)
    436         clearSite()
    437         return
    438416
    439417    def test_interface(self):
     
    471449       
    472450
    473 class CourseTicketProcessorTest(FunctionalTestCase):
    474 
    475     layer = FunctionalLayer
     451class CourseTicketProcessorTest(StudentImportExportSetup):
    476452
    477453    def setUp(self):
    478454        super(CourseTicketProcessorTest, self).setUp()
    479         self.dc_root = tempfile.mkdtemp()
    480         self.workdir = tempfile.mkdtemp()
    481         app = University()
    482         app['datacenter'].setStoragePath(self.dc_root)
    483         self.getRootFolder()['app'] = app
    484         self.app = self.getRootFolder()['app']
    485         setSite(app)
    486455
    487456        # Import students with subobjects
     
    492461        shutil.rmtree(os.path.dirname(fin_file))
    493462
    494         # Populate university
    495         self.certificate = createObject('waeup.Certificate')
    496         self.certificate.code = 'CERT1'
    497         self.certificate.application_category = 'basic'
    498         self.certificate.start_level = 200
    499         self.certificate.end_level = 500
    500         self.app['faculties']['fac1'] = Faculty()
    501         self.app['faculties']['fac1']['dep1'] = Department()
    502         self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
    503             self.certificate)
     463        # Add course and course referrer
    504464        self.course = createObject('waeup.Course')
    505465        self.course.code = 'COURSE1'
     
    534494            self.workdir, 'sample_courseticket_data.csv')
    535495        open(self.csv_file, 'wb').write(COURSETICKET_SAMPLE_DATA)
    536 
    537     def tearDown(self):
    538         super(CourseTicketProcessorTest, self).tearDown()
    539         shutil.rmtree(self.workdir)
    540         shutil.rmtree(self.dc_root)
    541         clearSite()
    542         return
    543496
    544497    def test_interface(self):
     
    579532        shutil.rmtree(os.path.dirname(fin_file))
    580533
    581 class PaymentProcessorTest(FunctionalTestCase):
    582 
    583     layer = FunctionalLayer
     534class PaymentProcessorTest(StudentImportExportSetup):
    584535
    585536    def setUp(self):
    586537        super(PaymentProcessorTest, self).setUp()
    587         self.dc_root = tempfile.mkdtemp()
    588         self.workdir = tempfile.mkdtemp()
    589         app = University()
    590         app['datacenter'].setStoragePath(self.dc_root)
    591         self.getRootFolder()['app'] = app
    592         self.app = self.getRootFolder()['app']
    593         setSite(app)
    594538
    595539        # Add student with payment
     
    616560            self.workdir, 'sample_payment_data.csv')
    617561        open(self.csv_file, 'wb').write(PAYMENT_SAMPLE_DATA)
    618 
    619     def tearDown(self):
    620         super(PaymentProcessorTest, self).tearDown()
    621         shutil.rmtree(self.workdir)
    622         shutil.rmtree(self.dc_root)
    623         clearSite()
    624         return
    625562
    626563    def test_interface(self):
     
    690627        StudentProcessorTest,StudentStudyCourseProcessorTest,
    691628        StudentStudyLevelProcessorTest,CourseTicketProcessorTest,
    692         PaymentProcessorTest,]:
     629        PaymentProcessorTest,StudentVerdictProcessorTest]:
    693630        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
    694631                testcase
Note: See TracChangeset for help on using the changeset viewer.