API Reference

The mbtest.server module

The mbtest.imposters.imposters module

class mbtest.imposters.imposters.Imposter(stubs, port=None, protocol=<Protocol.HTTP: 'http'>, name=None, record_requests=True)[source]

Represents a Mountebank imposter. Think of an imposter as a mock website, running a protocol, on a specific port. Required behaviors are specified using stubs.

Parameters
class Protocol[source]

Imposter Protocol.

HTTP = 'http'
HTTPS = 'https'
SMTP = 'smtp'
TCP = 'tcp'
property host
Return type

str

property url
Return type

furl

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Imposter

Returns

Converted object.

mbtest.imposters.imposters.smtp_imposter(name='smtp', record_requests=True)[source]

Canned SMTP server impostor.

Return type

Imposter

The mbtest.imposters.stubs module

class mbtest.imposters.stubs.Stub(predicates=None, responses=None)[source]

Represents a Mountebank stub. Think of a stub as a behavior, triggered by a matching predicate.

Parameters
as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Stub

Returns

Converted object.

class mbtest.imposters.stubs.Proxy(to, wait=None, inject_headers=None, mode=<Mode.ALWAYS: 'proxyAlways'>)[source]

Represents a Mountebank proxy.

Parameters

to (Union[furl, str]) – The origin server, to which the request should proxy.

class Mode[source]

Defines the replay behavior of the proxy.

ONCE = 'proxyOnce'
ALWAYS = 'proxyAlways'
TRANSPARENT = 'proxyTransparent'
as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Proxy

Returns

Converted object.

The mbtest.imposters.predicates module

class mbtest.imposters.predicates.BasePredicate[source]
static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

BasePredicate

Returns

Converted object.

class mbtest.imposters.predicates.Predicate(path=None, method=None, query=None, body=None, headers=None, xpath=None, operator=<Operator.EQUALS: 'equals'>, case_sensitive=True)[source]

Represents a Mountebank predicate. A predicate can be thought of as a trigger, which may or may not match a request.

Parameters
exception InvalidPredicateOperator[source]
class Method[source]

Predicate HTTP method.

DELETE = 'DELETE'
GET = 'GET'
HEAD = 'HEAD'
POST = 'POST'
PUT = 'PUT'
class Operator[source]

Predicate operator.

EQUALS = 'equals'
DEEP_EQUALS = 'deepEquals'
CONTAINS = 'contains'
STARTS_WITH = 'startsWith'
ENDS_WITH = 'endsWith'
MATCHES = 'matches'
EXISTS = 'exists'
classmethod has_value(name)[source]
Return type

bool

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Predicate

Returns

Converted object.

class mbtest.imposters.predicates.AndPredicate(left, right)[source]
as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

AndPredicate

Returns

Converted object.

class mbtest.imposters.predicates.OrPredicate(left, right)[source]
as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

OrPredicate

Returns

Converted object.

class mbtest.imposters.predicates.TcpPredicate(data)[source]
as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

TcpPredicate

Returns

Converted object.

The mbtest.imposters.responses module

class mbtest.imposters.responses.Response(body='', status_code=200, wait=None, repeat=None, headers=None, mode=None, copy=None, decorate=None, lookup=None, shell_transform=None)[source]

Represents a Mountebank ‘is’ response behavior.

Parameters
class Mode[source]

An enumeration.

TEXT = 'text'
BINARY = 'binary'
property body
Return type

str

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Response

Returns

Converted object.

class mbtest.imposters.responses.TcpResponse(data)[source]
as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

TcpResponse

Returns

Converted object.

The mbtest.imposters.behaviors.copy module

class mbtest.imposters.behaviors.copy.Copy(from_, into, using)[source]

Represents a copy behavior.

Parameters
  • from – The name of the request field to copy from, or, if the request field is an object, then an object specifying the path to the request field.

  • into (str) – The token to replace in the response with the selected request value.

  • using (Using) – The configuration needed to select values from the response.

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Copy

Returns

Converted object.

The mbtest.imposters.behaviors.lookup module

class mbtest.imposters.behaviors.lookup.Lookup(key, datasource_path, datasource_key_column, into)[source]

Represents a lookup behavior.

Parameters
  • key (Key) – How to select the key from the request.

  • datasource_path (Union[str, Path]) – The path to the data source.

  • datasource_key_column (str) – The header of the column to match against the key.

  • into (str) – The token to replace in the response with the selected request value.

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Lookup

Returns

Converted object.

class mbtest.imposters.behaviors.lookup.Key(from_, using, index=0)[source]

The information on how to select the key from the request.

Parameters
  • from – The name of the request field to copy from, or, if the request field is an object, then an object specifying the path to the request field.

  • using (Using) – The configuration needed to select values from the response

  • index (int) – Index of the iten from the result array to be selected.

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Key

Returns

Converted object.

The mbtest.imposters.behaviors.using module

class mbtest.imposters.behaviors.using.Using(method, selector)[source]

How to select values from the response.

Parameters
  • method (Method) – The method used to select the value(s) from the request.

  • selector (str) – The selector used to select the value(s) from the request.

class Method[source]

An enumeration.

REGEX = 'regex'
XPATH = 'xpath'
JSONPATH = 'jsonpath'
as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

Using

Returns

Converted object.

class mbtest.imposters.behaviors.using.UsingRegex(selector, ignore_case=False, multiline=False)[source]

Select values from the response using a regular expression.

Parameters
  • selector (str) – The selector used to select the value(s) from the request.

  • ignore_case (bool) – Uses a case-insensitive regular expression

  • multiline (bool) – Uses a multiline regular expression

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

UsingRegex

Returns

Converted object.

class mbtest.imposters.behaviors.using.UsingXpath(selector, ns=None)[source]

Select values from the response using an xpath expression.

Parameters
  • selector (str) – The selector used to select the value(s) from the request.

  • ns (Optional[Mapping[str, str]]) – The ns object maps namespace aliases to URLs

as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

UsingXpath

Returns

Converted object.

class mbtest.imposters.behaviors.using.UsingJsonpath(selector)[source]

Select values from the response using a jsonpath expression.

Parameters

selector (str) – The selector used to select the value(s) from the request.

static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure – JSON structure to be converted.

Return type

UsingJsonpath

Returns

Converted object.

The mbtest.matchers module

The mbtest.imposters.base module

class mbtest.imposters.base.JsonSerializable[source]

Object capable of being converted to a JSON serializable structure (using as_structure()) or from such a structure ((using from_structure()).

abstract as_structure()[source]

Converted to a JSON serializable structure.

Return type

Any

Returns

Structure suitable for JSON serialisation.

abstract static from_structure(structure)[source]

Converted from a JSON serializable structure.

Parameters

structure (Any) – JSON structure to be converted.

Return type

JsonSerializable

Returns

Converted object.

Indices and tables