[Zope3-checkins] CVS: Zope3/src/zope/app/utilities/tests -
test_content.py:1.3
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Aug 18 15:55:45 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/utilities/tests
In directory cvs.zope.org:/tmp/cvs-serv26491/utilities/tests
Modified Files:
test_content.py
Log Message:
Beefed up the Content Component Definition component, by supporting
flexible menu entries, which is very nice.
I consider my work on schema-driven Content Components done now and
encourage people to try it out. I think this functionality addresses an
audience that we have not dealt with much before, i.e. people that stand
somewhere between scripter and TTW developers.
=== Zope3/src/zope/app/utilities/tests/test_content.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/utilities/tests/test_content.py:1.2 Fri Aug 15 20:44:27 2003
+++ Zope3/src/zope/app/utilities/tests/test_content.py Mon Aug 18 14:55:40 2003
@@ -19,18 +19,24 @@
from zope.app import zapi
from zope.app.interfaces.annotation import IAttributeAnnotatable
+from zope.app.interfaces.container import IAdding
from zope.app.interfaces.publisher.browser import IBrowserMenuService
from zope.app.interfaces.services.utility import ILocalUtility
-from zope.app.interfaces.utilities.content import IContentComponentDefinition
+from zope.app.interfaces.utilities.content import \
+ IContentComponentDefinition, IContentComponentMenuItem
+from zope.app.publisher.browser.globalbrowsermenuservice import \
+ GlobalBrowserMenuService
from zope.app.services.menu import LocalBrowserMenuService, LocalBrowserMenu
from zope.app.services.tests.test_menu import addMenu
from zope.app.services.servicenames import BrowserMenu, Utilities
from zope.app.services.utility import LocalUtilityService
from zope.app.tests import setup
from zope.app.utilities.content import \
- ContentComponentDefinition, ContentComponentDefinitionRegistration
-from zope.app.utilities.content import ContentComponentInstance
+ ContentComponentDefinition, ContentComponentDefinitionRegistration, \
+ ContentComponentDefinitionMenuItem, ContentComponentInstance
from zope.component import getServiceManager
+from zope.component.adapter import provideAdapter
+from zope.component.exceptions import ComponentLookupError
from zope.interface import Interface, classImplements
from zope.schema import Int, TextLine, Text
@@ -46,9 +52,15 @@
setup.placefulSetUp()
self.rootFolder = setup.buildSampleFolderTree()
+ # Define Menu Item Adapter
+ provideAdapter(IContentComponentDefinition,
+ IContentComponentMenuItem,
+ ContentComponentDefinitionMenuItem)
+
# Define Menu Service
sm=getServiceManager(None)
sm.defineService(BrowserMenu, IBrowserMenuService)
+ sm.provideService(BrowserMenu, GlobalBrowserMenuService())
classImplements(LocalBrowserMenu, ILocalUtility)
classImplements(LocalBrowserMenu, IAttributeAnnotatable)
mgr = setup.createServiceManager(self.rootFolder)
@@ -79,20 +91,107 @@
def test_activated(self):
self.reg.activated()
+ self.assertEqual(self.reg.getComponent().name, 'TestDoc')
service = zapi.getService(self.rootFolder, BrowserMenu)
menu = service.getLocalMenu('add_content')
self.assertEqual('TestDoc', menu['1'].title)
- self.assert_(self.reg.menuitem_id != None)
- self.assert_(self.reg.menu != None)
- self.assertEqual(menu, menu)
+ mi = zapi.getAdapter(self.reg.getComponent(), IContentComponentMenuItem)
+ self.assert_(mi._menuItem != None)
+ self.assertEqual(mi._menu, menu)
def test_deactivated(self):
self.test_activated()
self.reg.deactivated()
- self.assertEqual(self.reg.menuitem_id, None)
- self.assertEqual(self.reg.menu, None)
- self.assertEqual(self.reg.getComponent().name,
- '<component not activated>')
+ mi = zapi.getAdapter(self.reg.getComponent(), IContentComponentMenuItem)
+ self.assertEqual(mi._menuItem, None)
+ self.assertEqual(mi._menu, None)
+ self.assertEqual(self.reg.getComponent().name, None)
+
+
+class ContentComponentDefinitionMenuItemTests(unittest.TestCase):
+
+ def setUp(self):
+ setup.placefulSetUp()
+ classImplements(ContentComponentDefinition, ILocalUtility)
+ classImplements(ContentComponentDefinition, IAttributeAnnotatable)
+ provideAdapter(IContentComponentDefinition,
+ IContentComponentMenuItem,
+ ContentComponentDefinitionMenuItem)
+
+ sm=getServiceManager(None)
+ sm.defineService(BrowserMenu, IBrowserMenuService)
+ sm.provideService(BrowserMenu, GlobalBrowserMenuService())
+
+ self.rootFolder = setup.buildSampleFolderTree()
+ self.mgr = setup.createServiceManager(self.rootFolder)
+
+ setup.addService(self.mgr, Utilities, LocalUtilityService())
+ ccd = ContentComponentDefinition('TestDoc', IDocument)
+ self.default = zapi.traverse(self.mgr, 'default')
+ self.default.setObject('Document', ccd)
+ ccd = zapi.traverse(self.default, 'Document')
+
+ self.mi = ContentComponentDefinitionMenuItem(ccd)
+
+ def tearDown(self):
+ setup.placefulTearDown()
+
+ def test_interface(self):
+ self.assertEqual(self.mi.interface, IAdding)
+ self.mi.interface = Interface
+ self.assertEqual(self.mi.interface, Interface)
+
+ def test_action(self):
+ self.assertEqual(self.mi.action, 'AddContentComponent/TestDoc')
+ self.mi.context.name = 'Document'
+ self.assertEqual(self.mi.action, 'AddContentComponent/Document')
+
+ def test_title(self):
+ self.assertEqual(self.mi.title, 'TestDoc')
+ self.mi.title = 'Test Document'
+ self.assertEqual(self.mi.title, 'Test Document')
+
+ def test_description(self):
+ self.assertEqual(self.mi.description, '')
+ self.mi.description = 'Test Document Description'
+ self.assertEqual(self.mi.description, 'Test Document Description')
+
+ def test_permission(self):
+ self.assertEqual(self.mi.permission, 'zope.ManageContent')
+ self.mi.permission = 'zope.View'
+ self.assertEqual(self.mi.permission, 'zope.View')
+
+ def test_filter_string(self):
+ self.assertEqual(self.mi.filter_string, '')
+ self.mi.filter_string = 'not: context'
+ self.assertEqual(self.mi.filter_string, 'not: context')
+
+ def test_createMenuService(self):
+ menus = self.mi._createMenuService()
+ self.assertEqual(zapi.name(menus), 'Menus-1')
+ self.assert_('Menus-1' in zapi.getParent(menus))
+
+ def test_createMenu(self):
+ menu = self.mi._createMenu()
+ self.assertEqual(zapi.name(menu), 'add_content')
+ self.assert_('add_content' in zapi.getParent(menu))
+
+ def test_createMenuItem(self):
+ self.mi.createMenuItem()
+ self.assert_('Menus-1' in self.default)
+ self.assert_('add_content' in self.default)
+ menu = zapi.traverse(self.default, 'add_content')
+ item = menu.values()[0]
+ self.assertEqual(item.action, 'AddContentComponent/TestDoc')
+
+ def test_create(self):
+ # This tests also createMenuItem and removeMenuItem
+ self.assertEqual(self.mi.create, True)
+ self.mi.createMenuItem()
+ self.assertRaises(ComponentLookupError, self.mi.__setattr__,
+ 'create', False)
+ self.mi._data['create'] = False
+ self.assertEqual(self.mi.create, False)
class ContentComponentInstanceTests(unittest.TestCase):
@@ -121,6 +220,7 @@
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ContentComponentDefinitionRegistrationTests),
+ unittest.makeSuite(ContentComponentDefinitionMenuItemTests),
unittest.makeSuite(ContentComponentInstanceTests),
))
More information about the Zope3-Checkins
mailing list