Back to index

plone3  3.1.7
test_utils.py
Go to the documentation of this file.
00001 from Acquisition import aq_base
00002 from Testing.ZopeTestCase import user_name
00003 
00004 from zope.component import getUtility, getMultiAdapter
00005 from zope.app.component.hooks import setSite, setHooks
00006 
00007 from plone.portlets.interfaces import IPortletManager
00008 from plone.portlets.interfaces import IPortletAssignmentMapping
00009 
00010 from plone.portlets.constants import USER_CATEGORY, CONTEXT_CATEGORY
00011 
00012 from plone.app.portlets.storage import PortletAssignmentMapping
00013 from plone.app.portlets.portlets import classic
00014 
00015 from plone.app.portlets.tests.base import PortletsTestCase
00016 
00017 from plone.app.portlets.utils import assignment_from_key
00018 
00019 class TestAssignmentFromKey(PortletsTestCase):
00020 
00021     def afterSetUp(self):
00022         setHooks()
00023         setSite(self.portal)
00024         self.manager = getUtility(IPortletManager, name=u'plone.leftcolumn')
00025         self.cat = self.manager[USER_CATEGORY]
00026         self.cat[user_name] = PortletAssignmentMapping(manager=u'plone.leftcolumn',
00027                                                        category=USER_CATEGORY,
00028                                                        name=user_name)
00029 
00030     def testGetPortletFromContext(self):
00031         mapping = getMultiAdapter((self.folder, self.manager,), IPortletAssignmentMapping)
00032         c = classic.Assignment()
00033         mapping['foo'] = c
00034         path = '/'.join(self.folder.getPhysicalPath())
00035         a = assignment_from_key(self.portal, u'plone.leftcolumn', CONTEXT_CATEGORY, path, 'foo')
00036         self.assertEquals(c, a)
00037 
00038     def testGetPortletFromUserCategory(self):
00039         c = classic.Assignment()
00040         self.cat[user_name]['foo'] = c
00041         a = assignment_from_key(self.portal, u'plone.leftcolumn', USER_CATEGORY, user_name, 'foo')
00042         self.assertEquals(c, a)
00043 
00044 def test_suite():
00045     from unittest import TestSuite, makeSuite
00046     suite = TestSuite()
00047     suite.addTest(makeSuite(TestAssignmentFromKey))
00048     return suite