Ignore:
Timestamp:
6 Apr 2012, 20:43:18 (13 years ago)
Author:
Henrik Bettermann
Message:

See last revision.

Location:
main/waeup.uniben/trunk/src/waeup/uniben/applicants
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/applicants/tests.py

    r8053 r8056  
    1919import shutil
    2020import tempfile
     21import datetime
     22from zope.intid.interfaces import IIntIds
    2123from zope.interface.verify import verifyClass, verifyObject
    2224from zope.component.hooks import setSite, clearSite
    23 from zope.component import createObject
     25from zope.component import createObject, getUtility
     26from zope.catalog.interfaces import ICatalog
    2427from zope.testbrowser.testing import Browser
    2528from waeup.kofa.app import University
     
    2831from waeup.kofa.testing import FunctionalTestCase
    2932from waeup.kofa.applicants.container import ApplicantsContainer
     33from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
     34from waeup.kofa.interfaces import IBatchProcessor
    3035from waeup.uniben.testing import FunctionalLayer
    31 from waeup.kofa.interfaces import IBatchProcessor
     36from waeup.uniben.applicants.export import ApplicantsExporter
     37
    3238
    3339class ApplicantUITest(FunctionalTestCase):
     
    145151        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    146152        return
     153
     154class ApplicantsExporterTest(ApplicantImportExportSetup):
     155
     156    layer = FunctionalLayer
     157
     158    def setUp(self):
     159        super(ApplicantsExporterTest, self).setUp()
     160        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     161        self.cat = getUtility(ICatalog, name='applicants_catalog')
     162        self.intids = getUtility(IIntIds)
     163        return
     164
     165    def setup_applicant(self, applicant):
     166        # set predictable values for `applicant`
     167        applicant.reg_number = u'123456'
     168        applicant.applicant_id = u'dp2011_654321'
     169        applicant.firstname = u'Anna'
     170        applicant.lastname = u'Tester'
     171        applicant.middlename = u'M.'
     172        applicant.date_of_birth = datetime.date(1981, 2, 4)
     173        applicant.sex = 'f'
     174        applicant.email = 'anna@sample.com'
     175        applicant.phone = u'+234-123-12345'
     176        applicant.course1 = self.certificate
     177        applicant.course2 = self.certificate
     178        applicant.course_admitted = self.certificate
     179        applicant.notice = u'Some notice\nin lines.'
     180        applicant.screening_score = 98
     181        applicant.screening_venue = u'Exam Room'
     182        applicant.password = 'any password'
     183        return applicant
     184
     185    def test_export_all(self):
     186        # we can export all applicants in a portal
     187        # set values we can expect in export file
     188        self.applicant = self.setup_applicant(self.applicant)
     189        exporter = ApplicantsExporter()
     190        exporter.export_all(self.app, self.outfile)
     191        result = open(self.outfile, 'rb').read()
     192        # The exported records do contain a real date in their
     193        # history dict. We skip the date and split the comparison
     194        # into two parts.
     195        self.assertTrue(
     196            'applicant_id,application_date,application_number,course1,course2,'
     197            'course_admitted,date_of_birth,display_fullname,email,emp2_end,'
     198            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,emp_reason,'
     199            'emp_start,employer,employer2,firstname,history,hq_degree,hq_disc,'
     200            'hq_matric_no,hq_school,hq_session,hq_type,lastname,lga,locked,'
     201            'middlename,notice,password,perm_address,phone,pp_school,reg_number,'
     202            'screening_score,screening_venue,sex,state,student_id'
     203            in result)
     204        self.assertTrue(
     205            'Application initialized by system\'],,,,,,,Tester,foreigner,0,M.,'
     206            '"Some notice\nin lines.",any password,,+234-123-12345,,123456,98,'
     207            'Exam Room,f,initialized,' in result)
     208        return
Note: See TracChangeset for help on using the changeset viewer.