miguelgrinberg/Flask-SocketIO-Chat

How best to test WS events?

wcpines opened this issue · 3 comments

Hey Miguel,

I'm playing around with building a chat app API/backend using Flask-SocketIO. However, I'm currently stuck trying to test socketio events. With standard RESTful endpoints, I can easily use curl or HTTPie. But what about testing something like joining a room? E.g.

@socketio.on('join')
def on_join(data):
    username = data['username']
    room = data['room']
    join_room(room)
    send(username + ' has entered the room.', room=room)

Am I missing something?

Thanks!

@wcpines you have basically two options.

If you want to go the mock route, you can use the test client that comes with Flask-SocketIO. Take a look at the unit tests in that package to see how that works, but it is similar in concept to the Flask test client for HTTP routes. This option does not use a real server, so it is ideal for unit tests.

If you want to test things on a running server, then you need to use a Socket.IO client to connect to the server and send events. There is one for Python that I heard from users works well with this server: https://pypi.python.org/pypi/socketIO-client.

OK great, thank you!

This issue will be automatically closed due to being inactive for more than six months. Seeing that I haven't responded to your last comment, it is quite possible that I have dropped the ball on this issue and I apologize about that. If that is the case, do not take the closing of the issue personally as it is an automated process doing it, just reopen it and I'll get back to you.