Skip to main content

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

Project description

mbtest

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

Includes pytest fixture and PyHamcrest matchers.

Build Status

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.14.1 --production

Basic example

import pytest
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

@pytest.mark.usefixtures("mock_server")
def test_request_to_mock_server(mock_server):
    # Set up mock server with required behavior
    imposter = Imposter(Stub(Predicate(path="/test"), 
                             Response(body="sausages")), 
                        record_requests=True)

    with mock_server(imposter) as server:
        # Make request to mock server
        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 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:

git commit -am"Release n.n.n" && git push # If not already all pushed, which it should be.
hub release create n.n.n -m"Release n.n.n"
python setup.py sdist
twine upload dist/`ls -t dist/ | head -n1`

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-1.0.1.tar.gz (7.5 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: mbtest-1.0.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.15rc1

File hashes

Hashes for mbtest-1.0.1.tar.gz
Algorithm Hash digest
SHA256 04a5b204f316e0db9f5f290618f9b910e34b5db97d5377396e609acc521b053b
MD5 2d8ad6e7f78649f4f6a07caeab4d5219
BLAKE2b-256 d67a509dadf6076b7032eed975da02ff9d4c3bded76a121b5e4df42c5f544397

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