Hi, Trying to test a URL in a unittest.py test using code as follows: apply(Site.restrictedTraverse('/folder/cmfsite/skinmethod'),params) Now, skinmethod uses the new Zope 2.5.0 sessioning: session=context.REQUEST.SESSION session.set('key','value') but the BeforeTraversal hook doesn't seem to kick in when restrictedTraverse is used :-( We always get an AttributeError on SESSION. How should we fix this and go about testing this method properly? cheers, Chris
Your problem is that a REQUEST is not created without the publisher. This is a particularly annoying and unsolved problem when doing tests. Your options are to use "import Zope; Zope.test('/some/method/name')" which has all sorts of bad side effects, or to dummy up the environment as much as possible via things like makerequest, etc. enough for the method to work. I can't say exactly what's needed for that in this case, I'd need to mess with it endlessly (luckily that's your job in this case ;-) Sorry, - C On Tue, 08 Jan 2002 10:16:16 +0000 Chris Withers <chrisw@nipltd.com> wrote:
Hi,
Trying to test a URL in a unittest.py test using code as follows:
apply(Site.restrictedTraverse('/folder/cmfsite/skinmethod'),params)
Now, skinmethod uses the new Zope 2.5.0 sessioning:
session=context.REQUEST.SESSION session.set('key','value')
but the BeforeTraversal hook doesn't seem to kick in when restrictedTraverse is used :-(
We always get an AttributeError on SESSION.
How should we fix this and go about testing this method properly?
cheers,
Chris
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Chris McDonough wrote:
Your problem is that a REQUEST is not created without the publisher. This is a particularly annoying and unsolved problem when doing tests.
Is it solved in Zope 3?
Your options are to use "import Zope; Zope.test('/some/method/name')" which has all sorts of bad side effects,
Never even knew that existed. Where's it documented? What does it do? What are the side effects?
or to dummy up the environment as much as possible via things like makerequest, etc. enough for the method to work. I can't say exactly what's needed for that in this case, I'd need to mess with it endlessly (luckily that's your job in this case ;-)
Well, we're using makerequest, and the following code seems to be keeping the SESSION stuff working: session = app.unrestrictedTraverse('/session_data_manager').getSessionData app.REQUEST.set_lazy('SESSION', session) Is that the 'right thing' to do? cheers, Chris
Is it solved in Zope 3?
Zope3 is more modular, so probably. Though I dont think it's a goal.
Never even knew that existed. Where's it documented? What does it do? What are the side effects?
"Zoper.test" as a side effect it commits a transaction. It's documented in the dev guide as "ZPublisher.Zope", sorry.
Well, we're using makerequest, and the following code seems to be keeping the SESSION stuff working:
session = app.unrestrictedTraverse('/session_data_manager').getSessionData app.REQUEST.set_lazy('SESSION', session)
Is that the 'right thing' to do?
That looks about right...
participants (2)
-
Chris McDonough -
Chris Withers