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

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

Add missing imports.

  • Property svn:keywords set to Id
File size: 3.6 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, clearSite
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        remove_logger('waeup.sirp.app.students')
42        super(StudentsContainerTestCase, self).setUp()
43        # Setup a sample site for each test
44        # Prepopulate the ZODB...
45        app = University()
46        self.getRootFolder()['app'] = app
47        self.app = self.getRootFolder()['app']
48        setSite(self.app)
49        self.dc_root = tempfile.mkdtemp()
50        app['datacenter'].setStoragePath(self.dc_root)
51        return
52
53    def tearDown(self):
54        super(StudentsContainerTestCase, self).tearDown()
55        clearSite()
56        shutil.rmtree(self.dc_root)
57        return
58
59    def test_interfaces(self):
60        # Make sure the correct interfaces are implemented.
61        self.assertTrue(
62            verifyClass(
63                IStudentsContainer, StudentsContainer)
64            )
65        self.assertTrue(
66            verifyObject(
67                IStudentsContainer, StudentsContainer())
68            )
69        return
70
71    def test_base(self):
72        # We cannot call the fundamental methods of a base in that case
73        container = StudentsContainer()
74        self.assertRaises(
75            NotImplementedError, container.archive)
76        self.assertRaises(
77            NotImplementedError, container.clear)
78
79    def test_logger(self):
80        # We can get a logger from root
81        logger = self.app['students'].logger
82        assert logger is not None
83        assert logger.name == 'waeup.sirp.app.students'
84        handlers = logger.handlers
85        assert len(handlers) == 1
86        filename = logger.handlers[0].baseFilename
87        assert filename.endswith('students.log')
88        assert filename.startswith(self.dc_root)
89
90    def test_logger_multiple(self):
91        # Make sure the logger is still working after 2nd call
92        # First time we call it, it might be registered
93        logger = self.app['students'].logger
94        # At second call the already registered logger should be returned
95        logger = self.app['students'].logger
96        assert logger is not None
97        assert logger.name == 'waeup.sirp.app.students'
98        handlers = logger.handlers
99        assert len(handlers) == 1
100        filename = logger.handlers[0].baseFilename
101        assert filename.endswith('students.log')
102        assert filename.startswith(self.dc_root)
Note: See TracBrowser for help on using the repository browser.