Skip to content

Commit 9de4e5f

Browse files
Change request_cls to prevent unintended bytes -> str conversion (#176)
1 parent 28a9b18 commit 9de4e5f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mocket/mocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def data(self):
561561
return self
562562

563563
response_index = 0
564-
request_cls = str
564+
request_cls = bytes
565565
response_cls = Response
566566
responses = None
567567
_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)