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
stubs (
Union
[Stub
,Proxy
,Iterable
[Union
[Stub
,Proxy
]]]) – One or more Stubs.protocol (
Protocol
) – Protocol to run on.name (
Optional
[str
]) – Impostor name - useful for interactive exploration of impostors on http://localhost:2525/impostorsrecord_requests (
bool
) – Record requests made against this impostor, so they can be asserted against later.
-
class
Protocol
[source]¶ Imposter Protocol.
-
HTTP
= 'http'¶
-
HTTPS
= 'https'¶
-
SMTP
= 'smtp'¶
-
TCP
= 'tcp'¶
-
-
property
url
¶ - Return type
furl
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
-
class
mbtest.imposters.stubs.
Proxy
(to, wait=None, inject_headers=None, mode=<Mode.ALWAYS: 'proxyAlways'>)[source]¶ Represents a Mountebank proxy.
-
class
Mode
[source]¶ Defines the replay behavior of the proxy.
-
ONCE
= 'proxyOnce'¶
-
ALWAYS
= 'proxyAlways'¶
-
TRANSPARENT
= 'proxyTransparent'¶
-
-
class
The mbtest.imposters.predicates module¶
-
class
mbtest.imposters.predicates.
BasePredicate
[source]¶
-
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
-
class
Method
[source]¶ Predicate HTTP method.
-
DELETE
= 'DELETE'¶
-
GET
= 'GET'¶
-
HEAD
= 'HEAD'¶
-
POST
= 'POST'¶
-
PUT
= 'PUT'¶
-
-
class
Operator
[source]¶ -
-
EQUALS
= 'equals'¶
-
DEEP_EQUALS
= 'deepEquals'¶
-
CONTAINS
= 'contains'¶
-
STARTS_WITH
= 'startsWith'¶
-
ENDS_WITH
= 'endsWith'¶
-
MATCHES
= 'matches'¶
-
EXISTS
= 'exists'¶
-
-
class
mbtest.imposters.predicates.
AndPredicate
(left, right)[source]¶ -
as_structure
()[source]¶ Converted to a JSON serializable structure.
- Return type
- Returns
Structure suitable for JSON serialisation.
-
-
class
mbtest.imposters.predicates.
OrPredicate
(left, right)[source]¶ -
as_structure
()[source]¶ Converted to a JSON serializable structure.
- Return type
- Returns
Structure suitable for JSON serialisation.
-
-
class
mbtest.imposters.predicates.
TcpPredicate
(data)[source]¶ -
as_structure
()[source]¶ Converted to a JSON serializable structure.
- Return type
- Returns
Structure suitable for JSON serialisation.
-
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
body (
str
) – Body text for response. Can be a string, or a JSON serialisable data structure.wait (
Union
[int
,str
,None
]) – Add latency, in ms.repeat (
Optional
[int
]) – Repeat this many times before moving on to next response.headers (
Optional
[Mapping
[str
,str
]]) – Response HTTP headersdecorate (
Optional
[str
]) – Decorate behavior.shell_transform (
Union
[str
,Iterable
[str
],None
]) – shellTransform behavior
-
class
mbtest.imposters.responses.
TcpResponse
(data)[source]¶ -
as_structure
()[source]¶ Converted to a JSON serializable structure.
- Return type
- Returns
Structure suitable for JSON serialisation.
-
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.
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
The mbtest.imposters.behaviors.using module¶
-
class
mbtest.imposters.behaviors.using.
Using
(method, selector)[source]¶ How to select values from the response.
- Parameters
-
class
mbtest.imposters.behaviors.using.
UsingRegex
(selector, ignore_case=False, multiline=False)[source]¶ Select values from the response using a regular expression.
- Parameters
-
as_structure
()[source]¶ Converted to a JSON serializable structure.
- Return type
- Returns
Structure suitable for JSON serialisation.
-
class
mbtest.imposters.behaviors.using.
UsingXpath
(selector, ns=None)[source]¶ Select values from the response using an xpath expression.
- Parameters
-
as_structure
()[source]¶ Converted to a JSON serializable structure.
- Return type
- Returns
Structure suitable for JSON serialisation.
-
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.
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 ((usingfrom_structure()
).-
abstract
as_structure
()[source]¶ Converted to a JSON serializable structure.
- Return type
- Returns
Structure suitable for JSON serialisation.
-
abstract