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
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Fixed `fragment_identifier_matcher` treating opaque fragments (those without
``=``, e.g. ``/users/5``) as always equal, so a required fragment matched a
different one or none at all. See #806
* Fixed non-strict `json_params_matcher` raising `TypeError` when an actual
nested object is compared with an expected scalar value.

0.26.2
------
Expand Down
2 changes: 1 addition & 1 deletion responses/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _filter_dict_recursively(
filtered_dict = {}
for k, val in dict1.items():
if k in dict2:
if isinstance(val, dict):
if isinstance(val, dict) and isinstance(dict2[k], dict):
val = _filter_dict_recursively(val, dict2[k])
filtered_dict[k] = val

Expand Down
19 changes: 19 additions & 0 deletions responses/tests/test_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ def run():
assert_reset()


def test_json_params_matcher_not_strict_nested_type_mismatch():
mock_request = Mock(body='{"page": {"type": "json"}}')

result = matchers.json_params_matcher(
{"page": 1},
strict_match=False,
)(mock_request)

assert result == (
False,
(
"request.body doesn't match: {'page': {'type': 'json'}} "
"doesn't match {'page': 1}\n"
"Note: You use non-strict parameters check, "
"to change it use `strict_match=True`."
),
)


def test_failed_matchers_dont_modify_inputs_order_in_error_message():
json_a = {"array": ["C", "B", "A"]}
json_b = '{"array" : ["B", "A", "C"]}'
Expand Down