Skip to main content

Python wrapper & utils for the Mountebank over the wire test double tool.

Project description

mbtest

Opinionated Python wrapper & utils for the Mountebank over the wire test double tool.

Includes pytest fixture and PyHamcrest matchers.

made-with-python Build Status PyPi Version Python Versions Licence GitHub all releases GitHub forks GitHub stars GitHub watchers GitHub contributors GitHub issues GitHub issues-closed GitHub pull-requests GitHub pull-requests closed

Setup

Install with pip:

pip install mbtest

(As usual, use of a venv or virtualenv is recommended.) Also requires Mountebank to have been installed:

npm install mountebank@1.16 --production

Basic example

import requests
from hamcrest import assert_that, is_
from brunns.matchers.response import response_with
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) as server:
        # Make request to mock server - exercise code under test here
        response = requests.get("{}/test".format(imposter.url))

        assert_that("We got the expected response", 
                    response, is_(response_with(status_code=200, body="sausages")))
        assert_that("The mock server recorded the request", 
                    server, had_request(path="/test", 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)

Examples of more complex predicates can be found in the integration tests.

Developing

Requires make and tox. Run make precommit tells you if you're OK to commit. For more options, run:

make help

Releasing

Requires hub, setuptools and twine. To release n.n.n:

version="n.n.n" # Needs to match new version number in setup.py.
make precommit && git commit -am"Release $version" && git push # If not already all pushed, which it should be.
hub release create $version -m"Release $version"
python setup.py sdist bdist_wheel
twine upload dist/*$version*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mbtest-2.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mbtest-2.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file mbtest-2.1.0.tar.gz.

File metadata

  • Download URL: mbtest-2.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for mbtest-2.1.0.tar.gz
Algorithm Hash digest
SHA256 d893f7280016f0d05c4b8f6567f29d1bd3fb7b6ab800b481bd579957eeadc97d
MD5 ad33d18a07ed910436c9abcaf4492ee3
BLAKE2b-256 4fc657e8444d7b9487cf28e06f664f7737ec9c95feccba14fd2f8ea07498e45d

See more details on using hashes here.

File details

Details for the file mbtest-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: mbtest-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for mbtest-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23161b6f09e4507bd8d2a0f8cbfface873be3c96f2a0bfbcbf59839279d15c9a
MD5 3c820ab81597f8693c6eaa28a9d7eff6
BLAKE2b-256 7aa732a960ef4342f56d1cfa22205947bf8414d4302b70a0eddf2697bda8fbd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page