Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/pook/matchers/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from .base import BaseMatcher, ExistsMatcher


def _to_query_value(value):
# Query string values are always strings; coerce numeric expectations
if isinstance(value, (int, float)) and not isinstance(value, bool):
return str(value)
return value


class QueryMatcher(BaseMatcher):
"""
QueryMatcher implements an URL query params matcher.
Expand All @@ -17,8 +24,11 @@ def test(key, param):
# Normalize param value
param = [param] if not isinstance(param, list) else param

# Compare query params
[[self.compare(value, expect) for expect in match] for value in param]
# Compare query params, coercing numeric expectations to str
[
[self.compare(_to_query_value(value), expect) for expect in match]
for value in param
]

return True

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/matchers/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ def test_param_exists_empty_allowed(url_404):

res = urlopen(f"{url_404}?x")
assert res.status == 200


@pytest.mark.pook
def test_params_numeric_value(url_404):
pook.get(url_404).params({"x": 1}).reply(200)

res = urlopen(f"{url_404}?x=1")
assert res.status == 200