-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
Description
Hi, thanks for creating this awesome library!
I've just started using mocket to test raw socket connections and uncovered some weirdness with MocketEntry.request_cls. The default behavior is to cast the request data as a str, but this doesn't really make sense for python 3 because sockets use bytes. This results in the request data being mangled as a string. Here's an example
import socket
from mocket import Mocket, MocketEntry, Mocketizer
entry = MocketEntry(("example.com", 1965), "")
Mocket.register(entry)
with Mocketizer():
with socket.create_connection(("example.com", 1965)) as sock:
sock.sendall(b"example request data")
request = Mocket.last_request()
# I expect the request to contain the bytes that I sent, but it's actually a string object
print(type(request), repr(request))
# <class 'str'> "b'example request data'"I suspect this is a holdout bug from the python 2 -> 3 conversion, and not the intended behavior. For now I've fixed it for myself by subclassing the mocket entry.
class RawMocketEntry(MocketEntry):
request_cls = bytesMetadata
Metadata
Assignees
Labels
No labels