Skip to content

Commit f940dc7

Browse files
kleptogMartijn van Oosterhoutmarkstory
authored
Allow asserts on add_callback() matches (#774)
Allow asserts on add_callback() matches Fixes #727 Co-authored-by: Martijn van Oosterhout <[email protected]> Co-authored-by: Mark Story <[email protected]>
1 parent 9485a01 commit f940dc7

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
------
33

44
* Fix bug where the content type is always recorded as either text/plain or application/json. See #770
5+
* Allow asserts on add_callback() matches. See #727
56

67
0.25.7
78
------

responses/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,8 @@ def add_callback(
967967
match_querystring: Union[bool, FalseBool] = FalseBool(),
968968
content_type: Optional[str] = "text/plain",
969969
match: "_MatcherIterable" = (),
970-
) -> None:
971-
self._registry.add(
970+
) -> BaseResponse:
971+
return self._registry.add(
972972
CallbackResponse(
973973
url=url,
974974
method=method,

responses/tests/test_responses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,15 @@ def request_callback(_request):
574574

575575
@responses.activate
576576
def run():
577-
responses.add_callback(responses.GET, url, request_callback)
577+
rsp = responses.add_callback(responses.GET, url, request_callback)
578578
resp = requests.get(url)
579579
assert resp.text == "test callback"
580580
assert resp.status_code == status
581581
assert resp.reason == reason
582582
assert "bar" == resp.headers.get("foo")
583583
assert "application/json" == resp.headers.get("Content-Type")
584584
assert "13" == resp.headers.get("Content-Length")
585+
assert len(rsp.calls) == 1
585586

586587
run()
587588
assert_reset()

0 commit comments

Comments
 (0)