Back to index

plone3  3.1.7
test_context.py
Go to the documentation of this file.
00001 from plone.app.portlets.tests.base import PortletsTestCase
00002 
00003 from plone.portlets.interfaces import IPortletContext
00004 
00005 from Testing.ZopeTestCase import user_name
00006 
00007 class TestBasicContext(PortletsTestCase):
00008 
00009     def testParent(self):
00010         ctx = IPortletContext(self.folder)
00011         self.failUnless(ctx.getParent() is self.folder.aq_parent)
00012 
00013     def testGlobalsNoGroups(self):
00014         ctx = IPortletContext(self.folder)
00015         g = ctx.globalPortletCategories()
00016         self.assertEquals(len(g), 3)
00017         self.assertEquals(g[0], ('content_type', 'Folder'))
00018         self.assertEquals(g[1], ('user', user_name))
00019 
00020     def testGlobalsWithSingleGroup(self):
00021 
00022         group = self.portal.portal_groups.getGroupById('Reviewers')
00023         self.setRoles(('Manager',))
00024         group.addMember(user_name)
00025         self.setRoles(('Member',))
00026 
00027         ctx = IPortletContext(self.folder)
00028         g = ctx.globalPortletCategories()
00029         self.assertEquals(len(g), 4)
00030         self.assertEquals(g[0], ('content_type', 'Folder'))
00031         self.assertEquals(g[1], ('user', user_name))
00032         self.assertEquals(g[3], ('group', 'Reviewers'))
00033 
00034     def testGlobalsWithMultipleGroup(self):
00035 
00036         self.setRoles(('Manager',))
00037         group = self.portal.portal_groups.getGroupById('Reviewers')
00038         group.addMember(user_name)
00039         group = self.portal.portal_groups.getGroupById('Administrators')
00040         group.addMember(user_name)
00041         self.setRoles(('Member',))
00042 
00043         ctx = IPortletContext(self.folder)
00044         g = ctx.globalPortletCategories()
00045         self.assertEquals(len(g), 5)
00046         self.assertEquals(g[0], ('content_type', 'Folder'))
00047         self.assertEquals(g[1], ('user', user_name))
00048         self.assertEquals(g[2], ('group', 'Administrators'))
00049         self.assertEquals(g[4], ('group', 'Reviewers'))
00050 
00051     def testAnonymous(self):
00052         self.logout()
00053         ctx = IPortletContext(self.folder)
00054         g = ctx.globalPortletCategories()
00055         self.assertEquals(len(g), 2)
00056         self.assertEquals(g[0], ('content_type', 'Folder'))
00057         self.assertEquals(g[1], ('user', 'Anonymous User'))
00058 
00059 class TestPortalRootContext(PortletsTestCase):
00060 
00061     def testParent(self):
00062         ctx = IPortletContext(self.portal)
00063         self.failUnless(ctx.getParent() is None)
00064 
00065     def testGlobalsNoGroups(self):
00066         ctx = IPortletContext(self.portal)
00067         g = ctx.globalPortletCategories()
00068         self.assertEquals(len(g), 3)
00069         self.assertEquals(g[0], ('content_type', 'Plone Site'))
00070         self.assertEquals(g[1], ('user', user_name))
00071 
00072     def testGlobalsWithSingleGroup(self):
00073 
00074         group = self.portal.portal_groups.getGroupById('Reviewers')
00075         self.setRoles(('Manager',))
00076         group.addMember(user_name)
00077         self.setRoles(('Member',))
00078 
00079         ctx = IPortletContext(self.portal)
00080         g = ctx.globalPortletCategories()
00081         self.assertEquals(len(g), 4)
00082         self.assertEquals(g[0], ('content_type', 'Plone Site'))
00083         self.assertEquals(g[1], ('user', user_name))
00084         self.assertEquals(g[3], ('group', 'Reviewers'))
00085 
00086     def testGlobalsWithMultipleGroup(self):
00087 
00088         self.setRoles(('Manager',))
00089         group = self.portal.portal_groups.getGroupById('Reviewers')
00090         group.addMember(user_name)
00091         group = self.portal.portal_groups.getGroupById('Administrators')
00092         group.addMember(user_name)
00093         self.setRoles(('Member',))
00094 
00095         ctx = IPortletContext(self.portal)
00096         g = ctx.globalPortletCategories()
00097         self.assertEquals(len(g), 5)
00098         self.assertEquals(g[0], ('content_type', 'Plone Site'))
00099         self.assertEquals(g[1], ('user', user_name))
00100         self.assertEquals(g[2], ('group', 'Administrators'))
00101         self.assertEquals(g[4], ('group', 'Reviewers'))
00102 
00103     def testAnonymous(self):
00104         self.logout()
00105         ctx = IPortletContext(self.portal)
00106         g = ctx.globalPortletCategories()
00107         self.assertEquals(len(g), 2)
00108         self.assertEquals(g[0], ('content_type', 'Plone Site'))
00109         self.assertEquals(g[1], ('user', 'Anonymous User'))
00110 
00111 def test_suite():
00112     from unittest import TestSuite, makeSuite
00113     suite = TestSuite()
00114     suite.addTest(makeSuite(TestBasicContext))
00115     suite.addTest(makeSuite(TestPortalRootContext))
00116     return suite