Ignore:
Timestamp:
22 Feb 2022, 12:48:36 (3 years ago)
Author:
Henrik Bettermann
Message:

Add exporters for previous study course data.

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

Legend:

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

    r16812 r16827  
    2121import datetime
    2222from cStringIO import StringIO
    23 from zope.component import queryUtility, getUtility
     23from zope.component import queryUtility, getUtility, createObject
    2424from zope.event import notify
    2525from zope.interface.verify import verifyObject, verifyClass
     
    3030from waeup.kofa.university.certificate import CertificateCourse
    3131from waeup.kofa.students.export import (
    32     StudentExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,
    33     CourseTicketExporter, StudentPaymentExporter, BedTicketExporter,
     32    StudentExporter,
     33    StudentStudyCourseExporter,
     34    FirstStudentStudyCourseExporter,
     35    SecondStudentStudyCourseExporter,
     36    StudentStudyLevelExporter,
     37    FirstStudentStudyLevelExporter,
     38    SecondStudentStudyLevelExporter,
     39    CourseTicketExporter,
     40    FirstCourseTicketExporter,
     41    SecondCourseTicketExporter,
     42    StudentPaymentExporter, BedTicketExporter,
    3443    SchoolFeePaymentsOverviewExporter, StudyLevelsOverviewExporter,
    3544    ComboCardDataExporter, DataForBursaryExporter,
     
    516525        return
    517526
     527class PreviousStudyCourseExporterTests(StudentImportExportSetup):
     528
     529    layer = FunctionalLayer
     530
     531    def setUp(self):
     532        super(PreviousStudyCourseExporterTests, self).setUp()
     533        self.setup_for_export()
     534        self.certificate2 = createObject('waeup.Certificate')
     535        self.certificate2.code = 'CERT2'
     536        self.certificate2.application_category = 'basic'
     537        self.certificate2.start_level = 200
     538        self.certificate2.end_level = 500
     539        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     540            self.certificate2)
     541        return
     542
     543    def test_export_studycourses(self):
     544        self.setup_student(self.student)
     545        exporter = FirstStudentStudyCourseExporter()
     546        exporter.export_all(self.app, self.outfile)
     547        result = open(self.outfile, 'rb').read()
     548        self.assertEqual(
     549            result,
     550            'certificate,current_level,current_session,current_verdict,'
     551            'entry_mode,entry_session,previous_verdict,student_id\r\n'
     552            )
     553        error = self.student.transfer(self.certificate2, current_session=2013)
     554        self.assertTrue(error == None)
     555        exporter.export_all(self.app, self.outfile)
     556        result = open(self.outfile, 'rb').read()
     557        self.assertEqual(
     558            result,
     559            'certificate,current_level,current_session,current_verdict,'
     560            'entry_mode,entry_session,previous_verdict,student_id\r\n'
     561            'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n')
     562        error = self.student.transfer(self.certificate,
     563                                      current_session=2014,
     564                                      current_level=300)
     565        self.assertTrue(error == None)
     566        exporter = SecondStudentStudyCourseExporter()
     567        exporter.export_all(self.app, self.outfile)
     568        result = open(self.outfile, 'rb').read()
     569        self.assertEqual(
     570            result,
     571            'certificate,current_level,current_session,current_verdict,'
     572            'entry_mode,entry_session,previous_verdict,student_id\r\n'
     573            'CERT2,,2013,,transfer,2010,,A111111\r\n')
     574        exporter = StudentStudyCourseExporter()
     575        exporter.export_all(self.app, self.outfile)
     576        result = open(self.outfile, 'rb').read()
     577        self.assertEqual(
     578            result,
     579            'certificate,current_level,current_session,current_verdict,'
     580            'entry_mode,entry_session,previous_verdict,student_id\r\n'
     581            'CERT1,300,2014,,transfer,2010,,A111111\r\n')
     582        return
     583
     584    def test_export_studylevels(self):
     585        self.setup_student(self.student)
     586        exporter = FirstStudentStudyLevelExporter()
     587        exporter.export_all(self.app, self.outfile)
     588        result = open(self.outfile, 'rb').read()
     589        self.assertEqual(
     590            result,
     591            'gpa,level,level_session,level_verdict,total_credits,'
     592            'transcript_remark,validated_by,validation_date,student_id,'
     593            'number_of_tickets,certcode\r\n'
     594            )
     595        error = self.student.transfer(self.certificate2, current_session=2013)
     596        self.assertTrue(error == None)
     597        exporter.export_all(self.app, self.outfile)
     598        result = open(self.outfile, 'rb').read()
     599        self.assertEqual(
     600            result,
     601            'gpa,level,level_session,level_verdict,total_credits,'
     602            'transcript_remark,validated_by,validation_date,student_id,'
     603            'number_of_tickets,certcode\r\n'
     604            '0.00,100,2012,A,100,,,,A111111,1,CERT1\r\n' )
     605        study_level = StudentStudyLevel()
     606        study_level.level_session = 2015
     607        study_level.level_verdict = "C"
     608        study_level.level = 400
     609        self.student['studycourse'].addStudentStudyLevel(
     610            self.certificate2, study_level)
     611        error = self.student.transfer(self.certificate,
     612                                      current_session=2014,
     613                                      current_level=300)
     614        self.assertTrue(error == None)
     615        exporter = SecondStudentStudyLevelExporter()
     616        exporter.export_all(self.app, self.outfile)
     617        result = open(self.outfile, 'rb').read()
     618        self.assertEqual(
     619            result,
     620            'gpa,level,level_session,level_verdict,total_credits,'
     621            'transcript_remark,validated_by,validation_date,student_id,'
     622            'number_of_tickets,certcode\r\n'
     623            '0.00,400,2015,C,0,,,,A111111,0,CERT2\r\n')
     624        exporter = StudentStudyLevelExporter()
     625        exporter.export_all(self.app, self.outfile)
     626        result = open(self.outfile, 'rb').read()
     627        self.assertEqual(
     628            result,
     629            'gpa,level,level_session,level_verdict,total_credits,'
     630            'transcript_remark,validated_by,validation_date,student_id,'
     631            'number_of_tickets,certcode\r\n')
     632        return
     633
     634    def test_export_coursetickets(self):
     635        self.setup_student(self.student)
     636        exporter = FirstCourseTicketExporter()
     637        exporter.export_all(self.app, self.outfile)
     638        result = open(self.outfile, 'rb').read()
     639        self.assertEqual(
     640            result,
     641            'automatic,carry_over,code,course_category,credits,dcode,'
     642            'fcode,level,level_session,mandatory,outstanding,passmark,'
     643            'score,semester,ticket_session,title,student_id,certcode,'
     644            'display_fullname\r\n'
     645            )
     646        error = self.student.transfer(self.certificate2, current_session=2013)
     647        self.assertTrue(error == None)
     648        exporter.export_all(self.app, self.outfile)
     649        result = open(self.outfile, 'rb').read()
     650        self.assertEqual(
     651            result,
     652            'automatic,carry_over,code,course_category,credits,dcode,'
     653            'fcode,level,level_session,mandatory,outstanding,passmark,'
     654            'score,semester,ticket_session,title,student_id,certcode,'
     655            'display_fullname\r\n'
     656            '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,'
     657            'A111111,CERT1,Anna M. Tester\r\n')
     658        study_level = StudentStudyLevel()
     659        study_level.level_session = 2015
     660        study_level.level_verdict = "C"
     661        study_level.level = 400
     662        self.student['studycourse'].addStudentStudyLevel(
     663            self.certificate2, study_level)
     664        ticket = CourseTicket()
     665        ticket.automatic = True
     666        ticket.carry_over = True
     667        ticket.code = u'CRS9'
     668        ticket.title = u'Course 9'
     669        ticket.fcode = u'FAC9'
     670        ticket.dcode = u'DEP9'
     671        ticket.credits = 150
     672        ticket.passmark = 100
     673        ticket.semester = 2
     674        study_level[ticket.code] = ticket
     675        error = self.student.transfer(self.certificate,
     676                                      current_session=2014,
     677                                      current_level=300)
     678        self.assertTrue(error == None)
     679        exporter = SecondCourseTicketExporter()
     680        exporter.export_all(self.app, self.outfile)
     681        result = open(self.outfile, 'rb').read()
     682        self.assertEqual(
     683            result,
     684            'automatic,carry_over,code,course_category,credits,dcode,'
     685            'fcode,level,level_session,mandatory,outstanding,passmark,'
     686            'score,semester,ticket_session,title,student_id,certcode,'
     687            'display_fullname\r\n1,1,CRS9,,150,DEP9,FAC9,400,2015,0,0,'
     688            '100,,2,,Course 9,A111111,CERT2,Anna M. Tester\r\n')
     689        exporter = CourseTicketExporter()
     690        exporter.export_all(self.app, self.outfile)
     691        result = open(self.outfile, 'rb').read()
     692        self.assertEqual(
     693            result,
     694            'automatic,carry_over,code,course_category,credits,dcode,'
     695            'fcode,level,level_session,mandatory,outstanding,passmark,'
     696            'score,semester,ticket_session,title,student_id,certcode,'
     697            'display_fullname\r\n'
     698            )
     699        return
    518700
    519701class StudentStudyLevelExporterTest(StudentImportExportSetup):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py

    r15416 r16827  
    160160        super(StudentRemovalTests, self).setUp()
    161161        self.setup_for_export()
     162        self.certificate2 = createObject('waeup.Certificate')
     163        self.certificate2.code = 'CERT2'
     164        self.certificate2.application_category = 'basic'
     165        self.certificate2.start_level = 200
     166        self.certificate2.end_level = 500
     167        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     168            self.certificate2)
    162169        return
    163170
     
    190197            IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
    191198        for name in STUDENT_BACKUP_EXPORTER_NAMES:
     199            if name[-2:-1] == '_':
     200                continue
    192201            csv_path = os.path.join(del_dir, '%s.csv' % name)
    193202            self.assertTrue(os.path.isfile(csv_path))
     
    218227            IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
    219228        for name in STUDENT_BACKUP_EXPORTER_NAMES:
     229            if name[-2:-1] == '_':
     230                continue
    220231            csv_path = os.path.join(del_dir, '%s.csv' % name)
    221232            self.assertTrue(os.path.isfile(csv_path))
     
    223234            # We expect 3 lines output including a linebreak at end of file.
    224235            self.assertEqual(len(contents), 3)
     236        return
     237
     238    def test_backup_single_graduated_transferred_data(self):
     239        del_dir = self.app['datacenter'].graduated_path
     240        # when a single graduated student is removed, the data is backed up
     241        # somewhere else including previous study courses
     242        self.setup_student(self.student)
     243        error = self.student.transfer(self.certificate2, current_session=2013)
     244        self.assertTrue(error == None)
     245        IWorkflowState(self.student).setState('graduated')
     246        handle_student_removed(self.student, None)
     247        # The previous study course data were put into CSV files
     248        name = 'studentstudycourses_1'
     249        csv_path = os.path.join(del_dir, '%s.csv' % name)
     250        self.assertTrue(os.path.isfile(csv_path))
     251        contents = open(csv_path, 'rb').read().split('\r\n')
     252        # We expect 3 lines output including a linebreak at end of file.
     253        self.assertEqual(len(contents), 3)
     254        name = 'studentstudycourses_2'
     255        csv_path = os.path.join(del_dir, '%s.csv' % name)
     256        self.assertTrue(os.path.isfile(csv_path))
     257        contents = open(csv_path, 'rb').read().split('\r\n')
     258        # We expect only 2 lines output including a linebreak at end of file.
     259        self.assertEqual(len(contents), 2)
     260        name = 'studentstudylevels_1'
     261        csv_path = os.path.join(del_dir, '%s.csv' % name)
     262        self.assertTrue(os.path.isfile(csv_path))
     263        contents = open(csv_path, 'rb').read().split('\r\n')
     264        # We expect 3 lines output including a linebreak at end of file.
     265        self.assertEqual(len(contents), 3)
     266        name = 'coursetickets_1'
     267        csv_path = os.path.join(del_dir, '%s.csv' % name)
     268        self.assertTrue(os.path.isfile(csv_path))
     269        contents = open(csv_path, 'rb').read().split('\r\n')
     270        # We expect 3 lines output including a linebreak at end of file.
     271        self.assertEqual(len(contents), 3)
    225272        return
    226273
Note: See TracChangeset for help on using the changeset viewer.