From 9aa3f766c5ab0fa2e47cc615eb515619e9bfe6cd Mon Sep 17 00:00:00 2001 From: Jonas Lundberg Date: Fri, 16 Sep 2022 10:49:07 +0200 Subject: [PATCH] Add Call.has_response() helper --- respx/models.py | 3 +++ tests/test_remote.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/respx/models.py b/respx/models.py index 39b680b..bda3ded 100644 --- a/respx/models.py +++ b/respx/models.py @@ -52,6 +52,9 @@ def response(self) -> httpx.Response: raise ValueError(f"{self!r} has no response") return self.optional_response + 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: diff --git a/tests/test_remote.py b/tests/test_remote.py index f33af82..a18768e 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -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