-
-
Notifications
You must be signed in to change notification settings - Fork 895
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
Test Client does not support binary data #601
Comments
I'll look into it, seems like it was an oversight on my part. |
Did you find out where the root cause of this issue is? I've tried to fix it on myself but I don’t have enough knowledge about this library, so I failed :( Let me know if I could help somehow as this is blocking tests on my project. |
@jpowie01 Can I ask you to retest your application with the master branch in this repo? I think binary packets should work now. |
Thank you very much for such quick help :) It works properly! But I've got another concern. I've used Test Client like above: web_socket_client = web_socket.test_client(app)
...
image = open('example_file.dcm', 'rb')
binary_data = image.read()
web_socket_client.emit('my_event', {'ref_id': 123, 'image': binary_data}, namespace='/my_namespace')
assert web_socket_client.get_received(namespace='/my_namespace') ... and it failed. I've checked the queue inside of the Test Client and it was empty: >>> print(web_socket_client.queue)
{'a40cc08de24348c9a0acc957cf9a7da4': []} But the logs show me that some message has been sent:
Code used for handling such event looks like this: class MyEventNamespace(Namespace):
def on_my_event(self, request: Dict) -> None:
...
emit('my_response', {'data': some_data})
web_socket.on_namespace(MyEventNamespace('/my_namespace')) My solution to this problem was to change the client to work on a specific namespace like this: web_socket_client = web_socket.test_client(app, namespace='/my_namespace') ...and it works! I've received this message and I could find it on the queue. Do I have to create Test Client for each of my namespaces? Or is it another bug? Maybe is it a proper behaviour? Could you expain what happened here? |
Yes, you have to think of the test client in the same way you use a real client. When you create the test client, it "connects" to the server, using the namespace provided. In the most common case the arguments that you pass to the As a side note, you can call |
Cool! Thanks for help :) |
Hello,
I've found an issue with emitting binary data using Test Client. Is there a way that I can use it in tests? As far as I looked into the code I found that this class always set
binary
argument toFalse
. Why? Was it done on purpose?Example use:
Example error:
FYI: I can properly send binary data from the JS level but I cannot manage Flask-SocketIO itself to be used during testing.
Does anybody managed to workaround this issue somehow or tried to resolve this bug? Maybe am I using it wrong?
The text was updated successfully, but these errors were encountered: