Back to index

plone3  3.1.7
test_dashboard.py
Go to the documentation of this file.
00001 from zExceptions import Unauthorized
00002 from zope.component import getUtility, getMultiAdapter
00003 from zope.event import notify
00004 
00005 from plone.portlets.interfaces import IPortletManager
00006 from plone.portlets.interfaces import IPortletRetriever
00007 from plone.portlets.interfaces import IPortletType
00008 
00009 from plone.portlets.constants import USER_CATEGORY
00010 
00011 from Products.PluggableAuthService.events import PrincipalCreated
00012 from Products.PluggableAuthService.PropertiedUser import PropertiedUser
00013 
00014 from plone.app.portlets.tests.base import PortletsTestCase
00015 
00016 class TestDashboard(PortletsTestCase):
00017     
00018     def test_default_dashboard_created_for_new_user(self):
00019         
00020         col = getUtility(IPortletManager, name='plone.dashboard1')
00021         user_portlets = col[USER_CATEGORY]
00022         self.failIf('fakeuser' in user_portlets)
00023         
00024         # This would normally happen when a user is created
00025         notify(PrincipalCreated(PropertiedUser('fakeuser')))
00026         
00027         # We would expect some portlets to have been created after the
00028         # event handler has finished processing
00029 
00030         self.failUnless('fakeuser' in user_portlets)
00031         self.failUnless(len(user_portlets['fakeuser']) > 0)
00032   
00033     def test_non_ascii_usernames_created(self):
00034         user1, pass1 = u'user1\xa9'.encode('utf-8'), 'pass1'
00035         uf = self.portal.acl_users
00036         
00037         # Bug #6100 - Would throw a unicode decode error in event handler
00038         # in dashboard.py
00039         uf.userFolderAddUser(user1, pass1, ['Manager'], [])
00040 
00041         col = getUtility(IPortletManager, name='plone.dashboard1')
00042         retriever = getMultiAdapter((self.portal, col), IPortletRetriever)
00043         
00044         # Bug #7860 - Would throw a unicode decode error when fetching
00045         # portlets
00046         retriever.getPortlets()
00047    
00048 
00049     def test_disable_dasboard_breaks_event_portlet(self):
00050         # Bug #8230: disabling the dashboard breaks the event portlet
00051         self.portal.manage_permission('Portlets: Manage own portlets',
00052                 roles=['Manager'], acquire=0)
00053         self.loginAsPortalOwner()
00054 
00055         portlet = getUtility(IPortletType, name='portlets.Events')
00056         mapping = self.portal.restrictedTraverse('++contextportlets++plone.leftcolumn')
00057         addview = mapping.restrictedTraverse('+/' + portlet.addview)
00058         try:
00059             addview()
00060         except Unauthorized:
00061             self.fail()
00062 
00063 def test_suite():
00064     from unittest import TestSuite, makeSuite
00065     suite = TestSuite()
00066     suite.addTest(makeSuite(TestDashboard))
00067     return suite