source: main/waeup.sirp/trunk/src/waeup/sirp/tests/test_interfaces.py @ 7449

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

Replace the term 'WAeUP' by SIRP which is a WAeUP product.

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1## $Id: test_interfaces.py 7321 2011-12-10 06:15:17Z 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
19# Tests for interfaces and included components.
20import grok
21import unittest
22from waeup.sirp.interfaces import DuplicationError, RoleSource
23from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
24
25class DuplicationErrorTests(unittest.TestCase):
26
27    def test_is_exception(self):
28        exc = DuplicationError('Some message')
29        self.assertEqual(exc.msg, 'Some message')
30        self.assertEqual(exc.entries, [])
31
32    def test_as_string(self):
33        exc = DuplicationError('Some message')
34        self.assertEqual(exc.__str__(), "'Some message'")
35
36
37class RoleSourceTests(FunctionalTestCase):
38
39    layer = FunctionalLayer
40
41    def setUp(self):
42        super(RoleSourceTests, self).setUp()
43        # Register a role
44        class SomeRole(grok.Role):
45            grok.name('waeup.testrole')
46            grok.title('RoleWith.DotName')
47            grok.permissions('waeup.Public')
48        # Register a role not visible to waeup portal as its name does
49        # not start with 'waeup.'
50        class NonSIRPRole(grok.Role):
51            grok.name('nonwaeup.testrole')
52            grok.title('Role not suitable for waeup')
53            grok.permissions('waeup.Public')
54        grok.testing.grok_component('SomeRole', SomeRole)
55        grok.testing.grok_component('NonSIRPRole', NonSIRPRole)
56        return
57
58    def test_getValues(self):
59        source = RoleSource()
60        result = source.factory.getValues()
61        self.assertTrue(u'waeup.testrole' in result)
62        self.assertTrue(u'waeup.PortalManager' in result)
63        self.assertTrue(u'nonwaeup.testrole' not in result)
64
65    def test_getTitle(self):
66        source = RoleSource()
67        result = source.factory.getTitle(u'waeup.PortalManager')
68        self.assertEqual(result, 'Portal Manager')
69
70    def test_getTitleWithDot(self):
71        # If there is a dot in the role title, we get only the last part
72        source = RoleSource()
73        result = source.factory.getTitle(u'waeup.testrole')
74        self.assertEqual(result, 'DotName')
Note: See TracBrowser for help on using the repository browser.