wiremock / python-wiremock

A Python library for API mocking and testing with Testcontainers module and WireMock

Home Page:https://wiremock.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request Matching: bodyPatterns is a list not a dict

i-fimafeng opened this issue · comments

Issue:

the API to match request with bodyPatterns is expecting a array of dict not directly a dict.

bodyPatterns Array of object Request body patterns to match against in the : { "": "" } form

from http://wiremock.org/docs/api/#tag/Stub-Mappings/paths/~1__admin~1mappings/post

Whereas class MappingRequest(BaseAbstractEntity) in models.py define it as a dict
body_patterns = JsonProperty('bodyPatterns', klass=dict)`

Step to reproduce

Try matching request body

mapping = Mapping(
    priority=100,
    request=MappingRequest(
        method=HttpMethods.GET,
        url='/hello',
        bodyPatterns={"matchesXPath": "//world"}
    ),
    response=MappingResponse(
        status=200,
        body='hi'
    ),
    persistent=False,
)

create an error 500 in wiremock when trying to match.

Solution

Adding a list around dictionary works fine.

mapping = Mapping(
    priority=100,
    request=MappingRequest(
        method=HttpMethods.GET,
        url='/hello',
        bodyPatterns=[{"matchesXPath": "//world"}]
    ),
    response=MappingResponse(
        status=200,
        body='hi'
    ),
    persistent=False,
)

but defining bodyPatterns as JsonProperty of klass dict is misleading.

fixed and released in 2.0.0