# Tests for interfaces and included components. import grok import unittest from waeup.sirp.interfaces import DuplicationError, RoleSource from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase class DuplicationErrorTests(unittest.TestCase): def test_is_exception(self): exc = DuplicationError('Some message') self.assertEqual(exc.msg, 'Some message') self.assertEqual(exc.entries, []) def test_as_string(self): exc = DuplicationError('Some message') self.assertEqual(exc.__str__(), "'Some message'") class RoleSourceTests(FunctionalTestCase): layer = FunctionalLayer def setUp(self): super(RoleSourceTests, self).setUp() # Register a role class SomeRole(grok.Role): grok.name('waeup.testrole') grok.title('RoleWith.DotName') grok.permissions('waeup.Public') # Register a role not visible to waeup portal as its name does # not start with 'waeup.' class NonWAeUPRole(grok.Role): grok.name('nonwaeup.testrole') grok.title('Role not suitable for waeup') grok.permissions('waeup.Public') grok.testing.grok_component('SomeRole', SomeRole) grok.testing.grok_component('NonWAeUPRole', NonWAeUPRole) return def test_getValues(self): source = RoleSource() result = source.factory.getValues() self.assertTrue(u'waeup.testrole' in result) self.assertTrue(u'waeup.PortalManager' in result) self.assertTrue(u'nonwaeup.testrole' not in result) def test_getTitle(self): source = RoleSource() result = source.factory.getTitle(u'waeup.PortalManager') self.assertEqual(result, 'Portal Manager') def test_getTitleWithDot(self): # If there is a dot in the role title, we get only the last part source = RoleSource() result = source.factory.getTitle(u'waeup.testrole') self.assertEqual(result, 'DotName')