bravado Package¶
bravado
Package¶
client
Module¶
The SwaggerClient
provides an interface for making API calls based on
a swagger spec, and returns responses of python objects which build from the
API response.
Structure Diagram:
+---------------------+
| |
| SwaggerClient |
| |
+------+--------------+
|
| has many
|
+------v--------------+
| |
| Resource +------------------+
| | |
+------+--------------+ has many |
| |
| has many |
| |
+------v--------------+ +------v--------------+
| | | |
| Operation | | SwaggerModel |
| | | |
+------+--------------+ +---------------------+
|
| uses
|
+------v--------------+
| |
| HttpClient |
| |
+---------------------+
To get a client
client = bravado.client.SwaggerClient.from_url(swagger_spec_url)
-
class
bravado.client.
ResourceDecorator
(resource, also_return_response=False)¶ Bases:
object
Wraps
bravado_core.resource.Resource
so that accesses to contained operations can be instrumented.
-
class
bravado.client.
SwaggerClient
(swagger_spec, also_return_response=False)¶ Bases:
object
A client for accessing a Swagger-documented RESTful service.
-
classmethod
from_spec
(spec_dict, origin_url=None, http_client=None, config=None)¶ Build a
SwaggerClient
from a Swagger spec in dict form.Parameters: - spec_dict – a dict with a Swagger spec in json-like form
- origin_url (str) – the url used to retrieve the spec_dict
- config – Configuration dict - see spec.CONFIG_DEFAULTS
Return type:
-
classmethod
from_url
(spec_url, http_client=None, request_headers=None, config=None)¶ Build a
SwaggerClient
from a url to the Swagger specification for a RESTful API.Parameters: - spec_url (str) – url pointing at the swagger API specification
- http_client (
bravado.http_client.HttpClient
) – an HTTP client used to perform requests - request_headers (dict) – Headers to pass with http requests
- config – Config dict for bravado and bravado_core. See CONFIG_DEFAULTS in :module:`bravado_core.spec`. See CONFIG_DEFAULTS in :module:`bravado.client`.
Return type:
-
get_model
(model_name)¶
-
is_equal
(other)¶
-
classmethod
-
bravado.client.
construct_params
(operation, request, op_kwargs)¶ Given the parameters passed to the operation invocation, validates and marshals the parameters into the provided request dict.
Parameters: op_kwargs – the kwargs passed to the operation invocation Raises: SwaggerMappingError on extra parameters or when a required parameter is not supplied.
-
bravado.client.
construct_request
(operation, request_options, **op_kwargs)¶ Construct the outgoing request dict.
Parameters: - request_options – _request_options passed into the operation invocation.
- op_kwargs – parameter name/value pairs to passed to the invocation of the operation.
Returns: request in dict form
-
bravado.client.
inject_headers_for_remote_refs
(request_callable, request_headers)¶ Inject request_headers only when the request is to retrieve the remote refs in the swagger spec (vs being a request for a service call).
Parameters: - request_callable – method on http_client to make a http request
- request_headers – headers to inject when retrieving remote refs
config
Module¶
-
class
bravado.config.
BravadoConfig
(also_return_response, disable_fallback_results, response_metadata_class)¶ Bases:
tuple
Create new instance of BravadoConfig(also_return_response, disable_fallback_results, response_metadata_class)
-
also_return_response
¶ Alias for field number 0
-
disable_fallback_results
¶ Alias for field number 1
-
response_metadata_class
¶ Alias for field number 2
-
-
class
bravado.config.
RequestConfig
(request_options, also_return_response_default)¶ Bases:
object
-
additional_properties
= {}¶
-
also_return_response
= False¶
-
connect_timeout
= None¶
-
force_fallback_result
= False¶
-
headers
= {}¶
-
response_callbacks
= []¶
-
timeout
= None¶
-
use_msgpack
= False¶
-
-
bravado.config.
bravado_config_from_config_dict
(config_dict)¶
requests_client
Module¶
-
class
bravado.requests_client.
ApiKeyAuthenticator
(host, api_key, param_name='api_key', param_in='query')¶ Bases:
bravado.requests_client.Authenticator
?api_key authenticator.
This authenticator adds an API key via query parameter or header.
Parameters: - host – Host to authenticate for.
- api_key – API key.
- param_name – Query parameter specifying the API key.
- param_in – How to send the API key. Can be ‘query’ or ‘header’.
-
apply
(request)¶ Apply authentication to a request.
Parameters: request – Request to add authentication information to.
-
class
bravado.requests_client.
Authenticator
(host)¶ Bases:
object
Authenticates requests.
Parameters: host – Host to authenticate for. -
apply
(request)¶ Apply authentication to a request.
Parameters: request – Request to add authentication information to.
-
matches
(url)¶ Returns true if this authenticator applies to the given url.
Parameters: url – URL to check. Returns: True if matches host and port, False otherwise.
-
-
class
bravado.requests_client.
BasicAuthenticator
(host, username, password)¶ Bases:
bravado.requests_client.Authenticator
HTTP Basic authenticator.
Parameters: - host – Host to authenticate for.
- username – Username.
- password – Password
-
apply
(request)¶ Apply authentication to a request.
Parameters: request – Request to add authentication information to.
-
class
bravado.requests_client.
RequestsClient
(ssl_verify=True, ssl_cert=None, future_adapter_class=<class 'bravado.requests_client.RequestsFutureAdapter'>, response_adapter_class=<class 'bravado.requests_client.RequestsResponseAdapter'>)¶ Bases:
bravado.http_client.HttpClient
Synchronous HTTP client implementation.
Parameters: - ssl_verify – Set to False to disable SSL certificate validation. Provide the path to a CA bundle if you need to use a custom one.
- ssl_cert – Provide a client-side certificate to use. Either a sequence of strings pointing to the certificate (1) and the private key (2), or a string pointing to the combined certificate and key.
- future_adapter_class – Custom future adapter class,
should be a subclass of
RequestsFutureAdapter
- response_adapter_class – Custom response adapter class,
should be a subclass of
RequestsResponseAdapter
-
apply_authentication
(request)¶
-
authenticated_request
(request_params)¶
-
request
(request_params, operation=None, request_config=None)¶ Parameters: - request_params (dict) – complete request data.
- operation (
bravado_core.operation.Operation
) – operation that this http request is for. Defaults to None - in which case, we’re obviously just retrieving a Swagger Spec. - request_config (RequestConfig) – per-request configuration
Returns: HTTP Future object
Return type: class: bravado_core.http_future.HttpFuture
-
separate_params
(request_params)¶ Splits the passed in dict of request_params into two buckets.
- sanitized_params are valid kwargs for constructing a requests.Request(..)
- misc_options are things like timeouts which can’t be communicated to the Requests library via the requests.Request(…) constructor.
Parameters: request_params – kitchen sink of request params. Treated as a read-only dict. Returns: tuple(sanitized_params, misc_options)
-
set_api_key
(host, api_key, param_name='api_key', param_in='query')¶
-
set_basic_auth
(host, username, password)¶
-
class
bravado.requests_client.
RequestsFutureAdapter
(session, request, misc_options)¶ Bases:
bravado.http_future.FutureAdapter
Mimics a
concurrent.futures.Future
for the purposes of making HTTP calls with the Requests library in a future-y sort of way.Kicks API call for Requests client
Parameters: - session – session object to use for making the request
- request – dict containing API request parameters
- misc_options (dict) – misc options to apply when sending a HTTP request. e.g. timeout, connect_timeout, etc
-
build_timeout
(result_timeout)¶ Build the appropriate timeout object to pass to session.send(…) based on connect_timeout, the timeout passed to the service call, and the timeout passed to the result call.
Parameters: result_timeout – timeout that was passed into future.result(..) Returns: timeout Return type: float or tuple(connect_timeout, timeout)
-
cancel
()¶ Must implement a cancel method which terminates any ongoing network request.
-
connection_errors
= (<class 'requests.exceptions.ConnectionError'>,)¶
-
result
(timeout=None)¶ Blocking call to wait for API response
Parameters: timeout (float) – timeout in seconds to wait for response. Defaults to None to wait indefinitely. Returns: raw response from the server Return type: dict
-
timeout_errors
= (<class 'requests.exceptions.ReadTimeout'>,)¶
-
class
bravado.requests_client.
RequestsResponseAdapter
(requests_lib_response)¶ Bases:
bravado_core.response.IncomingResponse
Wraps a requests.models.Response object to provide a uniform interface to the response innards.
-
headers
¶
-
json
(**kwargs)¶ Returns: response content in a json-like form Return type: int, float, double, string, unicode, list, dict
-
raw_bytes
¶
-
reason
¶
-
status_code
¶
-
text
¶
-
fido_client
Module¶
-
class
bravado.fido_client.
FidoClient
(future_adapter_class=<class 'bravado.fido_client.FidoFutureAdapter'>, response_adapter_class=<class 'bravado.fido_client.FidoResponseAdapter'>)¶ Bases:
bravado.http_client.HttpClient
Fido (Asynchronous) HTTP client implementation.
Parameters: - future_adapter_class – Custom future adapter class,
should be a subclass of
FidoFutureAdapter
- response_adapter_class – Custom response adapter class,
should be a subclass of
FidoResponseAdapter
-
static
prepare_request_for_twisted
(request_params)¶ Uses the python package ‘requests’ to prepare the data as per twisted needs. requests.PreparedRequest.prepare is able to compute the body and the headers for the http call based on the input request_params. This contains any query parameters, files, body and headers to include.
Returns: dictionary in the form { - ’body’: string, # (can represent any content-type i.e. json,
- file, multipart..),
’headers’: dictionary, # headers->values ‘method’: string, # can be ‘GET’, ‘POST’ etc. ‘url’: string, ‘timeout’: float, # optional ‘connect_timeout’: float, # optional
}
-
request
(request_params, operation=None, request_config=None)¶ Sets up the request params as per Twisted Agent needs. Sets up crochet and triggers the API request in background
Parameters: - request_params (dict) – request parameters for the http request.
- operation (
bravado_core.operation.Operation
) – operation that this http request is for. Defaults to None - in which case, we’re obviously just retrieving a Swagger Spec. - request_config (RequestConfig) – per-request configuration
Return type: class: bravado_core.http_future.HttpFuture
- future_adapter_class – Custom future adapter class,
should be a subclass of
-
class
bravado.fido_client.
FidoFutureAdapter
(eventual_result)¶ Bases:
bravado.http_future.FutureAdapter
This is just a wrapper for an EventualResult object from crochet. It implements the ‘result’ method which is needed by our HttpFuture to retrieve results.
-
cancel
()¶ Must implement a cancel method which terminates any ongoing network request.
-
connection_errors
= (<class 'fido.exceptions.TCPConnectionError'>, <class 'twisted.internet.error.ConnectingCancelledError'>, <class 'twisted.internet.error.DNSLookupError'>, <class 'twisted.web._newclient.RequestNotSent'>)¶
-
result
(timeout=None)¶ Must implement a result method which blocks on result retrieval.
Parameters: timeout – maximum time to wait on result retrieval. Defaults to None which means blocking undefinitely.
-
timeout_errors
= (<class 'fido.exceptions.HTTPTimeoutError'>,)¶
-
-
class
bravado.fido_client.
FidoResponseAdapter
(fido_response)¶ Bases:
bravado_core.response.IncomingResponse
Wraps a fido.fido.Response object to provide a uniform interface to the response innards.
-
headers
¶
-
json
(**_)¶ Returns: response content in a json-like form Return type: int, float, double, string, unicode, list, dict
-
raw_bytes
¶
-
reason
¶
-
status_code
¶
-
text
¶
-
http_future
Module¶
-
class
bravado.http_future.
FutureAdapter
¶ Bases:
typing.Generic
Mimics a
concurrent.futures.Future
regardless of which client is performing the request, whether it is synchronous or actually asynchronous.This adapter must be implemented by all bravado clients such as FidoClient or RequestsClient to wrap the object returned by their ‘request’ method.
-
cancel
()¶ Must implement a cancel method which terminates any ongoing network request.
-
connection_errors
= ()¶
-
result
(timeout=None)¶ Must implement a result method which blocks on result retrieval.
Parameters: timeout – maximum time to wait on result retrieval. Defaults to None which means blocking undefinitely.
-
timeout_errors
= ()¶
-
-
class
bravado.http_future.
HttpFuture
(future, response_adapter, operation=None, request_config=None)¶ Bases:
typing.Generic
Wrapper for a
FutureAdapter
that returns an HTTP response.Parameters: - future – The future object to wrap.
- response_adapter (type that is a subclass of
bravado_core.response.IncomingResponse
.) – Adapter type which exposes the innards of the HTTP response in a non-http client specific way. - request_config (RequestConfig) – See
bravado.config.RequestConfig
andbravado.client.REQUEST_OPTIONS_DEFAULTS
-
cancel
()¶
-
response
(timeout=None, fallback_result=<bravado.http_future._SENTINEL object>, exceptions_to_catch=(<class 'bravado.exception.BravadoTimeoutError'>, <class 'bravado.exception.BravadoConnectionError'>, <class 'bravado.exception.HTTPServerError'>))¶ Blocking call to wait for the HTTP response.
Parameters: - timeout (float) – Number of seconds to wait for a response. Defaults to None which means wait indefinitely.
- fallback_result – either the swagger result or a callable that accepts an exception as argument and returns the swagger result to use in case of errors
- exceptions_to_catch – Exception classes to catch and call fallback_result with. Has no effect if fallback_result is not provided. By default, fallback_result will be called for read timeout and server errors (HTTP 5XX).
Returns: A BravadoResponse instance containing the swagger result and response metadata.
-
result
(timeout=None)¶ DEPRECATED: please use the response() method instead.
Blocking call to wait for and return the unmarshalled swagger result.
Parameters: timeout (float) – Number of seconds to wait for a response. Defaults to None which means wait indefinitely. Returns: Depends on the value of also_return_response sent in to the constructor.
-
bravado.http_future.
raise_on_expected
(http_response)¶ Raise an HTTPError if the response is non-2XX and matches a response in the swagger spec.
Parameters: http_response – bravado_core.response.IncomingResponse
Raises: HTTPError
-
bravado.http_future.
raise_on_unexpected
(http_response)¶ Raise an HTTPError if the response is 5XX.
Parameters: http_response – bravado_core.response.IncomingResponse
Raises: HTTPError
-
bravado.http_future.
reraise_errors
(func)¶
-
bravado.http_future.
unmarshal_response
(incoming_response, operation, response_callbacks=None)¶ So the http_client is finished with its part of processing the response. This hands the response over to bravado_core for validation and unmarshalling and then runs any response callbacks. On success, the swagger_result is available as
incoming_response.swagger_result
. :type incoming_response:bravado_core.response.IncomingResponse
:type operation:bravado_core.operation.Operation
:type response_callbacks: list of callable. Seebravado_core.client.REQUEST_OPTIONS_DEFAULTS.Raises: HTTPError - On 5XX status code, the HTTPError has minimal information. - On non-2XX status code with no matching response, the HTTPError
contains a detailed error message.
- On non-2XX status code with a matching response, the HTTPError
- contains the return value.
-
bravado.http_future.
unmarshal_response_inner
(response, op)¶ Unmarshal incoming http response into a value based on the response specification. :type response:
bravado_core.response.IncomingResponse
:type op:bravado_core.operation.Operation
:returns: value where type(value) matches response_spec[‘schema’][‘type’]if it exists, None otherwise.
response
Module¶
-
class
bravado.response.
BravadoResponse
(result, metadata)¶ Bases:
typing.Generic
Bravado response object containing the swagger result as well as response metadata.
Variables: - result – Swagger result from the server
- metadata (BravadoResponseMetadata) – metadata for this response including HTTP response
-
incoming_response
¶
-
class
bravado.response.
BravadoResponseMetadata
(incoming_response, swagger_result, start_time, request_end_time, handled_exception_info, request_config)¶ Bases:
typing.Generic
HTTP response metadata.
NOTE: The elapsed_time attribute might be slightly lower than the actual time spent since calling the operation object, as we only start measuring once the call to HTTPClient.request returns. Nevertheless, it should be accurate enough for logging and debugging, i.e. determining what went on and how much time was spent waiting for the response.
Variables: - start_time (float) – monotonic timestamp at which the future was created
- request_end_time (float) – monotonic timestamp at which we received the HTTP response
- processing_end_time (float) – monotonic timestamp at which processing the response ended
- handled_exception_info (tuple) – 3-tuple of exception class, exception instance and string representation of the traceback in case an exception was caught during request processing.
Parameters: - incoming_response – a subclass of bravado_core.response.IncomingResponse.
- swagger_result – the unmarshalled result that is being returned to the user.
- start_time – monotonic timestamp indicating when the HTTP future was created. Depending on the internal operation of the HTTP client used, this is either before the HTTP request was initiated (default client) or right after the HTTP request was sent (e.g. bravado-asyncio / fido).
- request_end_time – monotonic timestamp indicating when we received the incoming response, excluding unmarshalling, validation or potential fallback result processing.
- handled_exception_info – sys.exc_info() data if an exception was caught and handled as part of a fallback response; note that the third element in the list is a string representation of the traceback, not a traceback object.
- request_config (RequestConfig) – namedtuple containing the request options that were used for making this request.
-
elapsed_time
¶
-
headers
¶
-
incoming_response
¶
-
is_fallback_result
¶
-
request_elapsed_time
¶
-
status_code
¶
exception
Module¶
-
exception
bravado.exception.
BravadoConnectionError
¶ Bases:
ConnectionError
-
exception
bravado.exception.
BravadoTimeoutError
¶ Bases:
TimeoutError
-
exception
bravado.exception.
ForcedFallbackResultError
¶ Bases:
Exception
This exception will be handled if the option to force returning a fallback result is used.
-
exception
bravado.exception.
HTTPBadGateway
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/502 - Bad Gateway
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 502¶
-
exception
bravado.exception.
HTTPBadRequest
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/400 - Bad Request
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 400¶
-
exception
bravado.exception.
HTTPClientError
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPError
4xx responses.
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
exception
bravado.exception.
HTTPConflict
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/409 - Conflict
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 409¶
-
exception
bravado.exception.
HTTPError
(response, message=None, swagger_result=None)¶ Bases:
OSError
Unified HTTPError used across all http_client implementations.
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= None¶
-
class
bravado.exception.
HTTPErrorType
¶ Bases:
type
A metaclass for registering HTTPError subclasses.
-
exception
bravado.exception.
HTTPExpectationFailed
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/417 - Expectation Failed
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 417¶
-
exception
bravado.exception.
HTTPFailedDependency
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/424 - Failed Dependency
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 424¶
-
exception
bravado.exception.
HTTPForbidden
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/403 - Forbidden
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 403¶
-
exception
bravado.exception.
HTTPFound
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/302 - Found
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 302¶
-
exception
bravado.exception.
HTTPGatewayTimeout
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/504 - Gateway Timeout
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 504¶
-
exception
bravado.exception.
HTTPGone
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/410 - Gone
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 410¶
-
exception
bravado.exception.
HTTPHTTPVersionNotSupported
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/505 - HTTP Version Not Supported
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 505¶
-
exception
bravado.exception.
HTTPInsufficientStorage
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/507 - Insufficient Storage
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 507¶
-
exception
bravado.exception.
HTTPInternalServerError
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/500 - Internal Server Error
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 500¶
-
exception
bravado.exception.
HTTPLengthRequired
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/411 - Length Required
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 411¶
-
exception
bravado.exception.
HTTPLocked
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/423 - Locked
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 423¶
-
exception
bravado.exception.
HTTPLoopDetected
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/508 - Loop Detected
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 508¶
-
exception
bravado.exception.
HTTPMethodNotAllowed
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/405 - Method Not Allowed
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 405¶
-
exception
bravado.exception.
HTTPMisdirectedRequest
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/421 - Misdirected Request
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 421¶
-
exception
bravado.exception.
HTTPMovedPermanently
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/301 - Moved Permanently
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 301¶
-
exception
bravado.exception.
HTTPMultipleChoices
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/300 - Multiple Choices
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 300¶
-
exception
bravado.exception.
HTTPNetworkAuthenticationRequired
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/511 - Network Authentication Required
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 511¶
-
exception
bravado.exception.
HTTPNotAcceptable
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/406 - Not Acceptable
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 406¶
-
exception
bravado.exception.
HTTPNotExtended
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/510 - Not Extended
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 510¶
-
exception
bravado.exception.
HTTPNotFound
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/404 - Not Found
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 404¶
-
exception
bravado.exception.
HTTPNotImplemented
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/501 - Not Implemented
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 501¶
-
exception
bravado.exception.
HTTPNotModified
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/304 - Not Modified
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 304¶
-
exception
bravado.exception.
HTTPPayloadTooLarge
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/413 - Payload Too Large
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 413¶
-
exception
bravado.exception.
HTTPPaymentRequired
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/402 - Payment Required
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 402¶
-
exception
bravado.exception.
HTTPPermanentRedirect
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/308 - Permanent Redirect
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 308¶
-
exception
bravado.exception.
HTTPPreconditionFailed
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/412 - Precondition Failed
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 412¶
-
exception
bravado.exception.
HTTPPreconditionRequired
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/428 - Precondition Required
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 428¶
-
exception
bravado.exception.
HTTPProxyAuthenticationRequired
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/407 - Proxy Authentication Required
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 407¶
-
exception
bravado.exception.
HTTPRangeNotSatisfiable
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/416 - Range Not Satisfiable
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 416¶
-
exception
bravado.exception.
HTTPRedirection
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPError
3xx responses.
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
exception
bravado.exception.
HTTPRequestHeaderFieldsTooLarge
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/431 - Request Header Fields Too Large
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 431¶
-
exception
bravado.exception.
HTTPRequestTimeout
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/408 - Request Timeout
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 408¶
-
exception
bravado.exception.
HTTPSeeOther
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/303 - See Other
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 303¶
-
exception
bravado.exception.
HTTPServerError
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPError
5xx responses.
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
Bases:
bravado.exception.HTTPServerError
HTTP/503 - Service Unavailable
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
exception
bravado.exception.
HTTPTemporaryRedirect
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/307 - Temporary Redirect
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 307¶
-
exception
bravado.exception.
HTTPTooManyRequests
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/429 - Too Many Requests
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 429¶
-
exception
bravado.exception.
HTTPURITooLong
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/414 - URI Too Long
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 414¶
Bases:
bravado.exception.HTTPClientError
HTTP/401 - Unauthorized
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
Bases:
bravado.exception.HTTPClientError
HTTP/451 - Unavailable For Legal Reasons
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
exception
bravado.exception.
HTTPUnprocessableEntity
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/422 - Unprocessable Entity
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 422¶
-
exception
bravado.exception.
HTTPUnsupportedMediaType
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/415 - Unsupported Media Type
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 415¶
-
exception
bravado.exception.
HTTPUpgradeRequired
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPClientError
HTTP/426 - Upgrade Required
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 426¶
-
exception
bravado.exception.
HTTPUseProxy
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPRedirection
HTTP/305 - Use Proxy
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 305¶
-
exception
bravado.exception.
HTTPVariantAlsoNegotiates
(response, message=None, swagger_result=None)¶ Bases:
bravado.exception.HTTPServerError
HTTP/506 - Variant Also Negotiates
Parameters: - message – Optional string message
- swagger_result – If the response for this HTTPError is documented in the swagger spec, then this should be the result value of the response.
-
status_code
= 506¶
-
bravado.exception.
make_http_exception
(response, message=None, swagger_result=None)¶ Return an HTTP exception class based on the response. If a specific class doesn’t exist for a particular HTTP status code, a more general
HTTPError
class will be returned. :type response:bravado_core.response.IncomingResponse
:param message: Optional string message :param swagger_result: If the response for this HTTPError isdocumented in the swagger spec, then this should be the result value of the response.Returns: An HTTP exception class that can be raised
testing
Module¶
-
class
bravado.testing.integration_test.
IntegrationTestingFixturesMixin
¶ Bases:
bravado.testing.integration_test.IntegrationTestingServicesAndClient
Generic class to run integration tests with the different HTTP clients definitions
-
connection_errors_exceptions
= None¶
-
classmethod
encode_expected_response
(response)¶
-
http_client
= None¶
-
http_client_type
= None¶
-
http_future_adapter_type
= None¶
-
classmethod
setup_class
()¶
-
swagger_client
(swagger_http_server)¶
-
-
class
bravado.testing.integration_test.
IntegrationTestingServicesAndClient
¶ Bases:
object
-
not_answering_http_server
()¶
-
result_getter
(request)¶
-
swagger_http_server
()¶
-
-
class
bravado.testing.integration_test.
IntegrationTestsBaseClass
¶ Bases:
bravado.testing.integration_test.IntegrationTestingFixturesMixin
-
test_connection_errors_are_catchable_with_original_exception_types
(not_answering_http_server)¶
-
test_connection_errors_are_thrown_as_BravadoConnectionError
(not_answering_http_server)¶
-
test_connection_errors_exceptions_contains_all_future_adapter_connection_errors
()¶
-
test_fetch_specs
(swagger_http_server)¶
-
test_following_redirects
(swagger_http_server)¶
-
test_msgpack_support
(swagger_http_server)¶
-
test_multiple_requests
(swagger_http_server)¶
-
test_non_string_headers
(swagger_http_server)¶
-
test_post_request
(swagger_http_server)¶
-
test_redirects_are_not_followed
(swagger_http_server)¶
-
test_request_timeout_errors_are_thrown_as_BravadoTimeoutError
(swagger_http_server)¶
-
test_sanitized_resource_and_param
(swagger_client, result_getter)¶
-
test_swagger_client_connection_errors_are_thrown_as_BravadoConnectionError
(not_answering_http_server, swagger_client, result_getter)¶
-
test_swagger_client_json_response
(swagger_client, result_getter)¶
-
test_swagger_client_msgpack_response_with_flag
(swagger_client, result_getter)¶
-
test_swagger_client_msgpack_response_without_flag
(swagger_client, result_getter)¶
-
test_swagger_client_special_chars_path
(swagger_client, result_getter)¶
-
test_swagger_client_special_chars_query
(swagger_client, result_getter)¶
-
test_swagger_client_timeout_errors_are_thrown_as_BravadoTimeoutError
(swagger_client, result_getter)¶
-
test_timeout_errors_are_catchable_with_original_exception_types
(swagger_http_server)¶
-
test_timeout_errors_are_thrown_as_BravadoTimeoutError
(swagger_http_server)¶
-
test_unsanitized_param_as_header
(swagger_client, result_getter)¶
-
test_unsanitized_resource_and_param
(swagger_client, result_getter)¶
-
-
bravado.testing.integration_test.
api_json
()¶
-
bravado.testing.integration_test.
api_json_or_msgpack
()¶
-
bravado.testing.integration_test.
char_test
()¶
-
bravado.testing.integration_test.
double
()¶
-
bravado.testing.integration_test.
echo
()¶
-
bravado.testing.integration_test.
headers
()¶
-
bravado.testing.integration_test.
one
()¶
-
bravado.testing.integration_test.
redirect_test
()¶
-
bravado.testing.integration_test.
run_bottle_server
(port)¶ Wrapper function for bottle.run so that the child Python interpreter finds the bottle routes on Windows.
-
bravado.testing.integration_test.
sanitize_test
()¶
-
bravado.testing.integration_test.
sleep_api
()¶
-
bravado.testing.integration_test.
swagger_spec
()¶
-
bravado.testing.integration_test.
two
()¶
-
class
bravado.testing.response_mocks.
BravadoResponseMock
(result, metadata=None)¶ Bases:
typing.Generic
Class that behaves like the
HttpFuture.response()
method as well as aBravadoResponse
. Please check the documentation for further information.-
metadata
¶
-
result
¶
-
-
class
bravado.testing.response_mocks.
FallbackResultBravadoResponseMock
(exception=BravadoTimeoutError(), metadata=None)¶ Bases:
object
Class that behaves like the
HttpFuture.response()
method as well as aBravadoResponse
. It will always call thefallback_result
callback that’s passed to theresponse()
method. Please check the documentation for further information.-
metadata
¶
-
result
¶
-
-
class
bravado.testing.response_mocks.
IncomingResponseMock
(status_code, **kwargs)¶ Bases:
bravado_core.response.IncomingResponse