I've been using nosetests to test my controller methods, it is
terrific!    I'm trying to test a method which redirects one way on
success, and another on failure.    The test
testutil.call(cherrypy.root.orders.mymethod)
raises:

AttributeError: DummyRequest instance has no attribute 'object_trail'

 I want to check where the redirection will lead.  I came up with this
solution:

from turbogears.testutil import DummyRequest

class DummyRedirect(Exception):
    def __init__(self,urls,**kw):
        self.urls = urls
cherrypy.HTTPRedirect = DummyRedirect

class LessDumbRequest(DummyRequest):
    def __init__(self,**kw):
        DummyRequest.__init__(self,kw)
        self.object_trail=[[None,None]]

try:
 
testutil.call_with_request(cherrypy.root.orders.authorize,LessDumbRequest(),**self.kwargs)
except DummyRedirect, e:
    assert e.urls.endswith("/nextlocation")

This seems like a lot of hoops to jump through, but it works great.
So I'm wondering if there is already an existing way of doing this
test, or if any of this technique would be useful to testutil.
Thanks!

--Joseph


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to