gabbi Package

case Module

driver Module

fixture Module

Manage fixtures for gabbi at the test suite level.

class gabbi.fixture.GabbiFixture

Bases: object

A context manager that operates as a fixture.

Subclasses must implement start_fixture and stop_fixture, each of which contain the logic for stopping and starting whatever the fixture is. What a fixture is is left as an exercise for the implementor.

These context managers will be nested so any actual work needs to happen in start_fixture and stop_fixture and not in __init__. Otherwise exception handling will not work properly.

start_fixture()

Implement the actual workings of starting the fixture here.

stop_fixture()

Implement the actual workings of stopping the fixture here.

exception gabbi.fixture.GabbiFixtureError

Bases: exceptions.Exception

Generic exception for GabbiFixture.

class gabbi.fixture.SkipAllFixture

Bases: gabbi.fixture.GabbiFixture

A fixture that skips all the tests in the current suite.

start_fixture()
gabbi.fixture.nest(*args, **kwds)

Nest a series of fixtures.

This is duplicated from nested in the stdlib, which has been deprecated because of issues with how exceptions are difficult to handle during __init__. Gabbi needs to nest an unknown number of fixtures dynamically, so the with syntax that replaces nested will not work.

handlers Module

Handlers for processing the body of a response in various ways.

class gabbi.handlers.ForbiddenHeadersResponseHandler(test_class)

Bases: gabbi.handlers.ResponseHandler

Test that listed headers are not in the response.

action(test, forbidden, value=None)
test_key_suffix = 'forbidden_headers'
test_key_value = []
class gabbi.handlers.HeadersResponseHandler(test_class)

Bases: gabbi.handlers.ResponseHandler

Compare expected headers with actual headers.

If a header value is wrapped in / it is treated as a raw regular expression.

Headers values are always treated as strings.

action(test, header, value=None)
test_key_suffix = 'headers'
test_key_value = {}
class gabbi.handlers.JSONResponseHandler(test_class)

Bases: gabbi.handlers.ResponseHandler

Test for matching json paths in the json_data.

action(test, path, value=None)

Test json_paths against json data.

test_key_suffix = 'json_paths'
test_key_value = {}
class gabbi.handlers.ResponseHandler(test_class)

Bases: object

Add functionality for making assertions about an HTTP response.

A subclass may implement two methods: action and preprocess.

preprocess takes one argument, the TestCase. It is called exactly once for each test before looping across the assertions. It is used, rarely, to copy the test.output into a useful form (such as a parsed DOM).

action takes two or three arguments. If test_key_value is a list action is called with the test case and a single list item. If test_key_value is a dict then action is called with the test case and a key and value pair.

action(test, item, value=None)

Test an individual entry for this response handler.

If the entry is a key value pair the key is in item and the value in value. Otherwise the entry is considered a single item from a list.

preprocess(test)

Do any pre-single-test preprocessing.

test_key_suffix = ''
test_key_value = []
class gabbi.handlers.StringResponseHandler(test_class)

Bases: gabbi.handlers.ResponseHandler

Test for matching strings in the the response body.

action(test, expected, value=None)
test_key_suffix = 'strings'
test_key_value = []

suite Module

runner Module

utils Module

Utility functions grab bag.

gabbi.utils.create_url(base_url, host, port=None, prefix='', ssl=False)

Given pieces of a path-based url, return a fully qualified url.

gabbi.utils.decode_response_content(header_dict, content)

Decode content to a proper string.

gabbi.utils.extract_content_type(header_dict)

Extract content-type from headers.

gabbi.utils.get_colorizer(stream)

Return a function to colorize a string.

Only if stream is a tty .

gabbi.utils.not_binary(content_type)

Decide if something is content we’d like to treat as a string.

httpclient Module

Subclass of Http class for verbosity.

class gabbi.httpclient.Http(num_pools=10, headers=None, **connection_pool_kw)

Bases: urllib3.poolmanager.PoolManager

request(absolute_uri, method, body, headers, redirect)
class gabbi.httpclient.VerboseHttp(**kwargs)

Bases: gabbi.httpclient.Http

A subclass of Http that verbosely reports on activity.

If the output is a tty or GABBI_FORCE_COLOR is set in the environment, then output will be colorized according to COLORMAP.

Output can include request and response headers, request and response body content (if of a printable content-type), or both.

The color of the output has reasonable defaults. These may be overridden by setting the following environment variables

  • GABBI_CAPTION_COLOR
  • GABBI_HEADER_COLOR
  • GABBI_REQUEST_COLOR
  • GABBI_STATUS_COLOR

to any of: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE

COLORMAP = {'status': 'CYAN', 'caption': 'BLUE', 'request': 'CYAN', 'header': 'YELLOW'}
HEADER_BLACKLIST = ['status', 'reason']
REQUEST_PREFIX = '>'
RESPONSE_PREFIX = '<'
request(absolute_uri, method, body, headers, redirect)

Display request parameters before requesting.

gabbi.httpclient.get_http(verbose=False, caption='')

Return an Http class for making requests.