2014-12-31 17:08:23 +00:00
|
|
|
.. Gabbi documentation master file, created by
|
|
|
|
sphinx-quickstart on Wed Dec 31 17:07:32 2014.
|
|
|
|
You can adapt this file completely to your liking, but it should at least
|
|
|
|
contain the root `toctree` directive.
|
|
|
|
|
|
|
|
.. toctree::
|
2014-12-31 21:42:50 +00:00
|
|
|
:maxdepth: 1
|
|
|
|
:hidden:
|
|
|
|
|
|
|
|
format
|
2015-04-20 20:10:04 +01:00
|
|
|
example
|
2015-08-04 19:01:06 +01:00
|
|
|
jsonpath
|
2014-12-31 21:42:50 +00:00
|
|
|
host
|
|
|
|
fixtures
|
2015-03-30 22:12:58 +01:00
|
|
|
handlers
|
2015-04-15 19:03:54 +01:00
|
|
|
runner
|
2014-12-31 21:42:50 +00:00
|
|
|
gabbi
|
|
|
|
|
|
|
|
Gabbi
|
|
|
|
=====
|
|
|
|
|
2016-04-29 12:32:35 +01:00
|
|
|
.. highlight:: yaml
|
|
|
|
|
2014-12-31 21:42:50 +00:00
|
|
|
Gabbi is a tool for running HTTP tests where requests and responses
|
2016-04-29 12:32:35 +01:00
|
|
|
are expressed as declarations in a collection of YAML files. The
|
|
|
|
simplest test looks like this::
|
|
|
|
|
|
|
|
tests:
|
|
|
|
- name: A test
|
|
|
|
GET: /api/resources/id
|
|
|
|
|
|
|
|
See the rest of these docs for more details on the many features and
|
|
|
|
formats for setting request headers and bodies and evaluating responses.
|
2014-12-31 21:42:50 +00:00
|
|
|
|
2015-01-01 16:34:03 +00:00
|
|
|
The name is derived from "gabby": excessively talkative. In a test
|
2015-04-15 19:03:54 +01:00
|
|
|
environment having visibility of what a test is actually doing is a
|
2016-04-29 12:32:35 +01:00
|
|
|
good thing. This is especially true when the goal of a test is to
|
|
|
|
test the HTTP, not the testing infrastructure. Gabbi tries to put
|
|
|
|
the HTTP interaction in the foreground of testing.
|
2015-04-15 19:03:54 +01:00
|
|
|
|
2015-07-14 10:14:05 +01:00
|
|
|
Tests can be run using :ref:`unittest <test_loaders>` style test
|
2016-04-06 14:20:30 +01:00
|
|
|
runners or py.test or from the command line with a :doc:`gabbi-run <runner>` script.
|
2015-07-14 10:14:05 +01:00
|
|
|
|
2015-04-20 20:21:52 +01:00
|
|
|
If you want to get straight to creating tests look at
|
2015-04-20 20:10:04 +01:00
|
|
|
:doc:`example`, the test files in the `source distribution`_
|
2015-06-05 11:14:25 +01:00
|
|
|
and :doc:`format`. A `gabbi-demo`_ repository provides a tutorial
|
|
|
|
of using gabbi to build an API, via the commit history of the repo.
|
2014-12-31 21:42:50 +00:00
|
|
|
|
|
|
|
.. _source distribution: https://github.com/cdent/gabbi
|
2015-06-05 11:14:25 +01:00
|
|
|
.. _gabbi-demo: https://github.com/cdent/gabbi-demo
|
2014-12-31 21:42:50 +00:00
|
|
|
|
|
|
|
Purpose
|
|
|
|
-------
|
|
|
|
|
2016-04-29 12:32:35 +01:00
|
|
|
.. highlight:: none
|
|
|
|
|
2014-12-31 21:42:50 +00:00
|
|
|
Gabbi works to bridge the gap between human readable YAML files (see
|
|
|
|
:doc:`format` for details) that represent HTTP requests and expected
|
2015-04-15 19:03:54 +01:00
|
|
|
responses and the rather complex world of automated testing.
|
2014-12-31 21:42:50 +00:00
|
|
|
|
|
|
|
Each YAML file represents an ordered list of HTTP requests along with
|
|
|
|
the expected responses. This allows a single file to represent a
|
|
|
|
process in the API being tested. For example:
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
These features mean that it is possible to create tests that are useful
|
|
|
|
for both humans (as tools for learning, improving and developing APIs)
|
|
|
|
and automated CI systems.
|
|
|
|
|
2015-04-15 19:03:54 +01:00
|
|
|
Significant flexibility and power is available in the :doc:`format` to
|
|
|
|
make it relatively straightforward to test existing complex APIs.
|
|
|
|
This extended functionality includes the use of `JSONPath`_ to query
|
|
|
|
response bodies and templating of test data to allow access to the prior
|
|
|
|
HTTP response in the current request. For APIs which do not use JSON
|
|
|
|
additional :doc:`handlers` can be created.
|
2014-12-31 21:42:50 +00:00
|
|
|
|
2015-04-15 19:03:54 +01:00
|
|
|
Care should be taken when using this functionality when you are
|
|
|
|
creating a new API. If your API is so complex that it needs complex
|
2014-12-31 21:42:50 +00:00
|
|
|
test files then you may wish to take that as a sign that your API
|
2015-04-15 19:03:54 +01:00
|
|
|
itself too complex. One goal of gabbi is to encourage transparent
|
|
|
|
and comprehensible APIs.
|
|
|
|
|
|
|
|
Though gabbi is written in Python and under the covers uses
|
|
|
|
``unittest`` data structures and processes, there is no requirement
|
|
|
|
that the :doc:`host` be a Python-based service. Anything talking
|
|
|
|
HTTP can be tested. A :doc:`runner` makes it possible to simply
|
|
|
|
create YAML files and point them at a running server.
|
2015-01-01 16:34:03 +00:00
|
|
|
|
|
|
|
.. _JSONPath: http://goessner.net/articles/JsonPath/
|