source: main/waeup.kofa/trunk/src/waeup/kofa/university/tests/test_facultiescontainer.py @ 17669

Last change on this file since 17669 was 7819, checked in by Henrik Bettermann, 13 years ago

KOFA -> Kofa

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: test_facultiescontainer.py 7819 2012-03-08 22:28:46Z henrik $
2##
3## Copyright (C) 2011 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##
18
19# Tests for FacultiesContainer.
20import logging
21import unittest
22from StringIO import StringIO
23from zope.interface.verify import verifyObject, verifyClass
24from waeup.kofa.testing import FunctionalTestCase, FunctionalLayer
25from waeup.kofa.university.interfaces import IFacultiesContainer
26from waeup.kofa.university import FacultiesContainer
27from waeup.kofa.university.facultiescontainer import AcademicsPlugin
28
29class FakeLogger(object):
30
31    _stream = None
32
33    def get_logger(self):
34        logger = logging.getLogger('test')
35        logger.propagate = False
36        self._stream = StringIO()
37        self.handler = logging.StreamHandler(self._stream)
38        logger.setLevel(logging.DEBUG)
39        logger.addHandler(self.handler)
40        return logger
41
42    def close(self, logger):
43        # Remove handler from logger
44        handler = self.handler
45        if handler not in logger.handlers:
46            return
47        del logger.handlers[logger.handlers.index(handler)]
48        return
49
50    def get_messages(self):
51        self._stream.seek(0)
52        result = self._stream.read()
53        self._stream.seek(0, 2) # Seek to end of stream
54        return result
55
56class FacultiesContainerTests(unittest.TestCase):
57
58    def test_ifaces(self):
59        container = FacultiesContainer()
60        self.assertTrue(verifyClass(IFacultiesContainer, FacultiesContainer))
61        self.assertTrue(verifyObject(IFacultiesContainer, container))
62
63class AcademicsPluginTests(unittest.TestCase):
64
65    def setUp(self):
66        self._logger_factory = FakeLogger()
67        self.logger = self._logger_factory.get_logger()
68
69    def tearDown(self):
70        self._logger_factory.close(self.logger)
71
72    def test_setup(self):
73        site = dict()
74        logger = self.logger
75        plugin = AcademicsPlugin()
76        plugin.setup(site, 'testsite', logger)
77        self.assertTrue('faculties' in site.keys())
78        self.assertTrue(isinstance(site['faculties'], FacultiesContainer))
79        self.assertEqual(
80            self._logger_factory.get_messages(),
81            'Container for faculties created\n'
82            )
83
84    def test_setup_already_set_up(self):
85        site = dict(faculties=object())
86        logger = self.logger
87        plugin = AcademicsPlugin()
88        plugin.setup(site, 'testsite', logger)
89        self.assertTrue('faculties' in site.keys())
90        self.assertEqual(
91            self._logger_factory.get_messages(),
92            'Could not create container for faculties in Kofa.\n'
93            )
94
95    def test_update(self):
96        site = dict()
97        logger = self.logger
98        plugin = AcademicsPlugin()
99        plugin.update(site, 'testsite', logger)
100        self.assertTrue('faculties' in site.keys())
101        self.assertTrue(isinstance(site['faculties'], FacultiesContainer))
102        self.assertEqual(
103            self._logger_factory.get_messages(),
104            'Container for faculties created\n'
105            )
106
107    def test_update_already_set_up(self):
108        site = dict(faculties=object())
109        logger = self.logger
110        plugin = AcademicsPlugin()
111        plugin.update(site, 'testsite', logger)
112        self.assertTrue('faculties' in site.keys())
113        self.assertEqual(
114            self._logger_factory.get_messages(), '')
Note: See TracBrowser for help on using the repository browser.