source: main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_export.py @ 7878

Last change on this file since 7878 was 7864, checked in by uli, 13 years ago

Add first applicant-related exporter tests.

File size: 2.1 KB
Line 
1import datetime
2import os
3import shutil
4import tempfile
5import unittest
6from zope.component import queryUtility
7from zope.interface.verify import verifyObject, verifyClass
8from waeup.kofa.interfaces import ICSVExporter
9from waeup.kofa.testing import KofaUnitTestLayer
10from waeup.kofa.applicants import ApplicantsContainer
11from waeup.kofa.applicants.export import ApplicantsContainerExporter
12
13class ApplicantsContainersExporterTest(unittest.TestCase):
14
15    layer = KofaUnitTestLayer
16
17    def setUp(self):
18        self.workdir = tempfile.mkdtemp()
19        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
20        return
21
22    def tearDown(self):
23        shutil.rmtree(self.workdir)
24        return
25
26    def test_ifaces(self):
27        # make sure we fullfill interface contracts
28        obj = ApplicantsContainerExporter()
29        verifyObject(ICSVExporter, obj)
30        verifyClass(ICSVExporter, ApplicantsContainerExporter)
31        return
32
33    def test_get_as_utility(self):
34        # we can get a faculty exporter as utility
35        result = queryUtility(ICSVExporter, name="applicantscontainers")
36        self.assertTrue(result is not None)
37        return
38
39    def test_export(self):
40        # we can export a set of applicants containers (w/o applicants)
41        container = ApplicantsContainer()
42        container.code = u'dp2012'
43        container.startdate = datetime.date(2012, 1, 1)
44        exporter = ApplicantsContainerExporter()
45        exporter.export([container], self.outfile)
46        result = open(self.outfile, 'rb').read()
47        self.assertEqual(
48            result,
49            'code,title,prefix,entry_level,year,provider,application_category,'
50            'description,description_dict,startdate,enddate,strict_deadline\r\n'
51            'dp2012,-,,100,,,,"This text can been seen by anonymous users.\nHere we put mult-lingual information about the study courses provided, the application procedure and deadlines.\n>>de<<\nDieser Text kann von anonymen Benutzern gelesen werden.\nHier koennen mehrsprachige Informationen fuer Antragsteller hinterlegt werden.",{},2012-01-01,,1\r\n'
52            )
53        return
Note: See TracBrowser for help on using the repository browser.