Changeset 6576 for main/waeup.sirp/trunk/src
- Timestamp:
- 27 Jul 2011, 17:04:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/university/tests/test_facultycontainer.py
r6574 r6576 1 1 # Tests for FacultyContainer. 2 import logging 2 3 import unittest 4 from StringIO import StringIO 3 5 from zope.interface.verify import verifyObject, verifyClass 4 6 from waeup.sirp.testing import FunctionalTestCase, FunctionalLayer 5 7 from waeup.sirp.university.interfaces import IFacultyContainer 6 8 from waeup.sirp.university import FacultyContainer 9 from waeup.sirp.university.facultycontainer import AcademicsPlugin 10 11 class 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 7 37 8 38 class FacultyContainerTests(unittest.TestCase): … … 12 42 self.assertTrue(verifyClass(IFacultyContainer, FacultyContainer)) 13 43 self.assertTrue(verifyObject(IFacultyContainer, container)) 44 45 class 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.