Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jul 4, 2021
1 parent 18b1cc0 commit 9b2e335
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/flask_sock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def websocket_route(ws):
"""
def decorator(f):
@wraps(f)
def websocket_route(*args, **kwargs):
def websocket_route(*args, **kwargs): # pragma: no cover
ws = Server(request.environ)
try:
f(ws, *args, **kwargs)
Expand Down
33 changes: 29 additions & 4 deletions tests/test_flask_sock.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import unittest
import pytest # noqa: F401
from flask import Flask

import flask_sock # noqa: F401
import flask_sock


class FlaskSockTestCase(unittest.TestCase):
def test_dummy(self):
pass
def test_create_direct(self):
app = Flask(__name__, static_folder=None)
sock = flask_sock.Sock(app)

@sock.route('/ws')
def ws(ws):
pass

assert sock.app == app
assert sock.bp is None
assert app.url_map._rules[0].rule == '/ws'
assert app.url_map._rules[0].websocket is True

def test_create_indirect(self):
app = Flask(__name__, static_folder=None)
sock = flask_sock.Sock()

@sock.route('/ws')
def ws(ws):
pass

sock.init_app(app)

assert sock.app is None
assert sock.bp is not None
assert app.url_map._rules[0].rule == '/ws'
assert app.url_map._rules[0].websocket is True

0 comments on commit 9b2e335

Please sign in to comment.