HTTPretty

HTTP client mock for Python
Download

HTTPretty Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Publisher Name:
  • Gabriel Falcao
  • Publisher web site:
  • http://gabrielfalcao.com

HTTPretty Tags


HTTPretty Description

HTTP client mock for Python HTTPretty is a HTTP client mock library for Python 100% inspired on ruby's FakeWebMotivationWhen 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)Usageexpecting a simple response bodyfrom httpretty import HTTPrettyHTTPretty.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 Brazilmocking the status codeHTTPretty.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 Requirements: · Python


HTTPretty Related Software