[Zope3-checkins] CVS: Zope3/src/zope/app/utilities/tests -
test_content.py:1.2 test_interfaceutility.py:1.4
test_schemautility.py:1.2
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Aug 15 21:45:03 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/utilities/tests
In directory cvs.zope.org:/tmp/cvs-serv20171/app/utilities/tests
Modified Files:
test_interfaceutility.py test_schemautility.py
Added Files:
test_content.py
Log Message:
Merging dreamcatcher's TTW Schema branch:
1. Fixed Bug in adding that would cause infinite loops when the menu items
action was not a valif view or factory id.
2. Extended adding to support more complex views. Until now we only
supported constructions like "+/AddView=id". Now you are able to say
"+/AddView/More=id", which means that more information can be carried
in the URL. This can be used in many ways, including multi-page adding
wizards. In my case I needed it to pass in the type of the TTW Schema-
based Content Component.
3. Added Local Menus. This was a pain in the butt, but I think I got a
fairly nice model, where you can create local Menu Services, and Menus
are simply named utilities. When active they are menus in the menu
service. This is very similar to the local interface service and TTW
Schema.
4. Made some modifications to TTW Schema, cleaned up the code and moved
the browser code and interfaces to the places they belong.
5. Added a Content Component Definition utility component, which takes a
Schema and creates a content component for it, including permission
settings and a menu entry. Currently the menu entry is always made to
a local 'add_content' menu. I will change this and make it actually a
screen, where the menu and title of the menu item can be chosen by the
developer. Mmmh, should I add a factory for the definition as well, so
that the content component is also available via python?
6. Added a Content Component Instance component that represents an
instance od a Content Component Definition. You will never directly
encounter this component, since it is automatically used by the adding
code of the Content Component Definition.
7. Cleanups by both dreamcatcher and myself.
That's it. For more details see the branch checkin messages. I now consider
the dreamcatcher-ttwschema-branch closed.
=== Zope3/src/zope/app/utilities/tests/test_content.py 1.1 => 1.2 ===
--- /dev/null Fri Aug 15 20:45:02 2003
+++ Zope3/src/zope/app/utilities/tests/test_content.py Fri Aug 15 20:44:27 2003
@@ -0,0 +1,128 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Content Component Definition and Instance Tests
+
+$Id$
+"""
+import unittest
+
+from zope.app import zapi
+from zope.app.interfaces.annotation import IAttributeAnnotatable
+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.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
+from zope.component import getServiceManager
+from zope.interface import Interface, classImplements
+from zope.schema import Int, TextLine, Text
+
+class IDocument(Interface):
+ id = Int(title=u"id", default=0)
+ title = TextLine(title=u"title", default=u'Title goes here.')
+ description = Text(title=u"desription")
+
+
+class ContentComponentDefinitionRegistrationTests(unittest.TestCase):
+
+ def setUp(self):
+ setup.placefulSetUp()
+ self.rootFolder = setup.buildSampleFolderTree()
+
+ # Define Menu Service
+ sm=getServiceManager(None)
+ sm.defineService(BrowserMenu, IBrowserMenuService)
+ classImplements(LocalBrowserMenu, ILocalUtility)
+ classImplements(LocalBrowserMenu, IAttributeAnnotatable)
+ mgr = setup.createServiceManager(self.rootFolder)
+ self.root_ms = setup.addService(mgr, BrowserMenu,
+ LocalBrowserMenuService())
+
+ # Setup Utility Service
+ setup.addService(mgr, Utilities, LocalUtilityService())
+
+ # Define a Menu
+ addMenu(mgr, 'add_content', 'Add Content', True)
+
+ # Setup Definition
+ classImplements(ContentComponentDefinition, ILocalUtility)
+ classImplements(ContentComponentDefinition, IAttributeAnnotatable)
+ default = zapi.traverse(mgr, 'default')
+ default.setObject('TestDoc', ContentComponentDefinition())
+
+ # Setup Definition Registration
+ path = "%s/default/%s" % (zapi.getPath(mgr), 'TestDoc')
+ reg = ContentComponentDefinitionRegistration(
+ 'TestDoc', IContentComponentDefinition, path)
+ key = default.getRegistrationManager().setObject("", reg)
+ self.reg = zapi.traverse(default.getRegistrationManager(), key)
+
+ def tearDown(self):
+ setup.placefulTearDown()
+
+ def test_activated(self):
+ self.reg.activated()
+ 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)
+
+ 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>')
+
+
+class ContentComponentInstanceTests(unittest.TestCase):
+
+ def test_getattr(self):
+ doc = ContentComponentInstance('Document', IDocument)
+ self.assertEqual(doc.id, 0)
+ self.assertEqual(doc.title, 'Title goes here.')
+ self.assertEqual(doc.description, None)
+ self.assertRaises(AttributeError, getattr, doc, 'foo')
+
+ def test_setattr(self):
+ doc = ContentComponentInstance('Document', IDocument)
+ doc.id = 1
+ self.assertEqual(doc.id, 1)
+ doc.title = 'Doc 1'
+ self.assertEqual(doc.title, 'Doc 1')
+ doc.description = 'This is doc 1.'
+ self.assertEqual(doc.description, 'This is doc 1.')
+ self.assertRaises(AttributeError, setattr, doc, 'foo', 'bar')
+
+ def test_getSchema(self):
+ doc = ContentComponentInstance('Document', IDocument)
+ self.assertEqual(doc.getSchema(), IDocument)
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(ContentComponentDefinitionRegistrationTests),
+ unittest.makeSuite(ContentComponentInstanceTests),
+ ))
+
+if __name__ == '__main__':
+ unittest.main()
=== Zope3/src/zope/app/utilities/tests/test_interfaceutility.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/utilities/tests/test_interfaceutility.py:1.3 Mon Aug 11 10:48:32 2003
+++ Zope3/src/zope/app/utilities/tests/test_interfaceutility.py Fri Aug 15 20:44:27 2003
@@ -93,8 +93,6 @@
class Bar(Foo): pass
-IFACE_NAME = "%s.%s" % (Foo.__module__, Foo.__name__)
-
class TestInterfaceUtility(placefulsetup.PlacefulSetup, unittest.TestCase):
def setUp(self):
@@ -104,7 +102,8 @@
utility.LocalUtilityService())
def test_getLocalInterface_delegates_to_globalUtility(self):
- globalUtilityService.provideUtility(IInterface, Bar("global"))
+ globalUtilityService.provideUtility(IInterface, Bar("blob"),
+ name="blob")
globalUtilityService.provideUtility(IBaz, Baz("global baz"))
globalUtilityService.provideUtility(IInterface, Foo("global bob"),
name="bob")
@@ -112,7 +111,7 @@
iface_service = getService(self.rootFolder, Interfaces)
self.assert_(iface_service != globalInterfaceService)
self.assertEqual(iface_service.getInterface("bob").__class__, Foo)
- self.assertEqual(iface_service.getInterface('').__class__, Bar)
+ self.assertEqual(iface_service.getInterface("blob").__class__, Bar)
def test_localInterfaceitems_filters_accordingly(self):
bar = Bar("global")
@@ -136,8 +135,9 @@
for pair in [('bob', foo), ('', bar)]:
self.assert_(pair in ifaces)
- self.assertEqual(iface_service.items(base=Interface),
- [])
+ ifaces = iface_service.items(base=Interface)
+ for pair in [('bob', foo), ('', bar)]:
+ self.assert_(pair in ifaces)
def test_localInterfaceitems_filters_only_interfaces(self):
bar = Bar("global")
=== Zope3/src/zope/app/utilities/tests/test_schemautility.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/utilities/tests/test_schemautility.py:1.1 Thu Aug 7 16:42:00 2003
+++ Zope3/src/zope/app/utilities/tests/test_schemautility.py Fri Aug 15 20:44:27 2003
@@ -22,7 +22,8 @@
class SchemaUtilityTests(TestCase):
def setUp(self):
- self.s = SchemaUtility('IFoo')
+ self.s = SchemaUtility()
+ self.s.setName('IFoo')
self.alpha = Text(title=u"alpha")
def test_addField(self):
@@ -30,6 +31,15 @@
s.addField('alpha', self.alpha)
self.assertEquals(
[('alpha', self.alpha)],
+ getFieldsInOrder(s))
+
+ def test_addFieldInsertsAtEnd(self):
+ s = self.s
+ s.addField('alpha', self.alpha)
+ beta = Text(title=u"Beta")
+ s.addField('beta', beta)
+ self.assertEquals(
+ [('alpha', self.alpha),('beta', beta)],
getFieldsInOrder(s))
def test_removeField(self):
More information about the Zope3-Checkins
mailing list