source: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_container.py @ 12056

Last change on this file since 12056 was 11997, checked in by Henrik Bettermann, 10 years ago

propset svn:keywords "Id"

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