Coder Social home page Coder Social logo

Comments (7)

TronPaul avatar TronPaul commented on May 18, 2024

If I can get something working that looks like my sample code I'll make a pull request. If anyone has any other ideas for how to accomplish this, I'd love to see them.

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on May 18, 2024

I was thinking that for unit tests I was going to start the app for real and use a websocket client to acccess it. There is client that looks decent: https://pypi.python.org/pypi/websocket-client/, but I haven't tried it yet.

from flask-socketio.

TronPaul avatar TronPaul commented on May 18, 2024

I didn't really want to do end to end testing at this stage. And you can set the test_client_class in flask. I think I should be able to extend FlaskClient (flask's test client) to behave as expected for websockets. Would something of that nature be good for a pull request?

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on May 18, 2024

Oh sure, if you manage to get testing going I would take it.

I'm not sure you need a connection to the test client, though, since the socket stuff runs independently. You could have a SocketIOTestClient class for example that can send and receive socket.io messages.

The send() and emit() methods in this client would just invoke recv_message(), recv_json() or process_event() in the SocketIO object.

Receiving events from the server is going to be a little bit more tricky, you will need to get the GenericNamespace objects to inherit from a class that is compatible with BaseNamespace from gevent-socketio, but that instead of routing messages through the real thing it makes the messages available to the test client.

from flask-socketio.

TronPaul avatar TronPaul commented on May 18, 2024

Well the socket stuff runs independently, but there's a few things on the behavior of the context globals (with respect to their modifications with Flask-SocketIO) in flask that I'd like to test. I'd imagine that it'd be easier to tie it in with an additional mixin to the FlaskClient, but just having a test_client on the socketio might be simpler and fit my use case. I'll see how this goes.

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on May 18, 2024

Ah, but the context globals are all handled SocketIO.dispatch_message(), which is invoked by recv_message(), recv_json() and process_event(), so I think if you follow my advice you are covered on that front.

from flask-socketio.

miguelgrinberg avatar miguelgrinberg commented on May 18, 2024

I believe the need for unit tests is now addressed. Closing.

from flask-socketio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.