source: main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_export.py @ 17260

Last change on this file since 17260 was 9262, checked in by Henrik Bettermann, 12 years ago

We need to export the batch id. This is necessary for reimport batches.

  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1## $Id: test_export.py 9262 2012-10-01 06:36:33Z henrik $
2##
3## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18import os
19import shutil
20import tempfile
21import unittest
22from zope.component import queryUtility
23from zope.interface.verify import verifyObject, verifyClass
24from zope.securitypolicy.interfaces import IPrincipalRoleManager
25from waeup.kofa.interfaces import ICSVExporter
26from waeup.kofa.testing import KofaUnitTestLayer, FunctionalLayer
27from waeup.kofa.accesscodes.accesscode import (
28    AccessCodeBatchContainer, AccessCodeBatch)
29from waeup.kofa.accesscodes.export import AccessCodeBatchExporter
30
31
32class AccessCodeBatchExporterTest(unittest.TestCase):
33
34    layer = FunctionalLayer
35
36    def setUp(self):
37        self.workdir = tempfile.mkdtemp()
38        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
39        return
40
41    def tearDown(self):
42        shutil.rmtree(self.workdir)
43        return
44
45    def test_ifaces(self):
46        # make sure we fullfill interface contracts
47        obj = AccessCodeBatchExporter()
48        verifyObject(ICSVExporter, obj)
49        verifyClass(ICSVExporter, AccessCodeBatchExporter)
50        return
51
52    def test_get_as_utility(self):
53        # we can get a faculty exporter as utility
54        result = queryUtility(ICSVExporter, name="accesscodebatches")
55        self.assertTrue(result is not None)
56        return
57
58    def test_export_all(self):
59        # we can export all faculties in a site
60        container = AccessCodeBatchContainer()
61        site = {'accesscodes':container}
62        batch1 = AccessCodeBatch('now', 'manfred', 'APP', 6.6, 0)
63        batch2 = AccessCodeBatch('now', 'manfred', 'SFE', 6.6, 0)
64        container.addBatch(batch1)
65        container.addBatch(batch2)
66        exporter = AccessCodeBatchExporter()
67        exporter.export_all(site, self.outfile)
68        result = open(self.outfile, 'rb').read()
69        self.assertEqual(
70            result,
71             'cost,creation_date,creator,disabled_num,entry_num,num,'
72             'prefix,used_num,batch_id\r\n6.6,now,manfred,0,0,1,APP,0,APP-1\r\n'
73             '6.6,now,manfred,0,0,0,SFE,0,SFE-0\r\n'
74            )
75        return
76
Note: See TracBrowser for help on using the repository browser.