Changeset 7913 for main/waeup.kofa/trunk


Ignore:
Timestamp:
19 Mar 2012, 01:56:34 (13 years ago)
Author:
uli
Message:

Add applicant exporter tests (first draft).

File:
1 edited

Legend:

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

    r7905 r7913  
    44import tempfile
    55import unittest
    6 from zope.component import queryUtility, getUtilitiesFor
     6from zope.catalog.interfaces import ICatalog
     7from zope.component import queryUtility, getUtility, getUtilitiesFor
    78from zope.interface.verify import verifyObject, verifyClass
    8 from waeup.kofa.interfaces import ICSVExporter
    9 from waeup.kofa.testing import KofaUnitTestLayer
     9from zope.intid.interfaces import IIntIds
    1010from waeup.kofa.applicants import ApplicantsContainer
    11 from waeup.kofa.applicants.export import ApplicantsContainerExporter
     11from waeup.kofa.applicants.export import (
     12    ApplicantsContainerExporter, ApplicantsExporter)
    1213from waeup.kofa.applicants.interfaces import (
    1314    IApplicantsContainerProvider, AppCatSource)
     15from waeup.kofa.applicants.tests.test_batching import (
     16    ApplicantImportExportSetup)
     17from waeup.kofa.interfaces import ICSVExporter
     18from waeup.kofa.testing import KofaUnitTestLayer, FunctionalLayer
    1419
    1520class ApplicantsContainersExporterTest(unittest.TestCase):
     
    7681            )
    7782        return
     83
     84class ApplicantsExporterTest(ApplicantImportExportSetup):
     85
     86    layer = FunctionalLayer
     87
     88    def setUp(self):
     89        super(ApplicantsExporterTest, self).setUp()
     90        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
     91        self.cat = getUtility(ICatalog, name='applicants_catalog')
     92        self.intids = getUtility(IIntIds)
     93        return
     94
     95    def test_ifaces(self):
     96        # make sure we fullfill interface contracts
     97        obj = ApplicantsExporter()
     98        verifyObject(ICSVExporter, obj)
     99        verifyClass(ICSVExporter, ApplicantsExporter)
     100        return
     101
     102    def test_get_as_utility(self):
     103        # we can get an applicant exporter as utility
     104        result = queryUtility(ICSVExporter, name="applicants")
     105        self.assertTrue(result is not None)
     106        return
     107
     108    def test_export(self):
     109        # we can really export applicants
     110        # set values we can expect in export file
     111        self.applicant.reg_number = u'123456'
     112        self.applicant.applicant_id = u'dp2011_654321'
     113        intid = self.intids.getId(self.applicant)
     114        # reindex modified applicant
     115        self.cat.index_doc(intid, self.applicant)
     116        exporter = ApplicantsExporter()
     117        exporter.export([self.applicant], self.outfile)
     118        result = open(self.outfile, 'rb').read()
     119        self.assertEqual(
     120            result,
     121            'reg_number,school_grades,firstname,phone,middlename,lastname,'
     122            'lga,screening_score,notice,applicant_id,sex,course2,email,'
     123            'date_of_birth,screening_venue,course_admitted,course1\r\n'
     124
     125            '123456,[],Anna,,,Tester,foreigner,,,dp2011_654321,m,,,,,,\r\n'
     126            )
     127        return
Note: See TracChangeset for help on using the changeset viewer.