Ignore:
Timestamp:
28 Aug 2011, 08:33:12 (13 years ago)
Author:
Henrik Bettermann
Message:

Fix tests: Use functional tests instead of unit tests to test the new students logger correctly.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r6638 r6641  
    240240        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    241241        self.assertEqual(self.browser.url, self.history_student_path)
    242         self.assertMatches('...Student admitted by system...', self.browser.contents)
     242        self.assertMatches('...Student admitted by zope.mgr...', self.browser.contents)
    243243
    244244        return
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_container.py

    r6633 r6641  
    1818"""
    1919import unittest
     20import tempfile
     21import shutil
    2022from zope.interface.verify import verifyClass, verifyObject
    2123from zope.component.interfaces import IFactory
    22 from zope.app.testing.functional import FunctionalTestCase
     24from zope.component.hooks import setSite
     25from waeup.sirp.app import University
    2326from waeup.sirp.students.interfaces import (
    2427    IStudentsContainer,
     
    2730    StudentsContainer,
    2831    )
    29 from waeup.sirp.testing import FunctionalLayer
     32from waeup.sirp.testing import (
     33    FunctionalLayer, FunctionalTestCase, get_all_loggers, remove_new_loggers,
     34    remove_logger)
    3035
    31 class StudentsContainerTestCase(unittest.TestCase):
     36class StudentsContainerTestCase(FunctionalTestCase):
     37
     38    layer = FunctionalLayer
     39
     40    def setUp(self):
     41        super(StudentsContainerTestCase, self).setUp()
     42        remove_logger('waeup.sirp.app.students')
     43        self.old_loggers = get_all_loggers()
     44        # Setup a sample site for each test
     45
     46        # Prepopulate the ZODB...
     47        app = University()
     48        self.getRootFolder()['app'] = app
     49        self.app = self.getRootFolder()['app']
     50        setSite(self.app)
     51
     52        self.dc_root = tempfile.mkdtemp()
     53        app['datacenter'].setStoragePath(self.dc_root)
     54        return
     55
     56    def tearDown(self):
     57        super(StudentsContainerTestCase, self).tearDown()
     58        remove_new_loggers(self.old_loggers)
     59        shutil.rmtree(self.dc_root)
     60        return
    3261
    3362    def test_interfaces(self):
     
    5079        self.assertRaises(
    5180            NotImplementedError, container.clear)
     81
     82    def test_logger(self):
     83        # We can get a logger from root
     84        logger = self.app['students'].logger
     85        assert logger is not None
     86        assert logger.name == 'waeup.sirp.app.students'
     87        handlers = logger.handlers
     88        assert len(handlers) == 1
     89        filename = logger.handlers[0].baseFilename
     90        assert filename.endswith('students.log')
     91        assert filename.startswith(self.dc_root)
     92
     93    def test_logger_multiple(self):
     94        # Make sure the logger is still working after 2nd call
     95        # First time we call it, it might be registered
     96        logger = self.app['students'].logger
     97        # At second call the already registered logger should be returned
     98        logger = self.app['students'].logger
     99        assert logger is not None
     100        assert logger.name == 'waeup.sirp.app.students'
     101        handlers = logger.handlers
     102        assert len(handlers) == 1
     103        filename = logger.handlers[0].baseFilename
     104        assert filename.endswith('students.log')
     105        assert filename.startswith(self.dc_root)
Note: See TracChangeset for help on using the changeset viewer.