1 | import datetime |
---|
2 | import os |
---|
3 | import shutil |
---|
4 | import tempfile |
---|
5 | import unittest |
---|
6 | from zope.component import queryUtility |
---|
7 | from zope.interface.verify import verifyObject, verifyClass |
---|
8 | from waeup.kofa.interfaces import ICSVExporter |
---|
9 | from waeup.kofa.testing import KofaUnitTestLayer |
---|
10 | from waeup.kofa.applicants import ApplicantsContainer |
---|
11 | from waeup.kofa.applicants.export import ApplicantsContainerExporter |
---|
12 | |
---|
13 | class 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 |
---|