Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Unreleased
as bytes or a binary file-like object.
* Added ``responses.CallbackRequest`` so callback and matcher annotations can
include the ``params`` and ``req_kwargs`` attributes added by ``responses``.
* Fixed ``query_param_matcher`` failing to match when a list value contains
numbers, e.g. ``{"ids": [1, 2]}``.

0.26.3
------
Expand Down
2 changes: 2 additions & 0 deletions responses/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def query_param_matcher(
for k, v in params_dict.items():
if isinstance(v, (int, float)):
params_dict[k] = str(v)
elif isinstance(v, list):
params_dict[k] = [str(i) if isinstance(i, (int, float)) else i for i in v]

def match(request: PreparedRequest) -> Tuple[bool, str]:
reason = ""
Expand Down
17 changes: 17 additions & 0 deletions responses/tests/test_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,23 @@ def run():
assert_reset()


def test_query_params_numbers_in_list():
@responses.activate
def run():
expected_query_params = {"ids": [1, 2], "ratio": [0.5, "x"]}
responses.add(
responses.GET,
"https://example.com/",
match=[
matchers.query_param_matcher(expected_query_params),
],
)
requests.get("https://example.com", params=expected_query_params)

run()
assert_reset()


def test_query_param_matcher_does_not_mutate_input():
"""query_param_matcher must not modify the caller's params dict.

Expand Down
Loading