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

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

Further increase overall test coverage.

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