[7193] | 1 | ## $Id: test_interfaces.py 7811 2012-03-08 19:00:51Z uli $ |
---|
| 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 | |
---|
[6560] | 19 | # Tests for interfaces and included components. |
---|
| 20 | import grok |
---|
| 21 | import unittest |
---|
[7811] | 22 | from waeup.kofa.interfaces import DuplicationError, RoleSource |
---|
| 23 | from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase |
---|
[6560] | 24 | |
---|
| 25 | class 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 | |
---|
| 37 | class 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.' |
---|
[7811] | 50 | class NonKOFARole(grok.Role): |
---|
[6560] | 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) |
---|
[7811] | 55 | grok.testing.grok_component('NonKOFARole', NonKOFARole) |
---|
[6560] | 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') |
---|