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

Last change on this file since 6775 was 6560, checked in by uli, 13 years ago

Add tests for interfaces. We have to test non-interface components at
least.

File size: 2.0 KB
Line 
1# Tests for interfaces and included components.
2import grok
3import unittest
4from waeup.sirp.interfaces import DuplicationError, RoleSource
5from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
6
7class DuplicationErrorTests(unittest.TestCase):
8
9    def test_is_exception(self):
10        exc = DuplicationError('Some message')
11        self.assertEqual(exc.msg, 'Some message')
12        self.assertEqual(exc.entries, [])
13
14    def test_as_string(self):
15        exc = DuplicationError('Some message')
16        self.assertEqual(exc.__str__(), "'Some message'")
17
18
19class RoleSourceTests(FunctionalTestCase):
20
21    layer = FunctionalLayer
22
23    def setUp(self):
24        super(RoleSourceTests, self).setUp()
25        # Register a role
26        class SomeRole(grok.Role):
27            grok.name('waeup.testrole')
28            grok.title('RoleWith.DotName')
29            grok.permissions('waeup.Public')
30        # Register a role not visible to waeup portal as its name does
31        # not start with 'waeup.'
32        class NonWAeUPRole(grok.Role):
33            grok.name('nonwaeup.testrole')
34            grok.title('Role not suitable for waeup')
35            grok.permissions('waeup.Public')
36        grok.testing.grok_component('SomeRole', SomeRole)
37        grok.testing.grok_component('NonWAeUPRole', NonWAeUPRole)
38        return
39
40    def test_getValues(self):
41        source = RoleSource()
42        result = source.factory.getValues()
43        self.assertTrue(u'waeup.testrole' in result)
44        self.assertTrue(u'waeup.PortalManager' in result)
45        self.assertTrue(u'nonwaeup.testrole' not in result)
46
47    def test_getTitle(self):
48        source = RoleSource()
49        result = source.factory.getTitle(u'waeup.PortalManager')
50        self.assertEqual(result, 'Portal Manager')
51
52    def test_getTitleWithDot(self):
53        # If there is a dot in the role title, we get only the last part
54        source = RoleSource()
55        result = source.factory.getTitle(u'waeup.testrole')
56        self.assertEqual(result, 'DotName')
Note: See TracBrowser for help on using the repository browser.