HTTPretty is a HTTP client mock library for Python 100% inspired on ruby's FakeWeb
Motivation
When building systems that access external resources such as RESTful webservices, XMLRPC or even simple HTTP requests, we stumble in the problem:
"I'm gonna need to mock all those requests"
It brings a lot of hassle, you will need to use a generic mocking tool, mess with scope and so on.
The idea behind HTTPretty (how it works)
HTTPretty monkey matches Python's socket core module, reimplementing the HTTP protocol, by mocking requests and responses.
As for it works in this way, you don't need to worry what http library you're gonna use.
HTTPretty will mock the response for you :) (and also give you the latest requests so that you can check them)
Usage
expecting a simple response body
from httpretty import HTTPretty
HTTPretty.register_uri(HTTPretty.GET, "http://globo.com/",
body="The biggest portal in Brazil")
fd = urllib2.urlopen('http://globo.com')
got = fd.read()
fd.close()
print got
:: output ::
The biggest portal in Brazil
mocking the status code
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
body="here is the mocked body",
status=201)
fd = urllib2.urlopen('http://github.com')
got = fd.read()
fd.close()
assert got == "here is the mocked body"
assert fd.code == 201
Product's homepage
Requirements:
· Python