Ignore:
Timestamp:
17 Jun 2016, 07:46:34 (8 years ago)
Author:
Henrik Bettermann
Message:

Add ApplicantPaymentExporter.

File:
1 edited

Legend:

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

    r13080 r13949  
    66import unittest
    77from zope.catalog.interfaces import ICatalog
    8 from zope.component import queryUtility, getUtility
     8from zope.component import queryUtility, getUtility, createObject
    99from zope.interface.verify import verifyObject, verifyClass
    1010from zope.intid.interfaces import IIntIds
    1111from waeup.kofa.applicants import ApplicantsContainer
    1212from waeup.kofa.applicants.export import (
    13     ApplicantsContainerExporter, ApplicantExporter)
     13    ApplicantsContainerExporter, ApplicantExporter,
     14    ApplicantPaymentExporter)
    1415from waeup.kofa.applicants.interfaces import (
    1516    AppCatSource, ApplicationTypeSource)
     
    233234            in result)
    234235        return
     236
     237
     238class ApplicantPaymentExporterTest(ApplicantImportExportSetup):
     239
     240    layer = FunctionalLayer
     241
     242    def setUp(self):
     243        super(ApplicantPaymentExporterTest, self).setUp()
     244        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     245        self.cat = getUtility(ICatalog, name='applicants_catalog')
     246        self.intids = getUtility(IIntIds)
     247        return
     248
     249    def test_ifaces(self):
     250        # make sure we fullfill interface contracts
     251        obj = ApplicantPaymentExporter()
     252        verifyObject(ICSVExporter, obj)
     253        verifyClass(ICSVExporter, ApplicantPaymentExporter)
     254        return
     255
     256    def test_get_as_utility(self):
     257        # we can get an applicant exporter as utility
     258        result = queryUtility(ICSVExporter, name="applicantpayments")
     259        self.assertTrue(result is not None)
     260        return
     261
     262    def setup_applicant(self, applicant):
     263        # set predictable values for `applicant`
     264        applicant.reg_number = u'123456'
     265        applicant.applicant_id = u'dp2011_654321'
     266        applicant.firstname = u'Anna'
     267        applicant.lastname = u'Tester'
     268        applicant.middlename = u'M.'
     269        applicant.date_of_birth = datetime.date(1981, 2, 4)
     270        applicant.sex = 'f'
     271        applicant.email = 'anna@sample.com'
     272        applicant.phone = u'+234-123-12345'
     273        # Add payment
     274        payment = createObject(u'waeup.ApplicantOnlinePayment')
     275        payment.p_id = 'p120'
     276        payment.p_session = 2012
     277        payment.p_category = 'application'
     278        payment.p_state = 'paid'
     279        applicant['p120'] = payment
     280        return applicant
     281
     282    def test_export(self):
     283        applicant = self.setup_applicant(self.applicant)
     284        exporter = ApplicantPaymentExporter()
     285        exporter.export(applicant.values(), self.outfile)
     286        result = open(self.outfile, 'rb').read()
     287        cdate = str('%s#' % self.applicant['p120'].creation_date)
     288        self.assertEqual(
     289            'ac,amount_auth,creation_date,p_category,p_id,p_item,p_session,'
     290            'p_state,payment_date,r_amount_approved,r_code,r_desc,'
     291            'applicant_id\r\n,'
     292            '0.0,%s,application,p120,,2012,'
     293            'paid,,0.0,,,dp2011_654321\r\n' % cdate, result)
     294        return
     295
     296    def test_export_all(self):
     297        self.applicant = self.setup_applicant(self.applicant)
     298        exporter = ApplicantPaymentExporter()
     299        exporter.export_all(self.app, self.outfile)
     300        result = open(self.outfile, 'rb').read()
     301        cdate = str('%s#' % self.applicant['p120'].creation_date)
     302        self.assertEqual(
     303            'ac,amount_auth,creation_date,p_category,p_id,p_item,p_session,'
     304            'p_state,payment_date,r_amount_approved,r_code,r_desc,'
     305            'applicant_id\r\n,'
     306            '0.0,%s,application,p120,,2012,'
     307            'paid,,0.0,,,dp2011_654321\r\n' % cdate, result)
     308        return
     309
     310    def test_export_filtered(self):
     311        self.applicant = self.setup_applicant(self.applicant)
     312        exporter = ApplicantPaymentExporter()
     313        exporter.export_filtered(
     314            self.app, self.outfile, container=self.container.code)
     315        result = open(self.outfile, 'rb').read()
     316        cdate = str('%s#' % self.applicant['p120'].creation_date)
     317        self.assertEqual(
     318            'ac,amount_auth,creation_date,p_category,p_id,p_item,p_session,'
     319            'p_state,payment_date,r_amount_approved,r_code,r_desc,'
     320            'applicant_id\r\n,'
     321            '0.0,%s,application,p120,,2012,'
     322            'paid,,0.0,,,dp2011_654321\r\n' % cdate, result)
     323        return
Note: See TracChangeset for help on using the changeset viewer.