[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Changed the addMenuItem directive so that it no-longer generates

Jim Fulton jim at zope.com
Tue Aug 24 16:21:30 EDT 2004


Log message for revision 27252:
  Changed the addMenuItem directive so that it no-longer generates
  unpredictable factory names.  It used to generate factory ids of the
  form "zope.app.browser.add." + class_name + ".f" + number, where
  number was alocated sequentially from one factory to another.
  This was a disaster for testability.
  
  Now factory ids are of the form:
  
  "zope.app.browser.add." + class_module_name + "." + class_name
  


Changed:
  U   Zope3/trunk/src/zope/app/ftests/doctest.txt
  U   Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
  U   Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py
  U   Zope3/trunk/src/zope/app/site/browser/ftests/test_utilitytools.py
  U   Zope3/trunk/src/zope/app/uniqueid/ftests.py
  U   Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py
  U   Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_processdefinition.py


-=-
Modified: Zope3/trunk/src/zope/app/ftests/doctest.txt
===================================================================
--- Zope3/trunk/src/zope/app/ftests/doctest.txt	2004-08-24 18:47:33 UTC (rev 27251)
+++ Zope3/trunk/src/zope/app/ftests/doctest.txt	2004-08-24 20:21:30 UTC (rev 27252)
@@ -124,10 +124,10 @@
   >>> print http(r"""
   ... POST /@@contents.html HTTP/1.1
   ... Authorization: Basic bWdyOm1ncnB3
-  ... Content-Length: 54
+  ... Content-Length: 73
   ... Content-Type: application/x-www-form-urlencoded
   ... 
-  ... type_name=zope.app.browser.add.Folder.f10&new_value=f1""")
+  ... type_name=zope.app.browser.add.zope.app.folder.folder.Folder&new_value=f1""")
   HTTP/1.1 303 See Other
   Content-Length: ...
   Content-Type: text/html;charset=utf-8

Modified: Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py	2004-08-24 18:47:33 UTC (rev 27251)
+++ Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py	2004-08-24 20:21:30 UTC (rev 27252)
@@ -75,14 +75,16 @@
             )
 
 
-_next_id = 0
 def addMenuItem(_context, title, class_=None, factory=None, description='',
                 permission=None, filter=None, view=None):
     """Create an add menu item for a given class or factory
 
-    As a convenience, a class can be provided, in which case, a factory is
-    automatically defined based on the class.
+    As a convenience, a class can be provided, in which case, a
+    factory is automatically defined based on the class.  In this
+    case, the factory id is based on the class name.
+
     """
+    
     if class_ is None:
         if factory is None:
             raise ValueError("Must specify either class or factory")
@@ -92,10 +94,8 @@
         if permission is None:
             raise ValueError(
                 "A permission must be specified when a class is used")
-        global _next_id
-        _next_id += 1
-        factory = "zope.app.browser.add.%s.f%s" % (
-            class_.__name__, _next_id) 
+        factory = "zope.app.browser.add.%s.%s" % (
+            class_.__module__, class_.__name__) 
         ContentDirective(_context, class_).factory(
             _context,
             id = factory)
@@ -110,11 +110,3 @@
     menuItemDirective(_context, 'zope.app.container.add', IAdding,
                       action, title, description, filter,
                       permission, extra)
-
-
-def test_reset():
-    global _next_id
-    _next_id = 0
-    
-from zope.testing.cleanup import addCleanUp
-addCleanUp(test_reset)

Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py	2004-08-24 18:47:33 UTC (rev 27251)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_addMenuItem.py	2004-08-24 20:21:30 UTC (rev 27252)
@@ -13,20 +13,20 @@
 ##############################################################################
 """Test the addMenuItem directive
 
->>> test_reset()
 >>> context = Context()
 >>> addMenuItem(context, class_=X, title="Add an X",
 ...             permission="zope.ManageContent")
->>> context
+>>> context # doctest: +CONTEXT_DIFF
 ((('utility',
    <InterfaceClass zope.component.interfaces.IFactory>,
-   'zope.app.browser.add.X.f1'),
+   'zope.app.browser.add.zope.app.publisher.browser.tests.test_addMenuItem.X'),
   <function handler>,
   ('Utilities',
    'provideUtility',
    <InterfaceClass zope.component.interfaces.IFactory>,
    <zope.component.factory.Factory object>,
-   'zope.app.browser.add.X.f1')),
+   'zope.app.browser.add.""" \
+         """zope.app.publisher.browser.tests.test_addMenuItem.X')),
  (None,
   <function provideInterface>,
   ('zope.component.interfaces.IFactory',
@@ -35,15 +35,18 @@
    'zope.app.container.add',
    <InterfaceClass zope.app.container.interfaces.IAdding>,
    'Add an X'),
-  <bound method GlobalBrowserMenuService.menuItem of <zope.app.publisher.browser.globalbrowsermenuservice.GlobalBrowserMenuService object>>,
+  <bound method GlobalBrowserMenuService.menuItem of """ \
+     """<zope.app.publisher.browser.globalbrowsermenuservice.""" \
+     """GlobalBrowserMenuService object>>,
   ('zope.app.container.add',
    <InterfaceClass zope.app.container.interfaces.IAdding>,
-   'zope.app.browser.add.X.f1',
+   'zope.app.browser.add.zope.app.publisher.browser.tests.test_addMenuItem.X',
    'Add an X',
    '',
    None,
    'zope.ManageContent',
-   {'factory': 'zope.app.browser.add.X.f1'})))
+   {'factory': 'zope.app.browser.add.""" \
+         """zope.app.publisher.browser.tests.test_addMenuItem.X'})))
 
 $Id$
 """
@@ -53,7 +56,7 @@
 import re
 import pprint
 import cStringIO
-from zope.app.publisher.browser.metaconfigure import addMenuItem, test_reset
+from zope.app.publisher.browser.metaconfigure import addMenuItem
 
 atre = re.compile(' at [0-9a-fA-Fx]+')
 
@@ -124,21 +127,22 @@
 
 def test_w_factory_class_view():
     """
-    >>> test_reset()
     >>> context = Context()
     >>> addMenuItem(context, class_=X, title="Add an X",
     ...             permission="zope.ManageContent", description="blah blah",
     ...             filter="context/foo", view="AddX")
-    >>> context
+    >>> context # doctest: +CONTEXT_DIFF
     ((('utility',
        <InterfaceClass zope.component.interfaces.IFactory>,
-       'zope.app.browser.add.X.f1'),
+       'zope.app.browser.add.""" \
+         """zope.app.publisher.browser.tests.test_addMenuItem.X'),
       <function handler>,
       ('Utilities',
        'provideUtility',
        <InterfaceClass zope.component.interfaces.IFactory>,
        <zope.component.factory.Factory object>,
-       'zope.app.browser.add.X.f1')),
+       'zope.app.browser.add.""" \
+         """zope.app.publisher.browser.tests.test_addMenuItem.X')),
      (None,
       <function provideInterface>,
       ('zope.component.interfaces.IFactory',
@@ -147,7 +151,9 @@
        'zope.app.container.add',
        <InterfaceClass zope.app.container.interfaces.IAdding>,
        'Add an X'),
-      <bound method GlobalBrowserMenuService.menuItem of <zope.app.publisher.browser.globalbrowsermenuservice.GlobalBrowserMenuService object>>,
+      <bound method GlobalBrowserMenuService.menuItem of """ \
+         """<zope.app.publisher.browser.globalbrowsermenuservice.""" \
+         """GlobalBrowserMenuService object>>,
       ('zope.app.container.add',
        <InterfaceClass zope.app.container.interfaces.IAdding>,
        'AddX',
@@ -155,7 +161,8 @@
        'blah blah',
        'context/foo',
        'zope.ManageContent',
-       {'factory': 'zope.app.browser.add.X.f1'})))
+       {'factory': 'zope.app.browser.add.""" \
+         """zope.app.publisher.browser.tests.test_addMenuItem.X'})))
 """
 
 

Modified: Zope3/trunk/src/zope/app/site/browser/ftests/test_utilitytools.py
===================================================================
--- Zope3/trunk/src/zope/app/site/browser/ftests/test_utilitytools.py	2004-08-24 18:47:33 UTC (rev 27251)
+++ Zope3/trunk/src/zope/app/site/browser/ftests/test_utilitytools.py	2004-08-24 20:21:30 UTC (rev 27252)
@@ -52,7 +52,9 @@
         # attempt to add something
         response = self.publish(
             path+'/action.html', basic='mgr:mgrpw',
-            form={'type_name': 'zope.app.browser.add.TranslationDomain.f1',
+            form={'type_name':
+                  'zope.app.browser.add.'
+                  'zope.app.i18n.translationdomain.TranslationDomain',
                   'id': 'zope',
                   'add': 'Add'})
 
@@ -74,7 +76,9 @@
         self.publish(
             path + '/action.html',
             basic='mgr:mgrpw',
-            form={'type_name': 'zope.app.browser.add.TranslationDomain.f1',
+            form={'type_name':
+                  'zope.app.browser.add.'
+                  'zope.app.i18n.translationdomain.TranslationDomain',
                   'id': 'zope',
                   'add': 'Add'})
 
@@ -96,7 +100,9 @@
         self.publish(
             path + '/action.html',
             basic='mgr:mgrpw',
-            form={'type_name': 'zope.app.browser.add.TranslationDomain.f1',
+            form={'type_name':
+                  'zope.app.browser.add.'
+                  'zope.app.i18n.translationdomain.TranslationDomain',
                   'id': 'zope',
                   'add': 'Add'})
 
@@ -120,7 +126,9 @@
         self.publish(
             path + '/action.html',
             basic='mgr:mgrpw',
-            form={'type_name': 'zope.app.browser.add.TranslationDomain.f1',
+            form={'type_name':
+                  'zope.app.browser.add.'
+                  'zope.app.i18n.translationdomain.TranslationDomain',
                   'id': 'zope',
                   'add': 'Add'})
 
@@ -145,7 +153,9 @@
         self.publish(
             path + '/action.html',
             basic='mgr:mgrpw',
-            form={'type_name': 'zope.app.browser.add.TranslationDomain.f1',
+            form={'type_name':
+                  'zope.app.browser.add.'
+                  'zope.app.i18n.translationdomain.TranslationDomain',
                   'id': 'zope',
                   'add': 'Add'})
 

Modified: Zope3/trunk/src/zope/app/uniqueid/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/ftests.py	2004-08-24 18:47:33 UTC (rev 27251)
+++ Zope3/trunk/src/zope/app/uniqueid/ftests.py	2004-08-24 20:21:30 UTC (rev 27252)
@@ -18,11 +18,14 @@
 
 import unittest
 import re
+from transaction import commit
+
 from zope.app import zapi
 from zope.app.tests import ztapi
 from zope.app.tests.setup import addUtility
 from zope.app.tests.functional import BrowserTestCase
 
+
 class TestUniqueIdUtility(BrowserTestCase):
 
     def setUp(self):
@@ -36,15 +39,10 @@
 
         sm = zapi.traverse(root, '/++etc++site')
         addUtility(sm, 'uniqueid', IUniqueIdUtility, UniqueIdUtility())
+        commit()
 
-        response = self.publish(self.basepath + '/contents.html', basic='mgr:mgrpw')
+        type_name = 'zope.app.browser.add.zope.app.uniqueid.UniqueIdUtility'
 
-        self.assertEqual(response.getStatus(), 200)
-
-        expr = 'zope.app.browser.add.UniqueIdUtility.f([0-9]*)'
-        m = re.search(expr, response.getBody())
-        type_name = m.group(0)
-
         response = self.publish(
             self.basepath + '/contents.html',
             basic='mgr:mgrpw',

Modified: Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py
===================================================================
--- Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py	2004-08-24 18:47:33 UTC (rev 27251)
+++ Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_contentworkflowsmanager.py	2004-08-24 20:21:30 UTC (rev 27252)
@@ -18,6 +18,8 @@
 import unittest
 import re
 
+from transaction import commit
+
 from zope.interface import Interface
 from zope.app.component.interface import nameToInterface
 from zope.app import zapi
@@ -44,21 +46,15 @@
                    IStatefulProcessDefinition,
                    StatefulProcessDefinition()
                    ) 
+        commit()
 
         response = self.publish(
             self.basepath + '/contents.html',
-            basic='mgr:mgrpw')
-
-        self.assertEqual(response.getStatus(), 200)
-
-        expr = 'zope.app.browser.add.ContentWorkflowsManager.f([0-9]*)'
-        m = re.search(expr, response.getBody())
-        type_name = m.group(0)
-
-        response = self.publish(
-            self.basepath + '/contents.html',
             basic='mgr:mgrpw',
-            form={'type_name': type_name,
+            form={'type_name':
+                  'zope.app.browser.add.'
+                  'zope.app.workflow.stateful.contentworkflow.'
+                  'ContentWorkflowsManager',
                   'new_value': 'mgr' })
 
         root = self.getRootFolder()

Modified: Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_processdefinition.py
===================================================================
--- Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_processdefinition.py	2004-08-24 18:47:33 UTC (rev 27251)
+++ Zope3/trunk/src/zope/app/workflow/stateful/browser/ftests/test_processdefinition.py	2004-08-24 20:21:30 UTC (rev 27252)
@@ -29,18 +29,11 @@
         self.basepath = '/++etc++site/default'
         response = self.publish(
             self.basepath + '/contents.html',
-            basic='mgr:mgrpw')
-
-        self.assertEqual(response.getStatus(), 200)
-
-        expr = 'zope.app.browser.add.StatefulProcessDefinition.f([0-9]*)'
-        m = re.search(expr, response.getBody())
-        type_name = m.group(0)
-
-        response = self.publish(
-            self.basepath + '/contents.html',
             basic='mgr:mgrpw',
-            form={'type_name': type_name,
+            form={'type_name':
+                  'zope.app.browser.add.'
+                  'zope.app.workflow.stateful.definition.'
+                  'StatefulProcessDefinition',
                   'new_value': 'pd' })
 
     def test_processdefinition(self):



More information about the Zope3-Checkins mailing list