You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Greg Gauthier 428150e81f collect the pid of the server on startup, and kill it on shutdown 1 year ago
app remove cache directories 1 year ago
tests fixes 1 year ago
.gitignore fixes 1 year ago
Pipfile initial commit 1 year ago add console output examples to doc 3 years ago fixing bash installer 1 year ago
requirements.txt initial commit 1 year ago collect the pid of the server on startup, and kill it on shutdown 1 year ago



This is a very simple project to demonstrate the perported uses of HoverFly (an api mocking/simulation tool). In this case, the testing use case is demonstrated by way of a custom pytest suite found in the tests directory.


1> Run the included script. This will:

  • confirm that you have python3 installed and ready for use
  • confirm that you have the HoverFly CLI installed and ready for use
  • confirm that you have pipenv for python3, and configure your project virtual environment

2> Run the included script, after install. This will:

  • use the pipenv environment to execute the hoverfly tests with pytest. What are these tests doing? 1: fire up the flask app. 2: hit both the GET endpoint and the POST endpoint, and execute a simple assert on the response JSONs. The test is actually using the stored session data for its comparison, rather than testing within the session itself. The suite deletes the session data files, when all tests are complete.


The /app directory contains a very simple Flask server app, designed to emulate a live application with available api endpoints. It's useless beyond the scope of this demo. It models two simple GET requests, and a simple POST request, both of which return json responses as many of our service APIs do.

The /tests directory contains a few standard Flask app unit tests, merely for reference. The main event, is the file, which contains the test code that includes the use of HoverFly capture/simulate code. It's actually a bit underwhelming, because of how easy it is to use in tests.

The point of having both sets of tests, is to show the difference between what a set of unit tests on an api project would look like, compared with a separate set of hoverfly api tests, which would be written to talk directly to a live api (note how the hoverfly tests require me to start the server in the setup).

I'm not sure if the hoverfly CLI binaries are actually necessary for the python bindings to work, but I added the installation of them here anyway, just to be sure, and to provide some documentation for future installations.

Why does it matter that we're using stored session data, rather than executing asserts during an active session? Well, for one thing, the stored session data could be used to execute mocked tests at a later date (the server need not be live). Or, mock sessions could be used to model CONTRACTS. Or, they could be used for ongoing development on a new endpoint.

More experimentation needs to be done, to determine the full value of the tool.


gregory@orpheus $ ./                                                                                                                         (28m) |[master] 
Python 3.7.3
Dependency Graph:
  - click [required: >=5.1, installed: 7.0]
  - itsdangerous [required: >=0.24, installed: 1.1.0]
  - Jinja2 [required: >=2.10, installed: 2.10.1]
    - MarkupSafe [required: >=0.23, installed: 1.1.1]
  - Werkzeug [required: >=0.14, installed: 0.15.4]
  - requests [required: Any, installed: 2.22.0]
    - certifi [required: >=2017.4.17, installed: 2019.3.9]
    - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
    - idna [required: >=2.5,<2.9, installed: 2.8]
    - urllib3 [required: >=1.21.1,<1.26,!=1.25.1,!=1.25.0, installed: 1.25.2]
  - atomicwrites [required: >=1.0, installed: 1.3.0]
  - attrs [required: >=17.4.0, installed: 19.1.0]
  - more-itertools [required: >=4.0.0, installed: 7.0.0]
  - pluggy [required: >=0.9,<1.0,!=0.10, installed: 0.11.0]
  - py [required: >=1.5.0, installed: 1.8.0]
  - setuptools [required: Any, installed: 41.0.1]
  - six [required: >=1.10.0, installed: 1.12.0]
  - wcwidth [required: Any, installed: 0.1.7]


gregory@orpheus $ ./                                                                                                                          (2m) |[master] 
========================================================================= test session starts ==========================================================================
platform darwin -- Python 3.7.3, pytest-4.5.0, py-1.8.0, pluggy-0.11.0 -- /Users/gregory/.virtualenvs/pyfly-demo-Cl6C4Sqb/bin/python
cachedir: .pytest_cache
rootdir: /Users/gregory/Repositories/gitlab/gregory/pyfly-demo
collected 4 items                                                                                                                                                      

tests/ PASSED                                                                                                    [ 25%]
tests/ PASSED                                                                                                  [ 50%]
tests/ PASSED                                                                                                   [ 75%]
tests/ PASSED                                                                                                        [100%]

======================================================================= 4 passed in 0.62 seconds =======================================================================