Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library like fakeweb for Python

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?

like image 643
VoY Avatar asked Jan 29 '10 13:01

VoY


2 Answers

See also How can one mock/stub python module like urllib . 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)
like image 170
joeforker Avatar answered Sep 25 '22 04:09

joeforker


HTTPretty works in the exact same way that FakeWeb does. HTTPretty works in the socket layer, so it should work intercepting any python http client libraries. It's battle tested against urllib2, httplib2 and requests

like image 25
Gabriel Falcão Avatar answered Sep 22 '22 04:09

Gabriel Falcão