Back to index

plone3  3.1.7
test_traversal.py
Go to the documentation of this file.
00001 from Acquisition import aq_parent
00002 from Testing.ZopeTestCase import user_name
00003 
00004 from zope.app.component.hooks import setSite, setHooks
00005 from zope.component import getMultiAdapter, getUtility
00006 
00007 from plone.portlets.interfaces import IPortletManager, IPortletAssignmentMapping
00008 
00009 from plone.portlets.constants import USER_CATEGORY
00010 from plone.portlets.constants import GROUP_CATEGORY
00011 from plone.portlets.constants import CONTENT_TYPE_CATEGORY
00012 
00013 from plone.app.portlets.tests.base import PortletsTestCase
00014 from plone.app.portlets.portlets import classic
00015 
00016 class TestTraversal(PortletsTestCase):
00017 
00018     def afterSetUp(self):
00019         setHooks()
00020         setSite(self.portal)
00021 
00022     def testContextNamespace(self):
00023         assignment = classic.Assignment()
00024         manager = getUtility(IPortletManager, name='plone.leftcolumn')
00025         mapping = self.folder.restrictedTraverse('++contextportlets++plone.leftcolumn')
00026         target = getMultiAdapter((self.folder, manager), IPortletAssignmentMapping)
00027         self.failUnless(aq_parent(mapping) is self.folder)
00028         mapping['foo'] = assignment
00029         self.failUnless(target['foo'] is assignment)
00030         self.assertEquals('++contextportlets++plone.leftcolumn', mapping.id)
00031 
00032     def testDashboardNamespace(self):
00033         assignment = classic.Assignment()
00034         manager = getUtility(IPortletManager, name='plone.dashboard1')
00035         mapping = self.portal.restrictedTraverse('++dashboard++plone.dashboard1+' + user_name)
00036         self.failUnless(aq_parent(mapping) is self.portal)
00037         mapping['foo'] = assignment
00038         self.failUnless(manager[USER_CATEGORY][user_name]['foo'] is assignment)
00039         self.assertEquals('++dashboard++plone.dashboard1+' + user_name, mapping.id)
00040 
00041     def testGroupNamespace(self):
00042         assignment = classic.Assignment()
00043         manager = getUtility(IPortletManager, name='plone.leftcolumn')
00044         mapping = self.portal.restrictedTraverse('++groupportlets++plone.leftcolumn+Reviewers')
00045         self.failUnless(aq_parent(mapping) is self.portal)
00046         mapping['foo'] = assignment
00047         self.failUnless(manager[GROUP_CATEGORY]['Reviewers']['foo'] is assignment)
00048         self.assertEquals('++groupportlets++plone.leftcolumn+Reviewers', mapping.id)
00049 
00050     def testContentTypeNamespace(self):
00051         assignment = classic.Assignment()
00052         manager = getUtility(IPortletManager, name='plone.leftcolumn')
00053         mapping = self.portal.restrictedTraverse('++contenttypeportlets++plone.leftcolumn+Image')
00054         self.failUnless(aq_parent(mapping) is self.portal)
00055         mapping['foo'] = assignment
00056         self.failUnless(manager[CONTENT_TYPE_CATEGORY]['Image']['foo'] is assignment)
00057         self.assertEquals('++contenttypeportlets++plone.leftcolumn+Image', mapping.id)
00058 
00059 def test_suite():
00060     from unittest import TestSuite, makeSuite
00061     suite = TestSuite()
00062     suite.addTest(makeSuite(TestTraversal))
00063     return suite