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

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

Add application browser components.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## $Id: test_container.py 12090 2014-11-29 07:57:51Z 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_logger(self):
71        # We can get a logger from root
72        logger = self.app['customers'].logger
73        assert logger is not None
74        assert logger.name == 'waeup.ikoba.app.customers'
75        handlers = logger.handlers
76        assert len(handlers) == 1
77        filename = logger.handlers[0].baseFilename
78        assert filename.endswith('customers.log')
79        assert filename.startswith(self.dc_root)
80
81    def test_logger_multiple(self):
82        # Make sure the logger is still working after 2nd call
83        # First time we call it, it might be registered
84        logger = self.app['customers'].logger
85        # At second call the already registered logger should be returned
86        logger = self.app['customers'].logger
87        assert logger is not None
88        assert logger.name == 'waeup.ikoba.app.customers'
89        handlers = logger.handlers
90        assert len(handlers) == 1
91        filename = logger.handlers[0].baseFilename
92        assert filename.endswith('customers.log')
93        assert filename.startswith(self.dc_root)
Note: See TracBrowser for help on using the repository browser.