Changeset 7913 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 19 Mar 2012, 01:56:34 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_export.py
r7905 r7913 4 4 import tempfile 5 5 import unittest 6 from zope.component import queryUtility, getUtilitiesFor 6 from zope.catalog.interfaces import ICatalog 7 from zope.component import queryUtility, getUtility, getUtilitiesFor 7 8 from zope.interface.verify import verifyObject, verifyClass 8 from waeup.kofa.interfaces import ICSVExporter 9 from waeup.kofa.testing import KofaUnitTestLayer 9 from zope.intid.interfaces import IIntIds 10 10 from waeup.kofa.applicants import ApplicantsContainer 11 from waeup.kofa.applicants.export import ApplicantsContainerExporter 11 from waeup.kofa.applicants.export import ( 12 ApplicantsContainerExporter, ApplicantsExporter) 12 13 from waeup.kofa.applicants.interfaces import ( 13 14 IApplicantsContainerProvider, AppCatSource) 15 from waeup.kofa.applicants.tests.test_batching import ( 16 ApplicantImportExportSetup) 17 from waeup.kofa.interfaces import ICSVExporter 18 from waeup.kofa.testing import KofaUnitTestLayer, FunctionalLayer 14 19 15 20 class ApplicantsContainersExporterTest(unittest.TestCase): … … 76 81 ) 77 82 return 83 84 class 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.