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

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

More copyright adjustments.

  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1## $Id: test_container.py 7193 2011-11-25 07:21:29Z henrik $
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 unittest
22import tempfile
23import shutil
24from zope.interface.verify import verifyClass, verifyObject
25from zope.component.interfaces import IFactory
26from zope.component.hooks import setSite, clearSite
27from waeup.sirp.app import University
28from waeup.sirp.university.department import Department
29from waeup.sirp.students.interfaces import (
30    IStudentsContainer,
31    )
32from waeup.sirp.students.container import (
33    StudentsContainer,
34    )
35from waeup.sirp.testing import (
36    FunctionalLayer, FunctionalTestCase, get_all_loggers, remove_new_loggers,
37    remove_logger)
38
39class StudentsContainerTestCase(FunctionalTestCase):
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        remove_logger('waeup.sirp.app.students')
45        super(StudentsContainerTestCase, self).setUp()
46        # Setup a sample site for each test
47        # Prepopulate the ZODB...
48        app = University()
49        self.getRootFolder()['app'] = app
50        self.app = self.getRootFolder()['app']
51        setSite(self.app)
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        clearSite()
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        # We cannot add arbitrary objects
82        department = Department()
83        self.assertRaises(
84            TypeError, container.addStudent, department)
85
86
87    def test_logger(self):
88        # We can get a logger from root
89        logger = self.app['students'].logger
90        assert logger is not None
91        assert logger.name == 'waeup.sirp.app.students'
92        handlers = logger.handlers
93        assert len(handlers) == 1
94        filename = logger.handlers[0].baseFilename
95        assert filename.endswith('students.log')
96        assert filename.startswith(self.dc_root)
97
98    def test_logger_multiple(self):
99        # Make sure the logger is still working after 2nd call
100        # First time we call it, it might be registered
101        logger = self.app['students'].logger
102        # At second call the already registered logger should be returned
103        logger = self.app['students'].logger
104        assert logger is not None
105        assert logger.name == 'waeup.sirp.app.students'
106        handlers = logger.handlers
107        assert len(handlers) == 1
108        filename = logger.handlers[0].baseFilename
109        assert filename.endswith('students.log')
110        assert filename.startswith(self.dc_root)
Note: See TracBrowser for help on using the repository browser.