Back to index

plone3  3.1.7
test_mapping.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 zope.publisher.interfaces.browser import IBrowserPublisher
00008 from zope.publisher.interfaces import NotFound
00009 from zope.app.container.interfaces import INameChooser
00010 
00011 from plone.portlets.interfaces import IPortletManager
00012 from plone.portlets.interfaces import IPortletAssignmentMapping
00013 
00014 from plone.portlets.constants import USER_CATEGORY
00015 
00016 from plone.app.portlets.storage import PortletAssignmentMapping
00017 from plone.app.portlets.portlets import classic
00018 
00019 from plone.app.portlets.browser.adding import PortletAdding
00020 
00021 from plone.app.portlets.tests.base import PortletsTestCase
00022 
00023 class TestNameChooser(PortletsTestCase):
00024 
00025     def testNameChooser(self):
00026         mapping = PortletAssignmentMapping()
00027         chooser = INameChooser(mapping)
00028         c = classic.Assignment()
00029         mapping[chooser.chooseName(None, c)] = c
00030         self.failUnless(c.__name__)
00031         d = classic.Assignment()
00032         self.failIfEqual(chooser.chooseName(None, d), c.__name__)
00033 
00034 class TestContextMapping(PortletsTestCase):
00035 
00036     def afterSetUp(self):
00037         setHooks()
00038         setSite(self.portal)
00039         self.manager = getUtility(IPortletManager, name=u'plone.leftcolumn')
00040 
00041     def testAdapting(self):
00042         mapping = getMultiAdapter((self.folder, self.manager,), IPortletAssignmentMapping)
00043         self.assertEquals(0, len(mapping))
00044 
00045     def testEquivalence(self):
00046         mapping = getMultiAdapter((self.folder, self.manager,), IPortletAssignmentMapping)
00047         c = classic.Assignment()
00048         mapping['foo'] = c
00049 
00050         mapping2 = getMultiAdapter((self.folder, self.manager,), IPortletAssignmentMapping)
00051         self.assertEquals(mapping2['foo'], c)
00052 
00053 class TestTraverser(PortletsTestCase):
00054 
00055     def afterSetUp(self):
00056         self.mapping = PortletAssignmentMapping()
00057         c = classic.Assignment()
00058         self.mapping['foo'] = c
00059         self.traverser = getMultiAdapter((self.mapping, self.folder.REQUEST), IBrowserPublisher)
00060 
00061     def testTraverseToName(self):
00062         obj = self.traverser.publishTraverse(self.folder.REQUEST, 'foo')
00063         self.failUnless(aq_base(obj) is self.mapping['foo'])
00064         self.failUnless(obj.aq_parent is self.mapping)
00065 
00066     def testTraverseToView(self):
00067         view = self.traverser.publishTraverse(self.folder.REQUEST, '+')
00068         self.failUnless(isinstance(view, PortletAdding))
00069         self.failUnless(view.aq_parent is self.mapping)
00070 
00071     def testTraverseToNonExistent(self):
00072         self.assertRaises(NotFound, self.traverser.publishTraverse, self.folder.REQUEST, 'bar')
00073 
00074 def test_suite():
00075     from unittest import TestSuite, makeSuite
00076     suite = TestSuite()
00077     suite.addTest(makeSuite(TestContextMapping))
00078     suite.addTest(makeSuite(TestTraverser))
00079     suite.addTest(makeSuite(TestNameChooser))
00080     return suite