[Checkins] SVN: zope.app.publisher/trunk/ - Menu items registered with <browser:page/> were not re-registered after the

Christian Zagrodnick cz at gocept.com
Thu Dec 4 02:19:40 EST 2008


Log message for revision 93600:
  - Menu items registered with <browser:page/> were not re-registered after the
    first functional test layer ran. In any subsequent functional test layer the
    items where not availabe (introduced in 3.5.0a3).
  
    I removed the "transient registry" for menuitems registered with the page
    directives. Since no test fails without it and I have a test which fails with
    it I feel quite comfortable. If this code is still required add a test case
    and proper clean up code.
  
  
  

Changed:
  U   zope.app.publisher/trunk/CHANGES.txt
  A   zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/menutestlayer.zcml
  A   zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_menutestlayer.py
  U   zope.app.publisher/trunk/src/zope/app/publisher/browser/viewmeta.py

-=-
Modified: zope.app.publisher/trunk/CHANGES.txt
===================================================================
--- zope.app.publisher/trunk/CHANGES.txt	2008-12-04 05:11:53 UTC (rev 93599)
+++ zope.app.publisher/trunk/CHANGES.txt	2008-12-04 07:19:40 UTC (rev 93600)
@@ -8,6 +8,10 @@
 - Added possibility to specify custom item class in menuItem, subMenuItem
   and addMenuItem directives using the ``item_class`` argument (LP #291865).
 
+- Menu items registered with <browser:page/> were not re-registered after the
+  first functional test layer ran. In any subsequent functional test layer the
+  items where not availabe (introduced in 3.5.0a3).
+
 3.5.2a1 (2008-10-23)
 ====================
 

Added: zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/menutestlayer.zcml
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/menutestlayer.zcml	                        (rev 0)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/menutestlayer.zcml	2008-12-04 07:19:40 UTC (rev 93600)
@@ -0,0 +1,22 @@
+<configure
+  xmlns="http://namespaces.zope.org/zope"
+  xmlns:browser="http://namespaces.zope.org/browser"
+  i18n_domain="zope">
+
+  <include package="zope.app.publisher" file="meta.zcml" />
+
+  <browser:menu
+    id="test_menu"
+    title="Test Menu"
+    />
+
+  <browser:page
+    for="zope.interface.Interface"
+    name="foo"
+    class="zope.app.publisher.browser.tests.test_menutestlayer.View"
+    permission="zope.Public"
+    menu="test_menu" title="Foo"
+    />
+
+</configure>
+

Added: zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_menutestlayer.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_menutestlayer.py	                        (rev 0)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_menutestlayer.py	2008-12-04 07:19:40 UTC (rev 93600)
@@ -0,0 +1,61 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Test that menu items are re-registered in subsequent layers.
+
+Menu items registered with <browser:page/> were not re-registered after the
+first functional test layer ran. In any subsequent functional test layer the
+items where not availabe (LP #XXX, introduced in 3.5.0a3)
+
+"""
+
+import os.path
+import unittest
+import zope.app.testing.functional
+import zope.publisher.browser
+import zope.publisher.interfaces.browser
+
+
+layer1 = zope.app.testing.functional.ZCMLLayer(
+    os.path.join(os.path.dirname(__file__), 'menutestlayer.zcml'),
+    __name__, 'MenuTestLayer1', allow_teardown=True)
+layer2 = zope.app.testing.functional.ZCMLLayer(
+    os.path.join(os.path.dirname(__file__), 'menutestlayer.zcml'),
+    __name__, 'MenuTestLayer2', allow_teardown=True)
+
+
+class View(object):
+    pass
+
+
+class TestLayerMenuReuse1(zope.app.testing.functional.BrowserTestCase):
+
+    layer = layer1
+
+    def test_menu(self):
+        request = zope.publisher.browser.TestRequest()
+        item = zope.app.publisher.browser.menu.getFirstMenuItem(
+            'test_menu', object(), request)
+        self.assertNotEqual(None, item)
+
+class TestLayerMenuReuse2(TestLayerMenuReuse1):
+
+    layer = layer2
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(TestLayerMenuReuse1))
+    suite.addTest(unittest.makeSuite(TestLayerMenuReuse2))
+    return suite
+


Property changes on: zope.app.publisher/trunk/src/zope/app/publisher/browser/tests/test_menutestlayer.py
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Modified: zope.app.publisher/trunk/src/zope/app/publisher/browser/viewmeta.py
===================================================================
--- zope.app.publisher/trunk/src/zope/app/publisher/browser/viewmeta.py	2008-12-04 05:11:53 UTC (rev 93599)
+++ zope.app.publisher/trunk/src/zope/app/publisher/browser/viewmeta.py	2008-12-04 07:19:40 UTC (rev 93600)
@@ -339,9 +339,6 @@
                     _context.info),
             )
 
-# transient _handle_menu registry
-_registeredMenus = {}
-
 def _handle_menu(_context, menu, title, for_, name, permission,
                  layer=IDefaultBrowserLayer):
 
@@ -355,15 +352,10 @@
                     "Menus can be specified only for single-view, not for "
                     "multi-views.")
 
-        registeredTitles = _registeredMenus.setdefault(menu, {})
-        registered = registeredTitles.setdefault(title, [])
+        return menuItemDirective(
+            _context, menu, for_[0], '@@' + name, title,
+            permission=permission, layer=layer)
 
-        if for_[0] not in registered:
-            registered.append(for_[0])
-            return menuItemDirective(
-                _context, menu, for_[0], '@@' + name, title,
-                permission=permission, layer=layer)
-
     return []
 
 def _handle_permission(_context, permission):



More information about the Checkins mailing list