[Zope3-checkins] CVS: Zope3/src/zope/app/publisher/browser/tests -
test_globalbrowsermenuservice.py:1.12
test_globalbrowsermenuservicedirectives.py:1.7 test_resource.py:1.5
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Aug 15 21:44:57 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/publisher/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv20171/app/publisher/browser/tests
Modified Files:
test_globalbrowsermenuservice.py
test_globalbrowsermenuservicedirectives.py test_resource.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/publisher/browser/tests/test_globalbrowsermenuservice.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py:1.11 Wed Jul 9 21:35:15 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py Fri Aug 15 20:43:51 2003
@@ -11,24 +11,22 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""XXX short summary goes here.
-
-XXX longer description goes here.
+"""Global Browser Menu Tests
$Id$
"""
-
-from unittest import TestCase, main, makeSuite
-from zope.publisher.interfaces.browser import IBrowserPublisher
+import unittest
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.interfaces.security import IPermissionService
+from zope.app.publisher.browser.globalbrowsermenuservice import \
+ GlobalBrowserMenuService
+from zope.app.security.registries.permissionregistry import permissionRegistry
+from zope.app.services.servicenames import Permissions
+from zope.component.service import serviceManager
from zope.exceptions import Forbidden, Unauthorized, DuplicationError
from zope.interface import Interface, implements
from zope.publisher.browser import TestRequest
-from zope.app.tests.placelesssetup import PlacelessSetup
-
-from zope.component.service import serviceManager
-from zope.app.services.servicenames import Permissions
-from zope.app.security.registries.permissionregistry import permissionRegistry
-from zope.app.interfaces.security import IPermissionService
+from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.security.management import newSecurityManager, system_user
class I1(Interface): pass
@@ -36,12 +34,15 @@
class I12(I1): pass
class I111(I11): pass
-class X:
+class TestObject:
implements(IBrowserPublisher, I111)
- def f(self): pass
+ def f(self):
+ pass
+
+ def browserDefault(self, r):
+ return self, ()
- def browserDefault(self, r): return self, ()
def publishTraverse(self, request, name):
if name[:1] == 'f':
raise Forbidden, name
@@ -50,14 +51,18 @@
return self.f
-class Test(PlacelessSetup, TestCase):
+def d(n):
+ return {'action': "a%s" % n,
+ 'title': "t%s" % n,
+ 'description': "d%s" % n,
+ 'selected': ''
+ }
- def __reg(self):
- from zope.app.publisher.browser.globalbrowsermenuservice \
- import GlobalBrowserMenuService
- r = GlobalBrowserMenuService()
- return r
+class GlobalBrowserMenuServiceTest(PlacelessSetup, unittest.TestCase):
+
+ def __reg(self):
+ return GlobalBrowserMenuService()
def testDup(self):
r = self.__reg()
@@ -77,15 +82,7 @@
r.menuItem('test_id', I111, 'u8', 't8', 'd8')
r.menuItem('test_id', I12, 'a9', 't9', 'd9')
- menu = r.getMenu('test_id', X(), TestRequest())
-
- def d(n):
- return {'action': "a%s" % n,
- 'title': "t%s" % n,
- 'description': "d%s" % n,
- 'selected': ''
- }
-
+ menu = r.getMenu('test_id', TestObject(), TestRequest())
self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
def test_w_permission(self):
@@ -105,23 +102,15 @@
r.menuItem('test_id', I111, 'u8', 't8', 'd8')
r.menuItem('test_id', I12, 'a9', 't9', 'd9')
- def d(n):
- return {'action': "a%s" % n,
- 'title': "t%s" % n,
- 'description': "d%s" % n,
- 'selected': ''
- }
-
newSecurityManager('test')
- menu = r.getMenu('test_id', X(), TestRequest())
+ menu = r.getMenu('test_id', TestObject(), TestRequest())
self.assertEqual(list(menu), [d(6), d(3), d(2), d(1)])
newSecurityManager(system_user)
- menu = r.getMenu('test_id', X(), TestRequest())
-
+ menu = r.getMenu('test_id', TestObject(), TestRequest())
self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
@@ -141,14 +130,7 @@
r.menuItem('test_id', I111, 'u8', 't8', 'd8')
r.menuItem('test_id', I12, 'a9', 't9', 'd9')
- menu = r.getMenu('test_id', X(), TestRequest())
-
- def d(n):
- return {'action': "a%s" % n,
- 'title': "t%s" % n,
- 'description': "d%s" % n,
- 'selected': ''}
-
+ menu = r.getMenu('test_id', TestObject(), TestRequest())
self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
def test_identify_action(self):
@@ -164,24 +146,24 @@
'description': "d%s" % n,
'selected': selected}
- menu = r.getMenu('test_id', X(),
+ menu = r.getMenu('test_id', TestObject(),
TestRequest(SERVER_URL='http://127.0.0.1/a1', PATH_INFO='/a1'))
self.assertEqual(list(menu), [d(2), d(12), d(1, 'selected')])
- menu = r.getMenu('test_id', X(),
+ menu = r.getMenu('test_id', TestObject(),
TestRequest(SERVER_URL='http://127.0.0.1/a12', PATH_INFO='/a12'))
self.assertEqual(list(menu), [d(2), d(12, 'selected'), d(1)])
- menu = r.getMenu('test_id', X(),
+ menu = r.getMenu('test_id', TestObject(),
TestRequest(SERVER_URL='http://127.0.0.1/@@a1', PATH_INFO='/@@a1'))
self.assertEqual(list(menu), [d(2), d(12), d(1, 'selected')])
- menu = r.getMenu('test_id', X(),
+ menu = r.getMenu('test_id', TestObject(),
TestRequest(SERVER_URL='http://127.0.0.1/@@a12',
PATH_INFO='/@@a12'))
self.assertEqual(list(menu), [d(2), d(12, 'selected'), d(1)])
- menu = r.getMenu('test_id', X(),
+ menu = r.getMenu('test_id', TestObject(),
TestRequest(SERVER_URL='http://127.0.0.1/++view++a1',
PATH_INFO='/++view++a1'))
self.assertEqual(list(menu), [d(2), d(12), d(1, 'selected')])
- menu = r.getMenu('test_id', X(),
+ menu = r.getMenu('test_id', TestObject(),
TestRequest(SERVER_URL='http://127.0.0.1/++view++a12',
PATH_INFO='/++view++a12'))
self.assertEqual(list(menu), [d(2), d(12, 'selected'), d(1)])
@@ -189,7 +171,7 @@
def testEmpty(self):
r = self.__reg()
r.menu('test_id', 'test menu')
- menu = r.getMenu('test_id', X(), TestRequest())
+ menu = r.getMenu('test_id', TestObject(), TestRequest())
self.assertEqual(list(menu), [])
def testUsage(self):
@@ -199,9 +181,31 @@
r.menu('test_id2', 'test menu')
self.assertEqual(r.getMenuUsage('test_id2'), u'')
+ def test_getAllMenuItema(self):
+ r = self.__reg()
+ r.menu('test_id', 'test menu')
+ r.menuItem('test_id', Interface, 'a1', 't1', 'd1')
+ r.menuItem('test_id', I1, 'a2', 't2', 'd2')
+ r.menuItem('test_id', I11, 'a3', 't3', 'd3')
+ r.menuItem('test_id', I111, 'a5', 't5', 'd5')
+ r.menuItem('test_id', I111, 'a6', 't6', 'd6')
+ r.menuItem('test_id', I111, 'a7', 't7', 'd7')
+ r.menuItem('test_id', I111, 'a8', 't8', 'd8')
+ r.menuItem('test_id', I12, 'a9', 't9', 'd9')
+
+ def d(n):
+ return ('a%s' %n, 't%s' %n, 'd%s' %n, None, None)
+
+ menu = r.getAllMenuItems('test_id', TestObject())
+ self.assertEqual(list(menu), [d(5), d(6), d(7), d(8), d(3),
+ d(2), d(1)])
+
+
def test_suite():
- return makeSuite(Test)
+ return unittest.TestSuite((
+ unittest.makeSuite(GlobalBrowserMenuServiceTest),
+ ))
-if __name__=='__main__':
- main(defaultTest='test_suite')
+if __name__ == '__main__':
+ unittest.main()
=== Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservicedirectives.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservicedirectives.py:1.6 Sun Aug 3 13:50:24 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservicedirectives.py Fri Aug 15 20:43:51 2003
@@ -87,9 +87,10 @@
from zope.app.publisher.browser.tests.test_globalbrowsermenuservice \
- import X
+ import TestObject
- menu = globalBrowserMenuService.getMenu('test_id', X(), TestRequest())
+ menu = globalBrowserMenuService.getMenu('test_id', TestObject(),
+ TestRequest())
def d(n):
return {'action': "a%s" % n,
@@ -101,7 +102,7 @@
self.assertEqual(list(menu), [d(5), d(6), d(3), d(2), d(1)])
first = globalBrowserMenuService.getFirstMenuItem(
- 'test_id', X(), TestRequest())
+ 'test_id', TestObject(), TestRequest())
self.assertEqual(first, d(5))
=== Zope3/src/zope/app/publisher/browser/tests/test_resource.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/publisher/browser/tests/test_resource.py:1.4 Fri Aug 8 14:07:27 2003
+++ Zope3/src/zope/app/publisher/browser/tests/test_resource.py Fri Aug 15 20:43:51 2003
@@ -15,33 +15,35 @@
$Id$
"""
-
import unittest
-from zope.publisher.browser import TestRequest
from zope.app.context import ContextWrapper
+from zope.app.publisher.browser.resource import Resource
+from zope.component.interfaces import IResourceService
+from zope.interface import implements
+from zope.publisher.browser import TestRequest
+
+class Service:
+ implements(IResourceService)
class TestResource(unittest.TestCase):
def testGlobal(self):
- from zope.app.publisher.browser.resource import Resource
req = TestRequest()
- r = ContextWrapper(Resource(req), None, name="foo")
+ r = ContextWrapper(Resource(req), Service(), name="foo")
self.assertEquals(r(), '/@@/foo')
- r = ContextWrapper(Resource(req), None, name="++resource++foo")
+ r = ContextWrapper(Resource(req), Service(), name="++resource++foo")
self.assertEquals(r(), '/@@/foo')
def testGlobalWithSkin(self):
- from zope.app.publisher.browser.resource import Resource
req = TestRequest()
req._presentation_skin = 'bar'
- r = ContextWrapper(Resource(req), None, name="foo")
+ r = ContextWrapper(Resource(req), Service(), name="foo")
self.assertEquals(r(), '/++skin++bar/@@/foo')
def testGlobalInVirtualHost(self):
- from zope.app.publisher.browser.resource import Resource
req = TestRequest()
req.setVirtualHostRoot(['x', 'y'])
- r = ContextWrapper(Resource(req), None, name="foo")
+ r = ContextWrapper(Resource(req), Service(), name="foo")
self.assertEquals(r(), '/x/y/@@/foo')
More information about the Zope3-Checkins
mailing list