[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container/tests - test_adding.py:1.8

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Aug 15 21:45:18 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/container/tests
In directory cvs.zope.org:/tmp/cvs-serv20171/app/browser/container/tests

Modified Files:
	test_adding.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/browser/container/tests/test_adding.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/browser/container/tests/test_adding.py:1.7	Fri Aug 15 15:41:17 2003
+++ Zope3/src/zope/app/browser/container/tests/test_adding.py	Fri Aug 15 20:42:42 2003
@@ -17,24 +17,30 @@
 """
 
 from unittest import TestCase, main, makeSuite
+from zope.app import zapi
+from zope.app.browser.absoluteurl import AbsoluteURL
 from zope.app.browser.container.adding import Adding
-from zope.app.interfaces.container import IAdding
+from zope.app.context import ContextWrapper
+from zope.app.event.tests.placelesssetup import getEvents
+from zope.app.interfaces.container import IAdding, IContainer, IZopeContainer
+from zope.app.interfaces.event import IObjectAddedEvent, IObjectModifiedEvent
+from zope.app.interfaces.exceptions import UserError
+from zope.app.interfaces.traversing import IContainmentRoot
 from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.component.adapter import provideAdapter
 from zope.component.view import provideView
 from zope.component.factory import provideFactory
 from zope.component.interfaces import IFactory
 from zope.component.exceptions import ComponentLookupError
 from zope.context import getWrapperContainer, getWrapperData
-from zope.publisher.browser import TestRequest
-from zope.publisher.browser import BrowserView
+from zope.context import \
+     getWrapperContainer, getWrapperData, getInnerWrapperData
+from zope.interface import implements, Interface
+from zope.publisher.browser import TestRequest, BrowserView
 from zope.publisher.interfaces.browser import IBrowserPresentation
-from zope.app.event.tests.placelesssetup import getEvents
-from zope.app.interfaces.event import IObjectAddedEvent, IObjectModifiedEvent
-from zope.app.interfaces.exceptions import UserError
 
-from zope.app.interfaces.container import IZopeContainer
-from zope.interface import implements
-from zope.app.context import ContextWrapper
+class Root:
+    implements(IContainmentRoot)
 
 class Container(dict):
 
@@ -62,6 +68,18 @@
         return 'some_content'
 
 
+class AbsoluteURL(BrowserView):
+
+    def __str__(self):
+        if IContainmentRoot.isImplementedBy(self.context):
+            return ''
+        name = getInnerWrapperData(self.context)['name']
+        url = str(zapi.getView(
+            zapi.getParent(self.context), 'absolute_url', self.request))
+        url += '/' + name
+        return url
+
+
 class Test(PlacelessSetup, TestCase):
 
     def setUp(self):
@@ -147,6 +165,26 @@
         adding.contentName = None
         self.assertRaises(ValueError, adding.action, type_name='foo')
         
+
+    def test_action(self):
+        container = Container()
+        # ensure container provides IZopeContainer
+        container = ContextWrapper(container, Root(), name="container")
+        request = TestRequest()
+        adding = Adding(container, request)
+        adding = ContextWrapper(adding, container, name="+")
+        provideView(IAdding, "Thing", IBrowserPresentation, CreationView)
+        provideView(Interface, "absolute_url", IBrowserPresentation,
+                    AbsoluteURL)
+        self.assertRaises(UserError, adding.action, '', 'foo')
+        self.assertRaises(UserError, adding.action, 'Unknown', '')
+        adding.action('Thing', 'foo')
+        self.assertEqual(adding.request.response._headers['location'],
+                         '/container/+/Thing=foo')
+        adding.action('Thing/screen1', 'foo')
+        self.assertEqual(adding.request.response._headers['location'],
+                         '/container/+/Thing/screen1=foo')
+
 
 def test_suite():
     return makeSuite(Test)




More information about the Zope3-Checkins mailing list