Wiremock Admin API Client
Project description
Python WireMock Admin API Client
Python Wiremock is an HTTP client that allows users to interact with a Wiremock instance from within a Python project.
Key Features
WireMock can run in unit tests, as a standalone process or a container. Key features include:
- Supports most of the major Wiremock features (more on their way soon)
- Support for testcontainers-python to easily start wiremock server for your tests
- Support for standalone wiremock JAVA sever
Install as Dependency
To install:
`pip install wiremock`
To install with testing dependencies:
`pip install wiremock[testing]`
To install via Poetry:
`poetry add --extras=testing wiremock`
Quick Start
The preferred way of using WireMock to mock your services is by using the provided WireMockContainer
testcontainers-python.
import pytest
from wiremock.testing.testcontainer import wiremock_container
@pytest.fixture(scope="session") # (1)
def wm_server():
with wiremock_container(secure=False) as wm:
Config.base_url = wm.get_url("__admin") # (2)
Mappings.create_mapping(
Mapping(
request=MappingRequest(method=HttpMethods.GET, url="/hello"),
response=MappingResponse(status=200, body="hello"),
persistent=False,
)
) # (3)
yield wm
def test_get_hello_world(wm_server): # (4)
resp1 = requests.get(wm_server.get_url("/hello"), verify=False)
assert resp1.status_code == 200
assert resp1.content == b"hello"
-
Create a pytest fixture to manage the container life-cycle. use fixture
scope
to control how often the container is created -
Set the wiremock sdk config url to the url exposed by the container
-
Create response and request mappings using the Admin SDK.
-
Use the
wm_server
fixture in your tests and make requests against the mock server.
You can read more about Testcontainers support in python-wiremock here.
Examples
There are several example projects included to demonstrate the different ways that wiremock can be used to mock services in your tests and systems. The example test modules demonstrate different strategies for testing against the same "product service" and act as a good demonstration of real world applications to help you get started.
Documentation
wiremock documentation can be found at http://wiremock.readthedocs.org/
Pull Requests
General Rules:
- All Tests must pass
- Coverage shouldn't decrease
- All Pull Requests should be rebased against master before submitting the PR.
Development
Setup the project using poetry.
poetry install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for wiremock-2.6.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d68bb38a37b95f0f0a82023d3712b95cc17fd26b0a3a89bccc46d2cbb080c7ae |
|
MD5 | 27b9b53909ac7b31d27d98e4761b527d |
|
BLAKE2b-256 | bb0709e9ac85da5ad1338d8f1bca731a0b89ebf54943e2693823511dd10f3d72 |