Repository navigation
Match parsed form fields in request expectations - #520
sricharanreddycheruku wants to merge 3 commits into
Conversation
| Use ``data_form`` to match parsed form fields without depending on their encoded | ||
| order or spelling: | ||
|
|
||
| .. code-block:: python |
There was a problem hiding this comment.
Could you move this python code example to the tests/examples folder and reference it from the docs? This is how I set up that we test the examples as well.
You can find example like this:
.. literalinclude :: ../tests/examples/test_example_query_params1.py
:language: python
You can also build documentation locally with "make doc" and run "make doc-preview" to show the index.html in your default browser.
| query_string: QueryMatcher | str | bytes | Mapping[str, str] | None = None, | ||
| header_value_matcher: HVMATCHER_T | None = None, | ||
| json: Any = UNDEFINED, | ||
| *, |
There was a problem hiding this comment.
why is it a kwarg-only?
Personally I think all option should be kwarg only, but I don't want to introduce API breaking. But adding this here just results a half-fixed thing.
Could you remove this if you are ok with it? I mean the *, only.
And in the other places as well.
|
Thanks for your PR, I have a few comments only, otherwise looks good to me. |
| ``werkzeug.datastructures.MultiDict`` to match all values of repeated fields. | ||
| Extra fields do not match, and an empty value is distinct from a missing field. | ||
|
|
||
| Werkzeug parses form fields using the request's ``Content-Type`` header. |
There was a problem hiding this comment.
I think this could be reworded. I think you wanted to write that werkzeug parses form fields if the content-type header is X. I think we should also include the value of the content-type header here.
Matching form-encoded request bodies currently requires a custom handler. This adds the
data_formargument proposed in #369 to compare Werkzeug's parsed form fields.A mapping compares the first value for each field, while a
MultiDictcompares all repeated values, consistently with query-string matching. Extra fields and missing empty-valued fields do not match. The raw body remains available to response handlers, and form expectations are mutually exclusive withdataandjson.The argument is available on normal, oneshot, ordered, baked and blocking expectations. Existing positional arguments and representations remain unchanged. When the new argument is unused, it is not forwarded to custom matcher factories or expectation overrides. Includes a how-to example, API docstrings, a release note and the updated source-package test inventory.
Original submission validation on Linux / Python 3.12.14 using locked development dependencies with Poetry 2.1.1:
data_formis absent.pytest -q tests --release): 171 passed, 3 skipped, 2 xfailed; one existing tar-extraction warning.pytest -q tests --ssl): 1 passed, 175 skips from SSL selection.make precommitandgit diff --check: passed.make doc: passed; the same 59 warnings occur on unchanged source, with no new warnings.Fixes #369
Revision after maintainer review:
data_form.tests/examples/test_howto_form_data.pyand included that tested file in the how-to documentation.application/x-www-form-urlencodedandmultipart/form-dataas the Content-Type values Werkzeug uses to parse form fields.Revision validation on Linux / Python 3.12.3 with pip-installed development dependencies and Poetry 2.1.1, rather than a lockfile installation:
git diff --checkpassed.