Skip to content

Commit

Permalink
This is a pretty significant change. This version of HoverPy now uses…
Browse files Browse the repository at this point in the history
… Hoverfly 0.10.1. There's been some reshuffling of the modules, instead of having the main HoverPy class inside __init__.py, it is now in hp.py. A decorators.py file has also been added. A lib folder has been added, which contains configurators, to get other networking libraries to play with hoverpy more easily.

Support and examples have been added for tornado and twisted. The docs were altered quite a lot to show all these changes.
  • Loading branch information
shyal committed Feb 17, 2017
1 parent 0338541 commit 07303ca
Show file tree
Hide file tree
Showing 51 changed files with 1,146 additions and 1,637 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.db
.venv
.eggs
*.bak
Expand Down
108 changes: 108 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
HoverPy
=======

HoverPy speeds up and simplifies Python development and testing that involves downstream HTTP / HTTPS services. It does so by using a high-performance Go caching proxy to capture, simulate, modify and synthesize network traffic.

.. code:: python
from hoverpy import capture, simulate
import requests
@capture("requests.db")
def captured_get():
print(requests.get("http://time.jsontest.com").json())
@simulate("requests.db")
def simulated_get():
print(requests.get("http://time.jsontest.com").json())
captured_get()
simulated_get()
This grants several benefits:

- Increased development speed
- Increased test speed
- Ability to work offline
- A deterministic test environment
- Ability to modify traffic
- Ability to sythesize traffic
- Ability to simulate network latency

.. code:: python
from hoverpy import capture, modify
import requests
@simulate("requests.db", delays=[("time.json.com", 1000)])
def simulated_latency():
print(requests.get("http://time.jsontest.com").json())
@modify(middleware="python middleware.py")
def modified_request():
print(requests.get("http://time.jsontest.com").json())
simulated_latency()
modified_request()
If/when the downstream service you are testing against changes, then you can simply delete your db file, and capture the test results again. Or you could have versioned db files for services that use versioning.

HoverPy uses `Hoverfly <http://hoverfly.io>`__ a Service Virtualisation server written in GoLang. For this reason it is rock solid in terms of speed and reliability.

Library Support
~~~~~~~~~~~~~~~

HoverPy works great with the following HTTP clients out of the box:

- tornado
- twisted
- requests
- urllib2
- urllib3
- pysimplesoap
- etc.

Since HoverPy can act as a proxy or a reverse proxy, it can easily be made to work with any networking library or framework.

Source
~~~~~~

https://github.com/SpectoLabs/hoverpy/

.. image:: hoverpy_logo.png

License
~~~~~~~

HoverPy uses Apache License V2. See LICENSE.txt for more details.

.. |PyPI version| image:: https://badge.fury.io/py/hoverpy.svg
:target: https://pypi.python.org/pypi/hoverpy
.. |RTD badget| image:: https://readthedocs.org/projects/hoverpy/badge/?version=latest
:target: http://hoverpy.readthedocs.io/en/latest/
.. |Build Status| image:: https://travis-ci.org/SpectoLabs/hoverpy.svg?branch=master
:target: https://travis-ci.org/SpectoLabs/hoverpy

Contents
========

.. toctree::
:maxdepth: 3

pages/installation
pages/introduction
pages/usage/usage

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`


|
|PyPI version| |RTD badget| |Build Status|

|
81 changes: 55 additions & 26 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,54 +1,76 @@
HoverPy
=======

.. image:: hoverpy_logo.png
HoverPy speeds up and simplifies Python development and testing that involves downstream HTTP / HTTPS services. It does so by using a high-performance Go caching proxy to capture, simulate, modify and synthesize network traffic.

|
.. code:: python
|PyPI version| |RTD badget| |Build Status|
from hoverpy import capture, simulate
import requests
|
@capture("requests.db")
def captured_get():
print(requests.get("http://time.jsontest.com").json())
What is HoverPy?
=================
@simulate("requests.db")
def simulated_get():
print(requests.get("http://time.jsontest.com").json())
HoverPy speeds up and simplifies tests that depend on HTTP / HTTPS
services. It does so by recording all HTTP traffic generated by your
python application inside a database file.
captured_get()
simulated_get()
When you run your code again, it plays back the responses corresponding
to your requests. This means during the simulate phase, no HTTP traffic
gets generated whatsoever. This grants several benefits:
This grants several benefits:

- Increased development speed
- Increased test speed
- Ability to work offline
- A deterministic test environment
- Ability to modify traffic
- Ability to sythesize traffic
- Ability to simulate network latency
- Deterministic test environment

If/when the service you are testing against changes its API, then you
can simply delete your db file, and capture the test results again.
.. code:: python
HoverPy uses `Hoverfly <http://hoverfly.io>`__, a high-performance API
simulation tool written in Go. For this reason it is rock solid in terms of
speed and reliability.
from hoverpy import capture, modify
import requests
HoverPy and Hoverfly are developed and maintained by `SpectoLabs <https://specto.io>`_.
@simulate("requests.db", delays=[("time.json.com", 1000)])
def simulated_latency():
print(requests.get("http://time.jsontest.com").json())
@modify(middleware="python middleware.py")
def modified_request():
print(requests.get("http://time.jsontest.com").json())
Support
~~~~~~~
simulated_latency()
modified_request()
If/when the downstream service you are testing against changes, then you can simply delete your db file, and capture the test results again. Or you could have versioned db files for services that use versioning.

HoverPy uses `Hoverfly <http://hoverfly.io>`__ a Service Virtualisation server written in GoLang. For this reason it is rock solid in terms of speed and reliability.

Library Support
~~~~~~~~~~~~~~~

HoverPy works great with the following HTTP clients out of the box:

HoverPy works great with the following HTTP clients:
- :ref:`tornado`
- :ref:`twisted`
- :ref:`requests <basic>`
- :ref:`urllib2`
- :ref:`urllib3`
- :ref:`pysimplesoap`
- etc.

- requests
- urllib2
- urllib3
- TBD
Since HoverPy can act as a proxy or a reverse proxy, it can easily be made to work with any networking library or framework.

Source
~~~~~~

https://github.com/SpectoLabs/hoverpy/

.. image:: hoverpy_logo.png

License
~~~~~~~

Expand Down Expand Up @@ -77,3 +99,10 @@ Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`


|
|PyPI version| |RTD badget| |Build Status|

|
25 changes: 9 additions & 16 deletions docs/pages/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
Installation
============

Installing from PIP
-------------------

You can also install HoverPy from PIP:

.. code:: bash
$ pip install hoverpy
Cloning
-------

Expand Down Expand Up @@ -54,22 +63,6 @@ Please note we'll cover the examples in the `usage`_ page. But for the truly imp
$ python examples/basic/basic.py
Installing from repo
--------------------

.. code:: bash
$ sudo python setup.py install
Installing from PIP
-------------------

You can also install HoverPy from PIP:

.. code:: bash
$ pip install hoverpy
Hoverfly binary
---------------

Expand Down
49 changes: 5 additions & 44 deletions docs/pages/usage/basic.rst
Original file line number Diff line number Diff line change
@@ -1,54 +1,15 @@
.. basic
.. _basic:

=====
basic
=====

This is by far the simplest example on how to get started with HoverPy. Please run this example using:
This is by far the simplest example on how to get started with HoverPy.

``$ python examples/basic/basic.py``

You should see your IP address show up twice. Let's walk through the code to see what's happening.

::

>>> from hoverpy import HoverPy
>>> import requests


Above, we start by importing our most important class `HoverPy`. We also bring in ``requests`` for our http traffic.

.. hoverpy: hoverpy.html#module-hoverpy
Now let's create our HoverPy object in capture mode. We do so with a `with` statement as this is the pythonic way, although this is not a necessity.

::

>>> with HoverPy(capture=True) as hoverpy:


Print the json from our get request. Hoverpy acted as a proxy: it made the request on our behalf, captured it, and returned it to us.

::

>>> print(requests.get("http://ip.jsontest.com/myip").json())


Switch HoverPy to simulate mode. HoverPy no longer acts as a proxy; all it does from now on is replay the captured data.

::

>>> hoverpy.simulate()


Print the json from our get request. This time the data comes from the store.

::

>>> print(requests.get("http://ip.jsontest.com/myip").json())
.. literalinclude:: ../../../examples/basic/basic.py

``$ python examples/basic/basic.py``

Requests.db
-----------
You should see time printed twice. Notice the time is the same on each request, that is because the ``simulated_get`` was served from data that was captured while calling ``captured_get``.

You may have noticed this created a ``requests.db`` inside your current directory. This is a boltdb database, holding our requests, and their responses.

0 comments on commit 07303ca

Please sign in to comment.