From e00d89307d9a3bdf65e862ce36dc323ac120a9ec Mon Sep 17 00:00:00 2001 From: Gabriel Falcao Date: Thu, 8 Nov 2012 16:15:52 -0500 Subject: [PATCH] new version with new readme --- README.md | 72 ++++++++++++++++++++++++++++--------------- httpretty/__init__.py | 2 +- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 783367b..17864d4 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,39 @@ # HTTPretty -> Version 0.5 +> Version 0.5.1 + [![Build Status](https://secure.travis-ci.org/gabrielfalcao/HTTPretty.png)](http://travis-ci.org/gabrielfalcao/HTTPretty) -# changes +# In a nutshell -## version 0.5 +Once upon a time a python developer wanted to use a RESTful api, +everything was fine but until the day he needed to test the code that +hits the RESTful API: what if the API server is down? What if its +content has changed ? -* supporting `https` (SSL'ed URLs) +Don't worry, HTTPretty is here for you: -# What +```python +import requests +from sure import expect +from httpretty import HTTPretty +from httpretty import httprettified -HTTPretty is a HTTP client mock library for Python 100% inspired on ruby's [FakeWeb](http://fakeweb.rubyforge.org/) -# Motivation +@httprettified +def test_yipit_api_returning_deals(): + HTTPretty.register_uri(HTTPretty.GET, "http://api.yipit.com/v1/deals/", + body="[{"title": "Test Deal"}]", + content_type="application/json") -When building systems that access external resources such as RESTful -webservices, XMLRPC or even simple HTTP requests, we stumble in the -problem: + response = requests.get('http://api.yipit.com/v1/deals/') - "I'm gonna need to mock all those requests" + expect(response.json).to.equal([{"title": "Test Deal"}]) +``` -It brings a lot of hassle, you will need to use a generic mocking -tool, mess with scope and so on. +# A more technical description -## The idea behind HTTPretty (how it works) - -HTTPretty [monkey matches](http://en.wikipedia.org/wiki/Monkey_patch) -Python's [socket](http://docs.python.org/library/socket.html) 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)* +HTTPretty is a HTTP client mock library for Python 100% inspired on ruby's [FakeWeb](http://fakeweb.rubyforge.org/). +If you come from ruby this would probably sound familiar :smiley: # Usage @@ -123,7 +123,6 @@ assert fd.code == 500 ``` - ## rotating responses same URL, same request method, the first request return the first @@ -183,6 +182,29 @@ expect(HTTPretty.last_request.method).to.equal("POST") expect(HTTPretty.last_request.headers['content-type']).to.equal('text/json') ``` +# 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](http://en.wikipedia.org/wiki/Monkey_patch) +Python's [socket](http://docs.python.org/library/socket.html) 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)* + # Acknowledgements ## caveats with the [requests](http://docs.python-requests.org/en/latest/) library diff --git a/httpretty/__init__.py b/httpretty/__init__.py index c178303..432cc00 100644 --- a/httpretty/__init__.py +++ b/httpretty/__init__.py @@ -23,7 +23,7 @@ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. -version = '0.5' +version = '0.5.1' import re import socket