diff --git a/CHANGES b/CHANGES index c259139c..6f473e74 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ------ diff --git a/responses/matchers.py b/responses/matchers.py index 32d068a4..a2bf6f79 100644 --- a/responses/matchers.py +++ b/responses/matchers.py @@ -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 = "" diff --git a/responses/tests/test_matchers.py b/responses/tests/test_matchers.py index 29c60475..1ae60f25 100644 --- a/responses/tests/test_matchers.py +++ b/responses/tests/test_matchers.py @@ -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.