source: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_container.py @ 9815

Last change on this file since 9815 was 7811, checked in by uli, 13 years ago

Rename all non-locales stuff from sirp to kofa.

  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1## $Id: test_container.py 7811 2012-03-08 19:00:51Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""
19Tests for students containers.
20"""
21import tempfile
22import shutil
23from zope.interface.verify import verifyClass, verifyObject
24from zope.component.hooks import setSite, clearSite
25from waeup.kofa.app import University
26from waeup.kofa.university.department import Department
27from waeup.kofa.students.interfaces import (
28    IStudentsContainer,
29    )
30from waeup.kofa.students.container import (
31    StudentsContainer,
32    )
33from waeup.kofa.testing import (
34    FunctionalLayer, FunctionalTestCase, remove_logger)
35
36class StudentsContainerTestCase(FunctionalTestCase):
37
38    layer = FunctionalLayer
39
40    def setUp(self):
41        remove_logger('waeup.kofa.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        # We cannot add arbitrary objects
79        department = Department()
80        self.assertRaises(
81            TypeError, container.addStudent, department)
82
83
84    def test_logger(self):
85        # We can get a logger from root
86        logger = self.app['students'].logger
87        assert logger is not None
88        assert logger.name == 'waeup.kofa.app.students'
89        handlers = logger.handlers
90        assert len(handlers) == 1
91        filename = logger.handlers[0].baseFilename
92        assert filename.endswith('students.log')
93        assert filename.startswith(self.dc_root)
94
95    def test_logger_multiple(self):
96        # Make sure the logger is still working after 2nd call
97        # First time we call it, it might be registered
98        logger = self.app['students'].logger
99        # At second call the already registered logger should be returned
100        logger = self.app['students'].logger
101        assert logger is not None
102        assert logger.name == 'waeup.kofa.app.students'
103        handlers = logger.handlers
104        assert len(handlers) == 1
105        filename = logger.handlers[0].baseFilename
106        assert filename.endswith('students.log')
107        assert filename.startswith(self.dc_root)
Note: See TracBrowser for help on using the repository browser.