From: optilude <svn...@pl...> - 2006-09-05 22:43:38
|
Author: optilude Date: Tue Sep 5 22:43:33 2006 New Revision: 10797 Modified: plone.app.portlets/trunk/plone/app/portlets/tests/test_mapping.py Log: Tests for user mapping Modified: plone.app.portlets/trunk/plone/app/portlets/tests/test_mapping.py ============================================================================== --- plone.app.portlets/trunk/plone/app/portlets/tests/test_mapping.py (original) +++ plone.app.portlets/trunk/plone/app/portlets/tests/test_mapping.py Tue Sep 5 22:43:33 2006 @@ -1,6 +1,8 @@ from Acquisition import aq_base +from Testing.ZopeTestCase import user_name from zope.component import getUtility, getMultiAdapter +from zope.app.component.hooks import setSite, setHooks from zope.publisher.interfaces.browser import IBrowserPublisher from zope.publisher.interfaces import NotFound @@ -9,7 +11,10 @@ from plone.portlets.interfaces import IPortletManager from plone.portlets.interfaces import IPortletAssignmentMapping +from plone.portlets.constants import USER_CATEGORY + from plone.app.portlets.storage import PortletAssignmentMapping +from plone.app.portlets.storage import CurrentUserAssignmentMapping from plone.app.portlets.portlets.classic import ClassicPortletAssignment from plone.app.portlets.browser.adding import PortletAdding @@ -30,7 +35,9 @@ class TestContextMapping(PortletsTestCase): def afterSetUp(self): - self.manager = getUtility(IPortletManager, name=u'plone.leftcolumn', context=self.portal) + setHooks() + setSite(self.portal) + self.manager = getUtility(IPortletManager, name=u'plone.leftcolumn') def testAdapting(self): mapping = getMultiAdapter((self.folder, self.manager,), IPortletAssignmentMapping) @@ -67,38 +74,81 @@ class TestCurrentUserAssignmentMapping(PortletsTestCase): + def afterSetUp(self): + setHooks() + setSite(self.portal) + manager = getUtility(IPortletManager, name='plone.leftcolumn') + self.cat = manager[USER_CATEGORY] + self.cat[user_name] = PortletAssignmentMapping() + self.mapping = CurrentUserAssignmentMapping(self.portal, self.cat) + def testKeys(self): - self.fail('Testing missing') + self.assertEquals(0, len(self.mapping.keys())) + assignment = ClassicPortletAssignment() + self.cat[user_name]['foo'] = assignment + self.assertEquals(['foo'], sorted(self.mapping.keys())) def testIter(self): - self.fail('Testing missing') + a1 = ClassicPortletAssignment() + a2 = ClassicPortletAssignment() + self.cat[user_name]['foo'] = a1 + self.cat[user_name]['bar'] = a2 + items = [a for a in self.mapping] + self.assertEquals(items, ['foo', 'bar']) def testGetItem(self): - self.fail('Testing missing') + assignment = ClassicPortletAssignment() + self.cat[user_name]['foo'] = assignment + self.assertEquals(assignment, self.mapping.get('foo')) + self.assertEquals(None, self.mapping.get('bar', None)) def testValues(self): - self.fail('Testing missing') + a1 = ClassicPortletAssignment() + a2 = ClassicPortletAssignment() + self.cat[user_name]['foo'] = a1 + self.cat[user_name]['bar'] = a2 + items = [a for a in self.mapping.values()] + self.assertEquals(items, [a1, a2]) def testLen(self): - self.fail('Testing missing') + self.assertEquals(0, len(self.mapping)) + self.cat[user_name]['foo'] = ClassicPortletAssignment() + self.assertEquals(1, len(self.mapping)) def testItems(self): - self.fail('Testing missing') + a1 = ClassicPortletAssignment() + a2 = ClassicPortletAssignment() + self.cat[user_name]['foo'] = a1 + self.cat[user_name]['bar'] = a2 + self.assertEquals([('foo', a1), ('bar', a2)], self.mapping.items()) def testContains(self): - self.fail('Test missing') + self.failIf('foo' in self.mapping) + self.cat[user_name]['foo'] = ClassicPortletAssignment() + self.failUnless('foo' in self.mapping) def testHasKey(self): - self.fail('Test missing') + self.failIf(self.mapping.has_key('foo')) + self.cat[user_name]['foo'] = ClassicPortletAssignment() + self.failUnless(self.mapping.has_key('foo')) def testSetItem(self): - self.fail('Test missing') + assignment = ClassicPortletAssignment() + self.mapping['foo'] = assignment + self.failUnless(self.cat[user_name]['foo'] is assignment) def testDelItem(self): - self.fail('Test missing') + self.cat[user_name]['foo'] = ClassicPortletAssignment() + del self.mapping['foo'] + self.assertEquals(0, len(self.cat[user_name])) def testUpdateOrder(self): - self.fail('Test missing') + a1 = ClassicPortletAssignment() + a2 = ClassicPortletAssignment() + self.cat[user_name]['foo'] = a1 + self.cat[user_name]['bar'] = a2 + self.mapping.updateOrder(['bar', 'foo']) + self.assertEquals([('bar', a2), ('foo', a1)], self.mapping.items()) def test_suite(): from unittest import TestSuite, makeSuite |