https://github.com/the-allanc/pyriform
Connect the requests library to your WSGI app without using sockets.
https://github.com/the-allanc/pyriform
requests-module testing wsgi
Last synced: about 2 months ago
JSON representation
Connect the requests library to your WSGI app without using sockets.
- Host: GitHub
- URL: https://github.com/the-allanc/pyriform
- Owner: the-allanc
- License: mit
- Created: 2017-08-27T22:39:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-14T00:12:38.000Z (over 7 years ago)
- Last Synced: 2025-02-17T09:40:04.264Z (4 months ago)
- Topics: requests-module, testing, wsgi
- Language: Python
- Homepage: https://pyriform.readthedocs.io/
- Size: 88.9 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
.. |name| replace:: pyriform
.. |summary| replace:: Connect the requests library to your WSGI app without using sockets.|name|
======|summary|
.. _repository: https://github.com/the-allanc/pyriform/
.. _documentation: https://pyriform.readthedocs.io/en/stable/
.. _pypi: https://pypi.python.org/pypi/pyriform
.. _coveralls: https://coveralls.io/github/the-allanc/pyriform
.. _license: https://github.com/the-allanc/pyriform/master/LICENSE.txt
.. _travis: https://travis-ci.org/the-allanc/pyriform
.. _codeclimate: https://codeclimate.com/github/the-allanc/pyriform.. |Build Status| image:: https://img.shields.io/travis/the-allanc/pyriform.svg
:target: travis_
:alt: Build Status
.. |Coverage| image:: https://img.shields.io/coveralls/the-allanc/pyriform.svg
:target: coveralls_
:alt: Coverage
.. |Docs| image:: https://readthedocs.org/projects/pyriform/badge/?version=stable&style=flat
:target: documentation_
:alt: Docs
.. |Release Version| image:: https://img.shields.io/pypi/pyversions/pyriform.svg
:target: pypi_
:alt: Release Version
.. |Python Version| image:: https://img.shields.io/pypi/v/pyriform.svg
:target: pypi_
:alt: Python Version
.. |License| image:: https://img.shields.io/pypi/l/pyriform.svg
:target: license_
:alt: License
.. |Code Climate| image:: https://img.shields.io/codeclimate/issues/github/the-allanc/pyriform.svg
:target: codeclimate_
:alt: Code Climate.. _requests: http://python-requests.org
.. _webtest: https://docs.pylonsproject.org/projects/webtest/Linking the Requests_ and WebTest_ libraries together, ``pyriform`` allows you to use the ``requests`` library to interact your WSGI app without needing to have it running on the network; it bonds these two web components together.
It's useful for testing purposes, handles all standard HTTP methods (as well as custom ones), supports request timeouts. and is both Python 2 and 3 compatible.
Example Usage
-------------.. _cherrypy: http://www.cherrypy.org
Here's an example with a small WSGI app (in this case, using CherryPy_), and how we can use Pyriform to connect to it::
>>> # Create the WSGI app.
>>>
>>> import cherrypy
>>>
>>> class SayHello(object):
...
... @cherrypy.expose
... def default(self, word):
... return "Hello %s from %s!" % (word, cherrypy.request.headers['X-Location'])
...
>>> cherrypy.config.update({'environment': 'embedded'}) # Suppress logging output.
>>> app = cherrypy.tree.mount(SayHello(), '/')
>>>
>>> # Now use Pyriform to map requests from a particular URL to this app.
>>>
>>> import pyriform
>>> import requests
>>> adapter = pyriform.WSGIAdapter(app)
>>> session = requests.Session()
>>> session.mount('http://helloapp/', adapter)
>>> resp = session.get('http://helloapp/World', headers={'X-Location': 'London'})
>>> print (resp.text)
Hello World from London!|Docs| |Release Version| |Python Version| |License| |Build Status| |Coverage| |Code Climate|
.. all-content-above-will-be-included-in-sphinx-docs
You can browse the source code and file bug reports at the project repository_. Full documentation can be found `here`__.
__ documentation_