def test_remote_unsubscribe(wsd, ws): ws.unsubscribe = Mock() ws._next_id = Mock(return_value='yyy') threadlocal.reset(websocket=wsd, message={'client': 'xxx'}) wsd.cached_queries['xxx'] = { None: (ws.make_caller('remote.foo'), (), {}, {}) } wsd.unsubscribe('xxx') ws.unsubscribe.assert_called_with('yyy')
class Root(object): def default(self, *args, **kwargs): raise cherrypy.HTTPRedirect(config['default_url']) def logout(self, return_to='/'): cherrypy.session.pop('username', None) raise cherrypy.HTTPRedirect('login?return_to=%s' % return_to) def login(self, username='', password='', message='', return_to=''): if username: if ldap_auth(username, password): cherrypy.session['username'] = username raise cherrypy.HTTPRedirect(return_to) else: message = 'Invalid credentials' return { 'message': message, 'username': username, 'return_to': return_to } def list_plugins(self): from sideboard.internal.imports import plugins plugin_info = {} for plugin, module in plugins.items(): plugin_info[plugin] = { 'name': ' '.join(plugin.split('_')).title(), 'version': getattr(module, '__version__', None), 'paths': [] } for path, app in cherrypy.tree.apps.items(): if path: # exclude what Sideboard itself mounts plugin = app.root.__module__.split('.')[0] plugin_info[plugin]['paths'].append(path) return { 'plugins': plugin_info, 'version': getattr(sideboard, '__version__', None) } def connections(self): return {'connections': connection_checker.check_all()} ws = WebSocketRoot() wsrpc = WebSocketRoot() json = _make_jsonrpc_handler(services.get_services(), precall=jsonrpc_auth) jsonrpc = _make_jsonrpc_handler( services.get_services(), precall=lambda body: threadlocal.reset( username=cherrypy.session.get('username'), client=body.get('websocket_client')))
def reset_threadlocal(): threadlocal.reset(username=cherrypy.session.get('username'))
def test_make_subscription_unsubscribe(ws, orig_ws): ws.unsubscribe = Mock() ws._next_id = Mock(return_value='xxx') threadlocal.reset(message={'client': 'yyy'}, websocket=orig_ws) ws.make_caller('foo.bar').unsubscribe() ws.unsubscribe.assert_called_with('xxx')
def test_make_updated_subscription_caller(ws, orig_ws): threadlocal.reset(message={'client': 'xxx'}, websocket=orig_ws) func = ws.make_caller('foo.bar') assert func is ws.make_caller('foo.baz') assert func.method == 'foo.baz'
def test_make_subscription_caller(ws, orig_ws): threadlocal.reset(message={'client': 'xxx'}, websocket=orig_ws) func = ws.make_caller('foo.bar') assert func(1, 2) == orig_ws.NO_RESPONSE ws._send.assert_called_with(method='foo.bar', params=(1, 2), client=ANY)
def reset_threadlocal(): threadlocal.reset( **{ field: cherrypy.session.get(field) for field in config['ws.session_fields'] })
def test_make_subscription_unsubscribe(ws): ws.unsubscribe = Mock() threadlocal.reset(message={'client': 'xxx'}, websocket=Mock(spec=['NO_RESPONSE'])) ws.make_caller('foo.bar').unsubscribe() ws.unsubscribe.assert_called_with('xxx')
def cleanup(): yield threadlocal.reset() WebSocketDispatcher.instances.clear()