7

I am building an app using flask_sockets library. How do I test it?

Here is a code sample I want to write unit tests for:

import flask
from flask import Flask
from flask_sockets import Sockets

app = Flask(__name__)
sockets = Sockets(app)

ws_conns = []


@sockets.route('/echo')
def echo_socket(ws):
    #on connect
    ws_conns.append(ws)

    #while connected
    while True:
        # message = ws.receive()
        # if message is None:
        # #socket has closed/errored
        #     break
        for c in ws_conns:
            c.send('hello and goodbye!')

    #disconnected
    ws_conns.remove(ws)
    ws.close()

I have using this code from this git repo.

Akhil
  • 107
  • 9

0 Answers0