Skip to content

Commit f03ca83

Browse files
MocketEntry.request_class str vs bytes (#177)
* Change request_cls to prevent unintended bytes -> str conversion (#176) * Use type from `.compat`. Co-authored-by: Michael Lazar <[email protected]>
1 parent 28a9b18 commit f03ca83

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

mocket/mocket.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,7 @@ def get_truesocket_recording_dir(cls):
548548
@classmethod
549549
def assert_fail_if_entries_not_served(cls):
550550
"""Mocket checks that all entries have been served at least once."""
551-
if not all(
552-
entry._served for entry in itertools.chain(*cls._entries.values())
553-
):
551+
if not all(entry._served for entry in itertools.chain(*cls._entries.values())):
554552
raise AssertionError("Some Mocket entries have not been served")
555553

556554

@@ -561,7 +559,7 @@ def data(self):
561559
return self
562560

563561
response_index = 0
564-
request_cls = str
562+
request_cls = byte_type
565563
response_cls = Response
566564
responses = None
567565
_served = None

tests/main/test_mocket.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ def test_raise_exception(self):
9494
with self.assertRaises(IOError):
9595
entry.get_response()
9696

97+
def test_collect_last_request(self):
98+
addr = ("localhost", 80)
99+
100+
entry = MocketEntry(addr, True)
101+
Mocket.register(entry)
102+
with Mocketizer():
103+
_so = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
104+
_so.connect(addr)
105+
_so.sendall(b"data\r\n")
106+
_so.close()
107+
self.assertEqual(Mocket.last_request(), b"data\r\n")
108+
97109
def test_subsequent_recv_requests_have_correct_length(self):
98110
addr = ("localhost", 80)
99111
Mocket.register(MocketEntry(addr, [b"Long payload", b"Short"]))

0 commit comments

Comments
 (0)