Skip to content
Serialization for python-requests based on JSON.
Python
Latest commit 1f38b26 Aug 5, 2013 @kanzure README: one more TODO
Failed to load latest commit information.
requestions handle CaseInsensitiveDict with convert_to_dict Aug 5, 2013
tests/data httpetrified decorator for unit testing Feb 2, 2013
.gitignore initial commit Jan 29, 2013
MANIFEST.in Merge branch 'adamlwgriffiths/master' into master Aug 4, 2013
Makefile
README.md README: one more TODO Aug 5, 2013
setup.py Merge branch 'fix-case-insensitive-dict-serialization' into master Aug 5, 2013
test_requestions.py handle CaseInsensitiveDict with convert_to_dict Aug 5, 2013

README.md

Requestions

Requestions is a serialization library for Requests using JSON. Also, requestions includes a decorator called httpetrified for storing responses and replaying them in the future for HTTP testing without the live interwebz.

Installing

Simple.

sudo pip install requestions

or,

sudo python setup.py install

Usage

# responses
original_response = requests.get("http://httpbin.org/get")
serialized_response = requestions.write_response(original_response)
response = requestions.read_response(serialized_response)

# requests
original_request = requests.models.Request(url="http://httpbin.org/post", method="POST")
serialized_request = requestions.write_request(original_request)
request = requestions.read_request(serialized_request)

Decorator

Save responses in a json file, then use them later to make unit testing not so miserable.

import json
import requests
from requestions import httpetrified

def get_current_ip_address(self):
    "Abuses some poor sap's ip address detection service."
    response = requests.get("http://jsonip.com")
    return response.json()["ip"]

@httpetrified("samples/helpers/jsonip-request.json")
def test_get_current_ip_address(self):
    self.assertEqual("127.0.0.1", get_current_ip_address())

Changelog

  • 0.0.7 - fix CaseInsensitiveDict problem
  • 0.0.5 - fix broken setup.py, gah
  • 0.0.4 - fix test for both requests==0.14.2 and requests>=1.0.3
  • 0.0.3 - httpetrified decorator
  • 0.0.1 - initial commit

Alternatives

Related

TODO

  • support multiple requests/responses in a single json file. This will allow a single test to cause multiple requests to be made that can all be mocked simultaneously.

  • support streaming http responses like HTTPretty does

License

BSD.

Something went wrong with that request. Please try again.