source: main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_container.py @ 6655

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

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

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
2## This program is free software; you can redistribute it and/or modify
3## it under the terms of the GNU General Public License as published by
4## the Free Software Foundation; either version 2 of the License, or
5## (at your option) any later version.
6##
7## This program is distributed in the hope that it will be useful,
8## but WITHOUT ANY WARRANTY; without even the implied warranty of
9## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10## GNU General Public License for more details.
11##
12## You should have received a copy of the GNU General Public License
13## along with this program; if not, write to the Free Software
14## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15##
16"""
17Tests for students containers.
18"""
19import unittest
20import tempfile
21import shutil
22from zope.interface.verify import verifyClass, verifyObject
23from zope.component.interfaces import IFactory
24from zope.component.hooks import setSite
25from waeup.sirp.app import University
26from waeup.sirp.students.interfaces import (
27    IStudentsContainer,
28    )
29from waeup.sirp.students.container import (
30    StudentsContainer,
31    )
32from waeup.sirp.testing import (
33    FunctionalLayer, FunctionalTestCase, get_all_loggers, remove_new_loggers,
34    remove_logger)
35
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
61
62    def test_interfaces(self):
63        # Make sure the correct interfaces are implemented.
64        self.assertTrue(
65            verifyClass(
66                IStudentsContainer, StudentsContainer)
67            )
68        self.assertTrue(
69            verifyObject(
70                IStudentsContainer, StudentsContainer())
71            )
72        return
73
74    def test_base(self):
75        # We cannot call the fundamental methods of a base in that case
76        container = StudentsContainer()
77        self.assertRaises(
78            NotImplementedError, container.archive)
79        self.assertRaises(
80            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 TracBrowser for help on using the repository browser.