Ignore:
Timestamp:
27 Mar 2014, 10:45:43 (11 years ago)
Author:
Henrik Bettermann
Message:

Adapt exporters and batch processors to customized interfaces.

Location:
main/kofacustom.skeleton/trunk/src/kofacustom/skeleton
Files:
4 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.skeleton/trunk/src/kofacustom/skeleton/applicants/tests/test_browser.py

    r10765 r11543  
    1919Test the applicant-related UI components.
    2020"""
     21import os
     22import datetime
     23from zope.component import createObject, getUtility
     24from zope.catalog.interfaces import ICatalog
     25from zope.intid.interfaces import IIntIds
    2126from kofacustom.skeleton.testing import FunctionalLayer
    2227from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
     28from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
     29from kofacustom.skeleton.applicants.export import CustomApplicantsExporter
     30from kofacustom.skeleton.applicants.batching import CustomApplicantProcessor
    2331
    2432class CustomApplicantUITests(ApplicantsFullSetup):
     
    2634
    2735    layer = FunctionalLayer
     36
     37class ApplicantsExporterTest(ApplicantImportExportSetup):
     38
     39    layer = FunctionalLayer
     40
     41    def setUp(self):
     42        super(ApplicantsExporterTest, self).setUp()
     43        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     44        self.cat = getUtility(ICatalog, name='applicants_catalog')
     45        self.intids = getUtility(IIntIds)
     46        return
     47
     48    def setup_applicant(self, applicant):
     49        # set predictable values for `applicant`
     50        applicant.reg_number = u'123456'
     51        applicant.applicant_id = u'dp2011_654321'
     52        applicant.firstname = u'Anna'
     53        applicant.lastname = u'Tester'
     54        applicant.middlename = u'M.'
     55        applicant.nationality = u'NG'
     56        applicant.date_of_birth = datetime.date(1981, 2, 4)
     57        applicant.sex = 'f'
     58        applicant.email = 'anna@sample.com'
     59        applicant.phone = u'+234-123-12345'
     60        applicant.course1 = self.certificate
     61        applicant.course2 = self.certificate
     62        applicant.course_admitted = self.certificate
     63        applicant.notice = u'Some notice\nin lines.'
     64        applicant.screening_score = 98
     65        applicant.screening_venue = u'Exam Room'
     66        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
     67        applicant.password = 'any password'
     68        return applicant
     69
     70    def test_export_reimport_all(self):
     71        # we can export all applicants in a portal
     72        # set values we can expect in export file
     73        self.applicant = self.setup_applicant(self.applicant)
     74        exporter = CustomApplicantsExporter()
     75        exporter.export_all(self.app, self.outfile)
     76        result = open(self.outfile, 'rb').read()
     77        self.assertMatches(result,
     78            'aggregate,applicant_id,application_date,application_number,'
     79            'course1,course2,course_admitted,date_of_birth,display_fullname,'
     80            'email,emp2_end,emp2_position,emp2_reason,emp2_start,emp_end,'
     81            'emp_position,emp_reason,emp_start,employer,employer2,'
     82            'firstname,history,hq_degree,hq_disc,hq_matric_no,hq_school,'
     83            'hq_session,hq_type,jamb_score,jamb_subjects,lastname,lga,'
     84            'locked,middlename,nationality,notice,nysc_lga,nysc_year,'
     85            'password,phone,pp_school,presently_inst,reg_number,'
     86            'result_uploaded,screening_date,screening_score,'
     87            'screening_venue,sex,special_application,'
     88            'state,student_id,suspended,container_code\r\n'
     89            ',dp2011_654321,,654321,CERT1,CERT1,CERT1,1981-02-04#,'
     90            'Anna M. Tester,anna@sample.com,,,,,,,,,,,Anna,'
     91            '[u\'2012-10-28 21:27:52 WAT - Application initialized by system\']'
     92            ',,,,,,,,,Tester,,0,M.,NG,"Some notice\nin lines.",,,'
     93            'any password,+234-123-12345#,,,123456,,'
     94            '"Saturday, 16th June 2012 2:00:00 PM",98,Exam Room,f,,initialized,,'
     95            '0,dp2011\r\n')
     96        # We can import the same file if we ignore some columns.
     97        # Since the applicants_catalog hasn't been notified, the same
     98        # record with same reg_number can be imported twice.
     99        processor = CustomApplicantProcessor()
     100        result = processor.doImport(
     101            self.outfile,
     102            ['aggreagate','ignore_applicant_id','application_date',
     103            'ignore_application_number','course1','course2',
     104            'course_admitted','date_of_birth','ignore3','email','emp2_end',
     105            'emp2_position','emp2_reason','emp2_start','emp_end','emp_position',
     106            'emp_reason','emp_start','employer','employer2','firstname','ignore4',
     107            'hq_degree','hq_disc','hq_matric_no','hq_school','hq_session','hq_type',
     108            'jamb_score','jamb_subjects','lastname','lga','locked','middlename',
     109            'nationality','notice','nysc_lga',
     110            'nysc_year','password','phone','pp_school','presently_inst',
     111            'reg_number','result_uploaded',
     112            'screening_date','screening_score','screening_venue','sex',
     113            'special_application',
     114            'state','student_id','suspended','container_code'],
     115            mode='create')
     116        num_succ, num_fail, finished_path, failed_path = result
     117        #content = open(failed_path).read()
     118        self.assertEqual(num_succ,1)
     119        self.assertEqual(num_fail,0)
     120        # Now we ignore also the container_code and import the same file
     121        # in update mode which means that INigeriaApplicantUpdateByRegNo
     122        # is used for field conversion. applicant_id must be ignored
     123        # too since the previous import has notified the applicants_catalog
     124        # so that the portal 'knows' that reg_number is in use.
     125        processor = CustomApplicantProcessor()
     126        result = processor.doImport(
     127            self.outfile,
     128            ['aggregate','ignore_applicant_id','application_date',
     129            'ignore_application_number','course1','course2',
     130            'course_admitted','date_of_birth','ignore3','email','emp2_end',
     131            'emp2_position','emp2_reason','emp2_start','emp_end','emp_position',
     132            'emp_reason','emp_start','employer','employer2','firstname','ignore4',
     133            'hq_degree','hq_disc','hq_matric_no','hq_school','hq_session','hq_type',
     134            'jamb_score','jamb_subjects','lastname','lga','locked','middlename',
     135            'nationality','notice','nysc_lga',
     136            'nysc_year','password','phone','pp_school','presently_inst',
     137            'reg_number','result_uploaded','screening_date','screening_score',
     138            'screening_venue','sex','special_application',
     139            'state','student_id','suspended','ignore_container_code'],
     140            mode='update')
     141        num_succ, num_fail, finished_path, failed_path = result
     142        self.assertEqual(num_succ,1)
     143        self.assertEqual(num_fail,0)
     144        return
Note: See TracChangeset for help on using the changeset viewer.