Optionally match empty values in query parameter presence matcher #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #110.
This PR simplifies the header and query param existence matches by introducing a new base matcher class,
ExistsMatcher
. Two new matcher classes,HeaderExistsMatcher
andQueryParameterExistsMatcher
are also introduced and the existingheader(s)_present
andparam_exists
methods are updated to use these matchers.This removes the need to use the catch-all regexes for the value-check of the existence matchers. The new query-parameter existence matcher can be configured to allow empty values, which fixes #110 while preserving the existing behaviour of requiring some value for the matcher's default behaviour. This prevents breaking backwards compatibility in the default behaviour. Setting
allow_empty=True
makes it possible to successfully match requests likehttps://example.com/?refresh
whererefresh
is interpreted as true by the requested API if it is present and false if it is missing or if it is explicitly set to false (refresh=false
). Here is a real-world example of such a parameter in a widely used API: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#docs-reindex-api-query-params.This backwards compatibility consideration does not effect headers, for whose existence matcher already allowed empty values in all cases because headers were never ignored due to their empty value.