1- # Python WireMock
1+ # Python WireMock Admin API Client
22
33<p align =" center " >
44 <a href="https://wiremock.org/docs/solutions/python/" target="_blank">
55 <img width="512px" src="docs/images/python-wiremock-horizontal.png" alt="WireMock Logo"/>
66 </a>
77</p >
88
9- Python WireMock is a library that allows users to interact with a WireMock instance from within a Python project.
10- Full documentation can be found at [ wiremock.readthedocs.org] ( http://wiremock.readthedocs.org/ ) .
9+ Python Wiremock is an HTTP client that allows users to interact with a Wiremock instance from within a Python project.
1110
1211[ ![ a] ( https://img.shields.io/badge/slack-%23wiremock%2Fpython-brightgreen?style=flat&logo=slack )] ( https://slack.wiremock.org/ )
1312[ ![ Docs] ( https://img.shields.io/badge/docs-latest-brightgreen.svg )] ( http://wiremock.readthedocs.org/ )
@@ -21,22 +20,91 @@ FIXME: Reporting is dead: https://github.com/wiremock/python-wiremock/issues/74
2120
2221WireMock can run in unit tests, as a standalone process or a container. Key features include:
2322
24- - [ Testcontainers Python] ( https://github.com/testcontainers/testcontainers-python ) module to easily start WireMock server for your tests
25- - REST API Client for a standalone WireMock Java server
2623- Supports most of the major [ Wiremock] ( https://wiremock.org/docs ) features (more on their way soon)
24+ - Support for [ testcontainers-python] ( https://github.com/testcontainers/testcontainers-python ) to easily start wiremock server for your tests
25+ - Support for standalone wiremock JAVA sever
2726
28- ## References
27+ ## Install as Dependency
2928
30- - [ Quickstart Guide] ( ./docs/quickstart )
31- - [ Installation] ( ./docs/install )
32- - [ Full documentation] ( http://wiremock.readthedocs.org/ )
29+ To install:
30+
31+ `pip install wiremock`
32+
33+ To install with testing dependencies:
34+
35+ `pip install wiremock[testing]`
36+
37+ To install via Poetry:
38+
39+ `poetry add --extras=testing wiremock`
40+
41+ ## Quick Start
42+
43+ The preferred way of using WireMock to mock your services is by using the provided ` WireMockContainer ` [ testcontainers-python] ( https://github.com/testcontainers/testcontainers-python ) .
44+
45+ ``` python
46+ import pytest
47+
48+ from wiremock.testing.testcontainer import wiremock_container
49+
50+ @pytest.fixture (scope = " session" ) # (1)
51+ def wm_server ():
52+ with wiremock_container(secure = False ) as wm:
53+
54+ Config.base_url = wm.get_url(" __admin" ) # (2)
55+
56+ Mappings.create_mapping(
57+ Mapping(
58+ request = MappingRequest(method = HttpMethods.GET , url = " /hello" ),
59+ response = MappingResponse(status = 200 , body = " hello" ),
60+ persistent = False ,
61+ )
62+ ) # (3)
63+ yield wm
64+
65+
66+ def test_get_hello_world (wm_server ): # (4)
67+
68+ resp1 = requests.get(wm_server.get_url(" /hello" ), verify = False )
69+
70+ assert resp1.status_code == 200
71+ assert resp1.content == b " hello"
72+ ```
73+
74+ 1 . Create a pytest fixture to manage the container life-cycle. use fixture ` scope ` to control how often the container is created
75+
76+ 2 . Set the wiremock sdk config url to the url exposed by the container
77+
78+ 3 . Create response and request mappings using the Admin SDK.
79+
80+ 4 . Use the ` wm_server ` fixture in your tests and make requests against the mock server.
81+
82+ You can read more about Testcontainers support in python-wiremock [ here] ( docs/testcontainers.md ) .
3383
3484## Examples
3585
3686There are several example projects included to demonstrate the different ways that wiremock can be used to mock
3787services in your tests and systems. The example test modules demonstrate different strategies for testing against
3888the same "product service" and act as a good demonstration of real world applications to help you get started.
3989
40- - [ Testcontainers Python] ( example/tests/test_testcontainers.py )
90+ - [ Python Testcontainers ] ( example/tests/test_testcontainers.py )
4191
4292- [ Standalone Java Server Version] ( example/tests/test_java_server.py )
93+
94+ ## Documentation
95+
96+ wiremock documentation can be found at http://wiremock.readthedocs.org/
97+
98+ ## Pull Requests
99+
100+ General Rules:
101+
102+ - All Tests must pass
103+ - Coverage shouldn't decrease
104+ - All Pull Requests should be rebased against master ** before** submitting the PR.
105+
106+ ## Development
107+
108+ Setup the project using poetry.
109+
110+ ` poetry install `
0 commit comments