1 | ## $Id: test_container.py 7811 2012-03-08 19:00:51Z uli $ |
---|
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 | """ |
---|
19 | Tests for customers containers. |
---|
20 | """ |
---|
21 | import tempfile |
---|
22 | import shutil |
---|
23 | from zope.interface.verify import verifyClass, verifyObject |
---|
24 | from zope.component.hooks import setSite, clearSite |
---|
25 | from waeup.ikoba.app import Company |
---|
26 | from waeup.ikoba.customers.interfaces import ( |
---|
27 | ICustomersContainer, |
---|
28 | ) |
---|
29 | from waeup.ikoba.customers.container import ( |
---|
30 | CustomersContainer, |
---|
31 | ) |
---|
32 | from waeup.ikoba.testing import ( |
---|
33 | FunctionalLayer, FunctionalTestCase, remove_logger) |
---|
34 | |
---|
35 | class 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) |
---|