From 48d0d6238561754d6e73d57fe78bd29f8711fc0d Mon Sep 17 00:00:00 2001 From: "Ivan A. Melnikov" Date: Thu, 17 Aug 2023 10:08:37 +0400 Subject: [PATCH 1/2] Implement MockHTTPResponse.close https://github.com/betamaxpy/betamax/issues/200 --- src/betamax/mock_response.py | 7 ++++++- tests/unit/test_cassette.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/betamax/mock_response.py b/src/betamax/mock_response.py index ffcc1b6..6de6b15 100644 --- a/src/betamax/mock_response.py +++ b/src/betamax/mock_response.py @@ -18,8 +18,13 @@ def __init__(self, headers): self.msg = p.parsestr(h) self.msg.set_payload(h) + self.__closed = False + def isclosed(self): - return False + return self.__closed + + def close(self): + self.__closed = True class EmailMessage(message.Message): diff --git a/tests/unit/test_cassette.py b/tests/unit/test_cassette.py index 01ae406..bad6205 100644 --- a/tests/unit/test_cassette.py +++ b/tests/unit/test_cassette.py @@ -496,3 +496,7 @@ def test_isclosed(self): def test_is_Message(self): assert isinstance(self.resp.msg, email.message.Message) + + def test_close(self): + self.resp.close() + assert self.resp.isclosed() is True From 983a6d27fdc1c5de1a3038f9adc876baa721639d Mon Sep 17 00:00:00 2001 From: Ian Stapleton Cordasco Date: Tue, 6 Feb 2024 06:42:05 -0600 Subject: [PATCH 2/2] Rename attribute for isclosed There's no need for `self.__closed` as we don't need something so hidden or mangled for this purpose, plus it doesn't really hide anything at all. --- src/betamax/mock_response.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/betamax/mock_response.py b/src/betamax/mock_response.py index 6de6b15..f423108 100644 --- a/src/betamax/mock_response.py +++ b/src/betamax/mock_response.py @@ -18,13 +18,13 @@ def __init__(self, headers): self.msg = p.parsestr(h) self.msg.set_payload(h) - self.__closed = False + self._closed = False def isclosed(self): - return self.__closed + return self._closed def close(self): - self.__closed = True + self._closed = True class EmailMessage(message.Message):