Skip to content

Commit

Permalink
flask_server: add subscription support
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Aug 9, 2023
1 parent 0b696cc commit 109b8d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lexrpc/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from flask import request
from flask.json import jsonify
from flask.views import View
from flask_sock import Sock
from jsonschema import ValidationError

from .base import NSID_RE
Expand All @@ -26,6 +27,12 @@ def init_flask(xrpc_server, app):
app: :class:`flask.Flask`
"""
logger.info(f'Registering {xrpc_server} with {app}')

sock = Sock(app)
for nsid, fn in xrpc_server._methods.items():
if xrpc_server._defs[nsid]['type'] == 'subscription':
sock.route(f'/xrpc/{nsid}')(fn)

app.add_url_rule('/xrpc/<nsid>',
view_func=XrpcEndpoint.as_view('xrpc-endpoint', xrpc_server),
methods=['GET', 'POST', 'OPTIONS'])
Expand Down
8 changes: 8 additions & 0 deletions lexrpc/tests/test_flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def test_query_boolean_param(self):
self.assertEqual("Got 'foolz' for boolean parameter z, expected true or false",
resp.json['message'])

# TODO
# needs websocket test client, but flask-sock doesn't have one yet
# https://github.com/miguelgrinberg/flask-sock/issues/23
@skip
def test_subscription(self):
resp = self.client.get('/xrpc/io.example.subscribe?start=3&end=6')
self.assertEqual(200, resp.status_code, resp.json)

# TODO
@skip
def test_procedure_missing_input(self):
Expand Down

0 comments on commit 109b8d8

Please sign in to comment.