views:

150

answers:

2

I really like the way fakeweb in Ruby can be used to fake http requests when testing. Is there a similar library or an alternative for Python?

+1  A: 

I recomend you produce a fake inteface to HTTP request like in questions 1016765 how-to-use-cookielib-with-httplib-in-python.

Charles Beattie
I don't know of a similar lib.
Charles Beattie
+2  A: 

See also http://stackoverflow.com/questions/295438/how-can-one-mock-stub-python-module-like-urllib/295503 . The answer that recommends Mox seems the most like fakeweb, but Mox lets you create fake versions of any module, not just urllib.

For incoming requests, if your web framework uses WebOb (repoze.bfg, Pylons others), you can use webob.Request.blank.

from webob import Request
r = Request.blank('/')
a_view_function(r)
joeforker