Skip to content

Commit 1061720

Browse files
authored
Merge pull request #82 from kwist-sgr/master
Add `form` to Predicate
2 parents e860499 + 5ac370a commit 1061720

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 2.13.2
4+
5+
* Enhancement - add form to Predicate.
6+
* Fix - added the `imurl` package to dependencies
7+
38
## 2.13.1
49

510
* Re-release
@@ -58,7 +63,7 @@
5863
* Add [dynamic predicates and responses](http://www.mbtest.org/docs/api/injection). This feature requires Mountebank 2.0 or later, but all other features should continue to work with older version.
5964
* Add MountebankServer.query_all_imposters() method to retrieve all imposters from a running MB server, including those not created locally.
6065

61-
## 2.4
66+
## 2.4
6267

6368
* Allow MountebankServer to attach to an already running MB instance on another host.
6469
* Make has_request() a builder style matcher, and use builder matcher construction wherever possible.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
setup(
5454
name="mbtest",
5555
zip_safe=False,
56-
version="2.13.1",
56+
version="2.13.2",
5757
description="Python wrapper & utils for the Mountebank over the wire test double tool.",
5858
long_description=long_description,
5959
long_description_content_type="text/markdown",

src/mbtest/imposters/predicates.py

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Predicate(LogicallyCombinablePredicate):
4444
:param query: Query arguments, keys and values.
4545
:param body: Body text. Can be a string, or a JSON serialisable data structure.
4646
:param headers: Headers, keys and values.
47+
:param form: Form-encoded key-value pairs in the body.
4748
:param xpath: xpath query
4849
:param jsonpath: jsonpath query
4950
:param operator:
@@ -88,6 +89,7 @@ def __init__(
8889
headers: Optional[Mapping[str, str]] = None,
8990
xpath: Optional[str] = None,
9091
jsonpath: Optional[str] = None,
92+
form: Optional[Mapping[str, str]] = None,
9193
operator: Union[Operator, str] = Operator.EQUALS,
9294
case_sensitive: bool = True, # noqa: FBT001,FBT002
9395
) -> None:
@@ -98,6 +100,7 @@ def __init__(
98100
self.headers = headers
99101
self.xpath = xpath
100102
self.jsonpath = jsonpath
103+
self.form = form
101104
self.operator = operator if isinstance(operator, Predicate.Operator) else Predicate.Operator(operator)
102105
self.case_sensitive = case_sensitive
103106

@@ -132,6 +135,7 @@ def fields_from_structure(self, inner):
132135
self.set_if_in_dict(inner, "query", "query")
133136
self.set_if_in_dict(inner, "body", "body")
134137
self.set_if_in_dict(inner, "headers", "headers")
138+
self.set_if_in_dict(inner, "form", "form")
135139
if "method" in inner:
136140
self.method = Predicate.Method(inner["method"])
137141

@@ -141,6 +145,7 @@ def fields_as_structure(self):
141145
self.add_if_true(fields, "query", self.query)
142146
self.add_if_true(fields, "body", self.body)
143147
self.add_if_true(fields, "headers", self.headers)
148+
self.add_if_true(fields, "form", self.form)
144149
if self.method:
145150
fields["method"] = self.method.value
146151
return fields

tests/unit/mbtest/test_predicate.py

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ def test_structure_headers():
7171
assert predicate.headers == expected_predicate.headers
7272

7373

74+
def test_structure_form():
75+
expected_predicate = Predicate(form={"key": "value"})
76+
predicate_structure = expected_predicate.as_structure()
77+
predicate = BasePredicate.from_structure(predicate_structure)
78+
assert predicate.headers == expected_predicate.headers
79+
80+
7481
def test_structure_operator():
7582
expected_predicate = Predicate(operator="deepEquals")
7683
predicate_structure = expected_predicate.as_structure()

0 commit comments

Comments
 (0)