Closed j3pic closed 10 months ago
Hi @j3pic, the only meaningful examples, like you said, are showing how to mock HTTP[S]. Many users ended up using Mocket for replacing HTTPretty, which is only capable of mocking web clients.
This said, Mocket also implements a stub for mocking Redis, which does not use HTTP as communication protocol. That's for sure the biggest example of a non-web mock. See: https://github.com/mindflayer/python-mocket/blob/main/mocket/mockredis.py
You'll probably realise you need three main components:
You can close the loop having a look at the tests for the above mock: https://github.com/mindflayer/python-mocket/blob/main/tests/main/test_redis.py
Answering your first question, create_connection
and connect
are already mocked. It's all done in https://github.com/mindflayer/python-mocket/blob/main/mocket/mocket.py
MocketSocket
is pretty advance, supporting even non-blocking sockets.
Hi @j3pic, did you manage to get started with low-level mocking of the socket
module?
Feel free to open a new issue with a more specific question. Thanks!
I have a project that directly uses sockets, without HTTP. But all the documentation is geared towards HTTP. What can Mocket do when it comes to opening and closing connections (both via
connect
orcreate_connection
, and vialisten
andaccept
), sending and receiving data, and usingselect.epoll
?Also, are UDP sockets supported in any way? What about UNIX domain sockets, which can transfer not only bytes but also file descriptors?