new version with new readme

This commit is contained in:
Gabriel Falcao
2012-11-08 16:15:52 -05:00
parent 0ba3ff6465
commit e00d89307d
2 changed files with 48 additions and 26 deletions

View File

@@ -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

View File

@@ -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