Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally match empty values in query parameter presence matcher #113

Merged
merged 2 commits into from
Jan 1, 2024

Conversation

sarayourfriend
Copy link
Collaborator

@sarayourfriend sarayourfriend commented Jan 1, 2024

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 and QueryParameterExistsMatcher are also introduced and the existing header(s)_present and param_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 like https://example.com/?refresh where refresh 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.

@sarayourfriend sarayourfriend marked this pull request as draft January 1, 2024 04:40
@sarayourfriend sarayourfriend marked this pull request as ready for review January 1, 2024 04:55
@sarayourfriend sarayourfriend changed the title Allow None values for header and query param existence matchers Optionally match empty values in query parameter presence matcher Jan 1, 2024
@sarayourfriend sarayourfriend merged commit 8e1fb41 into master Jan 1, 2024
8 checks passed
@sarayourfriend sarayourfriend deleted the fix/param_exists-matcher branch January 1, 2024 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

param_exists fails when requested query param has no value
1 participant