[Zope3-checkins] CVS: Zope3/src/zope/app/browser/container/tests -
test_adding.py:1.6.18.1
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Aug 15 19:25:24 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/browser/container/tests
In directory cvs.zope.org:/tmp/cvs-serv30690/browser/container/tests
Modified Files:
Tag: dreamcatcher-ttwschema-branch
test_adding.py
Log Message:
Added tests for Adding's action() method.
Add content instance tests.
This completes my work, and I am ready to merge, if dreamcatcher would not
have broken three tests... ;)
=== Zope3/src/zope/app/browser/container/tests/test_adding.py 1.6 => 1.6.18.1 ===
--- Zope3/src/zope/app/browser/container/tests/test_adding.py:1.6 Thu Jun 5 08:41:54 2003
+++ Zope3/src/zope/app/browser/container/tests/test_adding.py Fri Aug 15 18:24:50 2003
@@ -17,21 +17,27 @@
"""
from unittest import TestCase, main, makeSuite
-from zope.component.adapter import provideAdapter
+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
+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.context import getWrapperContainer, getWrapperData
+from zope.context import \
+ getWrapperContainer, getWrapperData, getInnerWrapperData
+from zope.interface import implements, Interface
from zope.publisher.browser import TestRequest
from zope.publisher.browser import 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.container import IContainer
-from zope.interface import implements
-from zope.app.context import ContextWrapper
+class Root:
+ implements(IContainmentRoot)
class Container:
@@ -52,6 +58,18 @@
def action(self):
return 'been there, done that'
+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):
@@ -105,6 +123,26 @@
self.assertEqual(adding.contentName, None)
view = adding.publishTraverse(request, 'Thing=')
self.assertEqual(adding.contentName, '')
+
+
+ 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():
More information about the Zope3-Checkins
mailing list