Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanzure/python-requestions
Serialization for python-requests based on JSON.
https://github.com/kanzure/python-requestions
Last synced: 3 months ago
JSON representation
Serialization for python-requests based on JSON.
- Host: GitHub
- URL: https://github.com/kanzure/python-requestions
- Owner: kanzure
- Created: 2013-01-30T02:54:21.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-05T06:10:05.000Z (over 11 years ago)
- Last Synced: 2024-09-14T05:28:48.803Z (4 months ago)
- Language: Python
- Size: 86.9 KB
- Stars: 14
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Requestions
Requestions is a serialization library for [Requests](https://github.com/kennethreitz/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.
``` bash
sudo pip install requestions
```or,
``` bash
sudo python setup.py install
```## Usage
``` python
# 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.
``` python
import json
import requests
from requestions import httpetrifieddef 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
* [requests-vcr](https://github.com/sigmavirus24/requests-vcr)
## Related
* [HTTPretty](https://github.com/gabrielfalcao/HTTPretty)
## 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.