diff --git a/CHANGES b/CHANGES index 9732e665..c1c617d7 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,7 @@ ------ * Fix bug where the content type is always recorded as either text/plain or application/json. See #770 +* Allow asserts on add_callback() matches. See #727 0.25.7 ------ diff --git a/responses/__init__.py b/responses/__init__.py index a00c08d3..89cc9a5c 100644 --- a/responses/__init__.py +++ b/responses/__init__.py @@ -967,8 +967,8 @@ def add_callback( match_querystring: Union[bool, FalseBool] = FalseBool(), content_type: Optional[str] = "text/plain", match: "_MatcherIterable" = (), - ) -> None: - self._registry.add( + ) -> BaseResponse: + return self._registry.add( CallbackResponse( url=url, method=method, diff --git a/responses/tests/test_responses.py b/responses/tests/test_responses.py index 21ee8492..66711a51 100644 --- a/responses/tests/test_responses.py +++ b/responses/tests/test_responses.py @@ -574,7 +574,7 @@ def request_callback(_request): @responses.activate def run(): - responses.add_callback(responses.GET, url, request_callback) + rsp = responses.add_callback(responses.GET, url, request_callback) resp = requests.get(url) assert resp.text == "test callback" assert resp.status_code == status @@ -582,6 +582,7 @@ def run(): assert "bar" == resp.headers.get("foo") assert "application/json" == resp.headers.get("Content-Type") assert "13" == resp.headers.get("Content-Length") + assert len(rsp.calls) == 1 run() assert_reset()