Skip to main content

A simple Python client for Mountebank

Project description

codecov Language grade: Python

mounty

A wrapper for Mountebank REST API, can be used for existing instances or for testing in CI/CD ephemeral Mountebank instances.

Who/what is Mountebank? Mountebank is an amazing open-source stub/service virtualisation tool, see more here. It can be used as a stub service for any external dependency, it can run as proxy (recording and replaying requests), it can be used for load testing services in isolation (stub external requests, so no more latency added)

Installation

$ pip install mounty

Usage examples:

import requests
from mounty import Mountebank
from mounty.models import Imposter, Stub

SIMPLE_IMPOSTER = {
 "port": 4555,
 "protocol": "https",
 "stubs": [{"responses": [{"is": {"statusCode": 201}}]}],
}

# the url must contain the port on which Mountebank is listening
mountebank = Mountebank(url="http://mountebank.foo:2525")
# or, if MOUNTEBANK_URL variable is defined:
mountebank_from_env = Mountebank.from_env()

imposter = mountebank.add_imposter(imposter=SIMPLE_IMPOSTER)

other_imposter = mountebank.add_imposter(
 imposter=Imposter(
  port=4556,
  protocol="http",
  stubs=[Stub(responses=[{"is": {"statusCode": 201}}])],
 )
)

# peform 2 requests
requests.post(url="http://mountebank.foo:4545")
requests.post(url="http://mountebank.foo:4545")
# wait for maximum 2 seconds for the imposter to contain 2 recorded requests
reqs = mountebank.wait_for_requests(port=4555, count=2, timeout=2)

Local development

You will first need to clone the repository using git and place yourself in its directory:

$ poetry install -vv
$ poetry run pytest tests/

To make sure that you don't accidentally commit code that does not follow the coding style:

$ poetry run pre-commit autoupdate
$ poetry run pre-commit install
$ poetry run pre-commit run --all-files

TODOs

  • Add integration tests which will create scenarios in several versions of Mountebank running as docker containers
  • MORE examples

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

mounty-1.0.0.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

mounty-1.0.0-py3-none-any.whl (7.8 kB view hashes)

Uploaded Python 3

Supported by

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