Ignore:
Timestamp:
16 Feb 2013, 12:20:06 (12 years ago)
Author:
Henrik Bettermann
Message:

Extend StudentStudyCourseProcessor? so that we can transfer students by import.

File:
1 edited

Legend:

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

    r9919 r9960  
    2727from time import time
    2828from zope.event import notify
    29 from zope.component import createObject
     29from zope.component import createObject, queryUtility
    3030from zope.component.hooks import setSite, clearSite
     31from zope.catalog.interfaces import ICatalog
    3132from zope.interface.verify import verifyClass, verifyObject
    3233from hurry.workflow.interfaces import IWorkflowState
     
    8889
    8990STUDYCOURSE_HEADER_FIELDS = STUDYCOURSE_SAMPLE_DATA.split(
     91    '\n')[0].split(',')
     92
     93TRANSFER_SAMPLE_DATA = open(
     94    os.path.join(os.path.dirname(__file__), 'sample_transfer_data.csv'),
     95    'rb').read()
     96
     97TRANSFER_HEADER_FIELDS = TRANSFER_SAMPLE_DATA.split(
    9098    '\n')[0].split(',')
    9199
     
    571579            self.workdir, 'sample_studycourse_data.csv')
    572580        open(self.csv_file, 'wb').write(STUDYCOURSE_SAMPLE_DATA)
     581        self.csv_file_transfer = os.path.join(
     582            self.workdir, 'sample_transfer_data.csv')
     583        open(self.csv_file_transfer, 'wb').write(TRANSFER_SAMPLE_DATA)
    573584        return
    574585
     
    639650            dict(reg_number='1', current_level=100), self.app)
    640651        self.assertEqual(err, 'No certificate to check level.')
     652        # When transferring students the method also checks
     653        # if the former studycourse is complete.
     654        err = self.processor.checkUpdateRequirements(
     655            self.student['studycourse'],
     656            dict(reg_number='1', certificate='CERT1', current_level=200,
     657            entry_mode='transfer'), self.app)
     658        self.assertEqual(err, 'Former study course record incomplete.')
     659        self.student['studycourse'].certificate = self.certificate
     660        self.student['studycourse'].entry_session = 2005
     661        # The method doesn't care if current_level
     662        # is not in range of CERT1. This is done by checkConversion
     663        # if certificate is in row.
     664        err = self.processor.checkUpdateRequirements(
     665            self.student['studycourse'],
     666            dict(reg_number='1', certificate='CERT1', current_level=200,
     667            entry_mode='transfer'), self.app)
     668        self.assertTrue(err is None)
    641669
    642670    def test_import(self):
     
    649677        self.assertEqual(studycourse.certificate.code, u'CERT1')
    650678        shutil.rmtree(os.path.dirname(fin_file))
     679
     680    def test_import_transfer(self):
     681        self.certificate2 = createObject('waeup.Certificate')
     682        self.certificate2.code = 'CERT2'
     683        self.certificate2.application_category = 'basic'
     684        self.certificate2.start_level = 200
     685        self.certificate2.end_level = 500
     686        self.certificate2.study_mode = u'ug_pt'
     687        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     688            self.certificate2)
     689        num, num_warns, fin_file, fail_file = self.processor.doImport(
     690            self.csv_file_transfer, TRANSFER_HEADER_FIELDS,'update')
     691        self.assertEqual(num_warns,0)
     692        self.assertEqual(self.student['studycourse'].certificate.code, 'CERT2')
     693        self.assertEqual(self.student['studycourse_1'].certificate.code, 'CERT1')
     694        self.assertEqual(self.student['studycourse'].entry_mode, 'transfer')
     695        self.assertEqual(self.student['studycourse_1'].entry_mode, 'ug_ft')
     696        self.assertEqual(self.student.current_mode, 'ug_pt')
     697        shutil.rmtree(os.path.dirname(fin_file))
     698        # Transer has bee logged.
     699        logcontent = open(self.logfile).read()
     700        self.assertTrue(
     701            'INFO - system - K1000000 - transferred from CERT1 to CERT2\n'
     702            in logcontent)
     703        self.assertTrue(
     704            'INFO - system - '
     705            'StudentStudyCourse Processor (update only) - '
     706            'sample_transfer_data - K1000000 - updated: entry_mode=transfer, '
     707            'certificate=CERT2, current_session=2009, current_level=300'
     708            in logcontent)
     709        # A history message has been added.
     710        history = ' '.join(self.student.history.messages)
     711        self.assertTrue(
     712            "Transferred from CERT1 to CERT2 by system" in history)
     713        # The catalog has been updated
     714        cat = queryUtility(ICatalog, name='students_catalog')
     715        results = list(
     716            cat.searchResults(
     717            certcode=('CERT2', 'CERT2')))
     718        self.assertTrue(results[0] is self.student)
     719        results = list(
     720            cat.searchResults(
     721            current_session=(2009, 2009)))
     722        self.assertTrue(results[0] is self.student)
     723        results = list(
     724            cat.searchResults(
     725            certcode=('CERT1', 'CERT1')))
     726        self.assertEqual(len(results), 0)
    651727
    652728class StudentStudyLevelProcessorTest(StudentImportExportSetup):
Note: See TracChangeset for help on using the changeset viewer.