2014-12-27 15:41:29 +00:00
|
|
|
.. image:: https://travis-ci.org/cdent/gabbi.svg?branch=master
|
|
|
|
:target: https://travis-ci.org/cdent/gabbi
|
2014-12-31 22:17:31 +00:00
|
|
|
.. image:: https://readthedocs.org/projects/gabbi/badge/?version=latest
|
2016-04-29 12:32:35 +01:00
|
|
|
:target: https://gabbi.readthedocs.io/en/latest/
|
2014-12-31 22:17:31 +00:00
|
|
|
:alt: Documentation Status
|
2014-12-27 15:41:29 +00:00
|
|
|
|
2015-04-08 00:00:03 +01:00
|
|
|
Gabbi
|
2014-10-27 16:24:39 +00:00
|
|
|
=====
|
|
|
|
|
2016-06-16 11:21:36 +01:00
|
|
|
`Release Notes`_
|
|
|
|
|
2014-10-27 16:24:39 +00:00
|
|
|
Gabbi is a tool for running HTTP tests where requests and responses
|
2016-04-29 12:32:35 +01:00
|
|
|
are represented in a declarative YAML-based form. The simplest test
|
|
|
|
looks like this::
|
|
|
|
|
|
|
|
tests:
|
|
|
|
- name: A test
|
|
|
|
GET: /api/resources/id
|
|
|
|
|
|
|
|
See the docs_ for more details on the many features and formats for
|
|
|
|
setting request headers and bodies and evaluating responses.
|
2014-12-12 14:46:03 +00:00
|
|
|
|
2017-01-02 12:07:59 +00:00
|
|
|
Gabbi is tested with Python 2.7, 3.4, 3.5, 3.6 and pypy.
|
2015-07-14 10:14:05 +01:00
|
|
|
|
2016-04-16 02:52:12 +01:00
|
|
|
Tests can be run using `unittest`_ style test runners, `pytest`_
|
|
|
|
or from the command line with a `gabbi-run`_ script.
|
2015-01-14 14:43:22 +00:00
|
|
|
|
2015-06-05 11:14:25 +01:00
|
|
|
There is a `gabbi-demo`_ repository which provides a tutorial via
|
|
|
|
its commit history. The demo builds a simple API using gabbi to
|
|
|
|
facilitate test driven development.
|
|
|
|
|
2016-06-16 11:21:36 +01:00
|
|
|
.. _Release Notes: https://gabbi.readthedocs.io/en/latest/release.html
|
2016-04-29 12:32:35 +01:00
|
|
|
.. _docs: https://gabbi.readthedocs.io/
|
2015-06-05 11:14:25 +01:00
|
|
|
.. _gabbi-demo: https://github.com/cdent/gabbi-demo
|
2016-04-29 12:32:35 +01:00
|
|
|
.. _unittest: https://gabbi.readthedocs.io/en/latest/example.html#loader
|
2016-04-06 14:20:30 +01:00
|
|
|
.. _pytest: http://pytest.org/
|
2016-04-29 12:32:35 +01:00
|
|
|
.. _loader docs: https://gabbi.readthedocs.io/en/latest/example.html#pytest
|
|
|
|
.. _gabbi-run: https://gabbi.readthedocs.io/en/latest/runner.html
|
2014-12-15 13:04:08 +00:00
|
|
|
|
|
|
|
Purpose
|
|
|
|
-------
|
|
|
|
|
|
|
|
Gabbi works to bridge the gap between human readable YAML files that
|
|
|
|
represent HTTP requests and expected responses and the obscured realm of
|
|
|
|
Python-based, object-oriented unit tests in the style of the unittest
|
|
|
|
module and its derivatives.
|
|
|
|
|
2014-12-27 20:20:32 +00:00
|
|
|
Each YAML file represents an ordered list of HTTP requests along with
|
2014-12-15 13:04:08 +00:00
|
|
|
the expected responses. This allows a single file to represent a
|
2014-12-27 20:20:32 +00:00
|
|
|
process in the API being tested. For example:
|
2014-12-15 13:04:08 +00:00
|
|
|
|
|
|
|
* Create a resource.
|
|
|
|
* Retrieve a resource.
|
|
|
|
* Delete a resource.
|
|
|
|
* Retrieve a resource again to confirm it is gone.
|
|
|
|
|
|
|
|
At the same time it is still possible to ask gabbi to run just one
|
|
|
|
request. If it is in a sequence of tests, those tests prior to it in
|
|
|
|
the YAML file will be run (in order). In any single process any test
|
|
|
|
will only be run once. Concurrency is handled such that one file
|
|
|
|
runs in one process.
|
|
|
|
|
2014-12-27 20:20:32 +00:00
|
|
|
These features mean that it is possible to create tests that are
|
2014-12-15 13:04:08 +00:00
|
|
|
useful for both humans (as tools for improving and developing APIs)
|
|
|
|
and automated CI systems.
|
|
|
|
|
2014-12-17 16:44:43 +00:00
|
|
|
Testing
|
|
|
|
-------
|
|
|
|
|
2014-12-27 20:20:32 +00:00
|
|
|
To run the built in tests (the YAML files are in the directories
|
|
|
|
``gabbi/gabbits_*`` and loaded by the file ``gabbi/test_*.py``),
|
2015-01-14 08:15:44 -08:00
|
|
|
you can use ``tox``::
|
2014-12-17 16:44:43 +00:00
|
|
|
|
2015-06-04 13:58:15 +00:00
|
|
|
tox -epep8,py27,py34
|
2014-12-17 16:44:43 +00:00
|
|
|
|
2014-12-22 15:04:21 +00:00
|
|
|
Or if you have the dependencies installed (or a warmed up
|
|
|
|
virtualenv) you can run the tests by hand and exit on the first
|
2015-01-14 08:15:44 -08:00
|
|
|
failure::
|
2014-12-17 16:44:43 +00:00
|
|
|
|
2014-12-27 20:20:32 +00:00
|
|
|
python -m subunit.run discover -f gabbi | subunit2pyunit
|
2015-09-30 12:03:55 +02:00
|
|
|
|
|
|
|
Testing can be limited to individual modules by specifying them
|
|
|
|
after the tox invocation::
|
|
|
|
|
|
|
|
tox -epep8,py27,py34 -- test_driver test_handlers
|
2016-05-06 13:23:18 +01:00
|
|
|
|
|
|
|
If you wish to avoid running tests that connect to internet hosts,
|
|
|
|
set ``GABBI_SKIP_NETWORK`` to ``True``.
|