From 6c9e93748a40fb69b4d0af82032f25289f735b49 Mon Sep 17 00:00:00 2001 From: mayureshsonawane17 Date: Mon, 5 Oct 2026 15:27:12 +0530 Subject: [PATCH] test: add test coverage for body_matcher bytes and mismatch cases --- responses/tests/test_matchers.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/responses/tests/test_matchers.py b/responses/tests/test_matchers.py index 4f67810c..3a2ec11e 100644 --- a/responses/tests/test_matchers.py +++ b/responses/tests/test_matchers.py @@ -50,6 +50,41 @@ def run(): assert_reset() +def test_body_matcher_bytes(): + @responses.activate + def run(): + url = "http://example.com" + responses.add( + responses.POST, + url, + body=b"test", + match=[matchers.body_matcher("123456")], + ) + resp = requests.post("http://example.com", data=b"123456") + assert_response(resp, "test") + + run() + assert_reset() + + +def test_body_matcher_mismatch(): + mock_request = Mock(body="mismatch_data") + result = matchers.body_matcher("expected_data")(mock_request) + assert result == ( + False, + "request.body doesn't match expected_data doesn't match mismatch_data", + ) + + +def test_body_matcher_bytes_mismatch(): + mock_request = Mock(body=b"mismatch_bytes") + result = matchers.body_matcher("expected_bytes")(mock_request) + assert result == ( + False, + "request.body doesn't match expected_bytes doesn't match mismatch_bytes", + ) + + def test_query_string_matcher(): @responses.activate def run():