Skip to content

Commit

Permalink
Add Call.has_response helper
Browse files Browse the repository at this point in the history
  • Loading branch information
lundberg committed Sep 16, 2022
1 parent a2f0e48 commit 06ff405
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions respx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def response(self) -> httpx.Response:
raise ValueError(f"{self!r} has no response")
return self.optional_response

@property
def has_response(self) -> bool:
return self.optional_response is not None


class CallList(list, mock.NonCallableMock):
def __init__(self, *args: Sequence[Call], name: Any = "respx") -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ async def test_raising_content(client):

assert route.call_count == 2
assert route.calls.last.request is not None
assert route.calls.last.has_response is False
with pytest.raises(ValueError, match="has no response"):
assert route.calls.last.response

Expand Down
2 changes: 1 addition & 1 deletion tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_remote_pass_through(using, client_lib, call_count): # pragma: nocover
assert response.json()["json"] == {"foo": "bar"}

assert respx_mock.calls.last.request.url == url
assert respx_mock.calls.last.response == None # noqa: E711
assert respx_mock.calls.last.has_response is False

assert route.call_count == call_count
assert respx_mock.calls.call_count == call_count

0 comments on commit 06ff405

Please sign in to comment.