A single HTTP request represented as a subclass of testtools.TestCase
The test case encapsulates the request headers and body and expected response headers and body. When the test is run an HTTP request is made using urllib3. Assertions are made against the reponse.
Bases: testtools.testcase.TestCase
Encapsulate a single HTTP request as a TestCase.
If the test is a member of a sequence of requests, ensure that prior tests are run.
To keep the test harness happy we need to make sure the setUp and tearDown are only run once.
Assert the iterable contains expected or print some output.
If the output is long, it is limited by either GABBI_MAX_CHARS_OUTPUT in the environment or the MAX_CHARS_OUTPUT constant.
Determine the content handler for this media type.
Replace magic strings in message.
Store the current result handler on this test.
Run this request if it has not yet run.
If there is a prior test in the sequence, run it first.
Decorate a test method that is expected to fail if ‘xfail’ is true.
Generate HTTP tests from YAML files
Each HTTP request is its own TestCase and can be requested to be run in isolation from other tests. If it is a member of a sequence of requests, prior requests will be run.
A sequence is represented by an ordered list in a single YAML file.
Each sequence becomes a TestSuite.
An entire directory of YAML files is a TestSuite of TestSuites.
Read YAML files from a directory to create tests.
Each YAML file represents an ordered sequence of HTTP requests.
Parameters: |
|
---|---|
Return type: | TestSuite containing multiple TestSuites (one for each YAML file). |
Generate tests cases for py.test
This uses build_tests to create TestCases and then yields them in a way that pytest can handle.
Legacy wrapper retained for backwards compatibility.
The code that creates a suite of tests.
The key piece of code is test_suite_from_dict(). It produces a gabbi.suite.GabbiSuite containing one or more gabbi.case.HTTPTestCase.
Bases: type
Metaclass to munge a dynamically created test.
Bases: object
A class for encapsulating test invariants.
All of the tests in a single gabbi file have invariants which are provided when creating each HTTPTestCase. It is not useful to pass these around when making each test case. So they are wrapped in this class which then has make_one_test called multiple times to generate all the tests in the suite.
Create one single HTTPTestCase.
The returned HTTPTestCase is added to the TestSuite currently being built (one per YAML file).
Generate a GabbiSuite from a dict represent a list of tests.
The dict takes the form:
Parameters: |
|
---|
Modify test in place to update with new data.
Manage fixtures for gabbi at the test suite level.
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.
Implement the actual workings of starting the fixture here.
Implement the actual workings of stopping the fixture here.
Bases: exceptions.Exception
Generic exception for GabbiFixture.
Bases: gabbi.fixture.GabbiFixture
A fixture that skips all the tests in the current suite.
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.
Package for response and content handlers that process the body of a response in various ways.
Base classes for response and content handlers.
Bases: gabbi.handlers.base.ResponseHandler
A subclass of ResponseHandlers that adds content handling.
Return True if this handler can handler this type.
Return structured data as a string.
If pretty is true, prettify.
Create structured (Python) data from a stream.
Return the string that is replacing RESPONSE.
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.
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.
Do any pre-single-test preprocessing.
Core response handlers.
Bases: gabbi.handlers.base.ResponseHandler
Test that listed headers are not in the response.
Bases: gabbi.handlers.base.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.
Bases: gabbi.handlers.base.ResponseHandler
Test for matching strings in the the response body.
JSON-related content handling.
Bases: gabbi.handlers.base.ContentHandler
A ContentHandler for JSON
Test json_paths against json data.
Extract the value at JSON Path path from the data.
The input data is a Python datastructure, not a JSON string.
A TestSuite for containing gabbi tests.
This suite has two features: the contained tests are ordered and there are suite-level fixtures that operate as context managers.
Bases: unittest.suite.TestSuite
A TestSuite with fixtures.
The suite wraps the tests with a set of nested context managers that operate as fixtures.
If a fixture raises unittest.case.SkipTest during setup, all the tests in this suite will be skipped.
Override TestSuite run to start suite-level fixtures.
To avoid exception confusion, use a null Fixture when there are no fixtures.
Start fixtures when using pytest.
Stop fixtures when using pytest.
A noop method used to disable collected tests.
Implementation of a command-line runner for gabbi files (AKA suites).
Extract command-line arguments following the – end-of-options delimiter, if any.
Load and return custom response handlers from the given Python package or module.
The import path references either a specific response handler class (“package.module:class”) or a module that contains one or more response handler classes (“package.module”).
For the latter, the module is expected to contain a gabbi_response_handlers object, which is either a list of response handler classes or a function returning such a list.
Run simple tests from STDIN.
This command provides a way to run a set of tests encoded in YAML that is provided on STDIN. No fixtures are supported, so this is primarily designed for use with real running services.
Host and port information may be provided in three different ways:
An example run might looks like this:
gabbi-run example.com:9999 < mytest.yaml
or:
gabbi-run http://example.com:999 < mytest.yaml
It is also possible to provide a URL prefix which can be useful if the target application might be mounted in different locations. An example:
gabbi-run example.com:9999 /mountpoint < mytest.yaml
or:
gabbi-run http://example.com:9999/mountpoint < mytest.yaml
Use -x or –failfast to abort after the first error or failure:
gabbi-run -x example.com:9999 /mountpoint < mytest.yaml
Use -v or –verbose with a value of all, headers or body to turn on verbosity for all tests being run.
Multiple files may be named as arguments, separated from other arguments by a --. Each file will be run as a separate test suite:
gabbi-run http://example.com -- /path/to/x.yaml /path/to/y.yaml
Output is formatted as unittest summary information.
Run the tests from the YAML in handle.
TestRunner and TestResult for gabbi-run.
Bases: unittest.runner.TextTestResult
A TextTestResult with simple but useful output.
If the output is a tty or GABBI_FORCE_COLOR is set in the environment, output will be colorized.
Bases: unittest.runner.TextTestRunner
A TextTestRunner that uses ConciseTestResult for reporting results.
alias of ConciseTestResult
Bases: unittest.result.TestResult
Wrap a test result to allow it to work with pytest.
The main behaviors here are:
Utility functions grab bag.
Given pieces of a path-based url, return a fully qualified url.
Decode content to a proper string.
Extract parsed content-type from headers.
Return a function to colorize a string.
Only if stream is a tty .
Turn url or host:port and target into test destination.
Read and parse any YAML file or filehandle.
Let exceptions flow where they may.
If no file or handle is provided, read from STDIN.
Decide if something is content we’d like to treat as a string.
Parse content type value for media type and charset.
Gabbi specific exceptions.
Bases: exceptions.ValueError
An exception to encapsulate poorly formed test data.
Bases: exceptions.SyntaxWarning
A warning about syntax that is not desirable.
Subclass of Http class for verbosity.
Bases: urllib3.poolmanager.PoolManager
A subclass of the urllib3.PoolManager to munge the data.
This transforms the response to look more like what httplib2 provided when it was used as the httpclient.
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
to any of: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE
Display request parameters before requesting.
Return an Http class for making requests.