Ignore:
Timestamp:
27 Jul 2011, 17:04:13 (13 years ago)
Author:
uli
Message:

Add tests for academics plugin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_facultycontainer.py

    r6574 r6576  
    11# Tests for FacultyContainer.
     2import logging
    23import unittest
     4from StringIO import StringIO
    35from zope.interface.verify import verifyObject, verifyClass
    46from waeup.sirp.testing import FunctionalTestCase, FunctionalLayer
    57from waeup.sirp.university.interfaces import IFacultyContainer
    68from waeup.sirp.university import FacultyContainer
     9from waeup.sirp.university.facultycontainer import AcademicsPlugin
     10
     11class FakeLogger(object):
     12
     13    _stream = None
     14
     15    def get_logger(self):
     16        logger = logging.getLogger('test')
     17        logger.propagate = False
     18        self._stream = StringIO()
     19        self.handler = logging.StreamHandler(self._stream)
     20        logger.setLevel(logging.DEBUG)
     21        logger.addHandler(self.handler)
     22        return logger
     23
     24    def close(self, logger):
     25        # Remove handler from logger
     26        handler = self.handler
     27        if handler not in logger.handlers:
     28            return
     29        del logger.handlers[logger.handlers.index(handler)]
     30        return
     31
     32    def get_messages(self):
     33        self._stream.seek(0)
     34        result = self._stream.read()
     35        self._stream.seek(0, 2) # Seek to end of stream
     36        return result
    737
    838class FacultyContainerTests(unittest.TestCase):
     
    1242        self.assertTrue(verifyClass(IFacultyContainer, FacultyContainer))
    1343        self.assertTrue(verifyObject(IFacultyContainer, container))
     44
     45class AcademicsPluginTests(unittest.TestCase):
     46
     47    def setUp(self):
     48        self._logger_factory = FakeLogger()
     49        self.logger = self._logger_factory.get_logger()
     50
     51    def tearDown(self):
     52        self._logger_factory.close(self.logger)
     53
     54    def test_setup(self):
     55        site = dict()
     56        logger = self.logger
     57        plugin = AcademicsPlugin()
     58        plugin.setup(site, 'testsite', logger)
     59        self.assertTrue('faculties' in site.keys())
     60        self.assertTrue(isinstance(site['faculties'], FacultyContainer))
     61        self.assertEqual(
     62            self._logger_factory.get_messages(),
     63            'Created faculty container for University\n'
     64            )
     65
     66    def test_setup_already_set_up(self):
     67        site = dict(faculties=object())
     68        logger = self.logger
     69        plugin = AcademicsPlugin()
     70        plugin.setup(site, 'testsite', logger)
     71        self.assertTrue('faculties' in site.keys())
     72        self.assertEqual(
     73            self._logger_factory.get_messages(),
     74            'Could not create faculty container in WAeUP SIRP.\n'
     75            )
     76
     77    def test_update(self):
     78        site = dict()
     79        logger = self.logger
     80        plugin = AcademicsPlugin()
     81        plugin.update(site, 'testsite', logger)
     82        self.assertTrue('faculties' in site.keys())
     83        self.assertTrue(isinstance(site['faculties'], FacultyContainer))
     84        self.assertEqual(
     85            self._logger_factory.get_messages(),
     86            'Created faculty container for University\n'
     87            )
     88
     89    def test_update_already_set_up(self):
     90        site = dict(faculties=object())
     91        logger = self.logger
     92        plugin = AcademicsPlugin()
     93        plugin.update(site, 'testsite', logger)
     94        self.assertTrue('faculties' in site.keys())
     95        self.assertEqual(
     96            self._logger_factory.get_messages(), '')
Note: See TracChangeset for help on using the changeset viewer.