Welcome to mbtest’s documentation#
Opinionated Python wrapper & utils for the Mountebank over the wire test double tool.
Includes pytest fixture and PyHamcrest matchers.
Contents:
- Guide
- API Reference
- The mbtest.server module
- The mbtest.imposters.imposters module
- The mbtest.imposters.stubs module
- The mbtest.imposters.predicates module
- The mbtest.imposters.responses module
- The mbtest.imposters.behaviors.copy module
- The mbtest.imposters.behaviors.lookup module
- The mbtest.imposters.behaviors.using module
- The mbtest.matchers module
- The mbtest.imposters.base module
- Indices and tables
Installation#
Install from Pypi as usual, using pip , tox, or setup.py
.
Also requires Mountebank to have been installed:
$ npm install mountebank@2.6 --production
Usage#
A basic example:
import requests
from hamcrest import assert_that
from brunns.matchers.response import is_response
from mbtest.matchers import had_request
from mbtest.imposters import Imposter, Predicate, Response, Stub
def test_request_to_mock_server(mock_server):
# Set up mock server with required behavior
imposter = Imposter(Stub(Predicate(path="/test"),
Response(body="sausages")))
with mock_server(imposter):
# Make request to mock server - exercise code under test here
response = requests.get(f"{imposter.url}/test")
assert_that("We got the expected response",
response, is_response().with_status_code(200).and_body("sausages"))
assert_that("The mock server recorded the request",
imposter, had_request().with_path("/test").and_method("GET"))
Needs a pytest fixture, most easily defined in conftest.py:
import pytest
from mbtest import server
@pytest.fixture(scope="session")
def mock_server(request):
return server.mock_server(request)