-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: basic websocket support #65
base: master
Are you sure you want to change the base?
Conversation
@h2non the PR is missing a lot of tests, documentation and a bit of a polish, but let me know what you think so far. |
f8984a8
to
7d84960
Compare
7d84960
to
b66e1b6
Compare
req.url = url | ||
|
||
# TODO does this work multithreaded?!? | ||
self._mock = self.engine.match(req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not work. Mutex synchronization is required to make it safe. However, I feel that's another feature that has to be implemented in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! This looks promising and ambitious!
Adding some extra tests would be great to cover more complex scenarios.
It would be great it can support as well this client, which works on top of asyncio
:
https://github.com/aaugustin/websockets
At user API design level, I wonder about how the mock DSL can be improved to mock up exchanged frames with arbitrary responses provided by a routine.
I guess one obvious solution would be allowing the user to pass a function with a signature like:
def framer(frame, request) -> MockFrame:
// Do magic things
return mock
At a user definition API level, I'm inclined to overload the body()
method to support this case:
def frame_mock(frame, request) -> MockFrame:
// Do magic things
return mock
(pook.get('ws://some-non-existing.org')
.reply(204)
.body(frame_mock)
Alternatively, implement a custom method for frames specific case:
(pook.get('ws://some-non-existing.org')
.reply(204)
.frames(frames_mock)
Opinions?
This PR adds a very very basic (and highly likely buggy) support for mocking websockets.