def raw_jsonrpc(service_patcher, precall, monkeypatch): service_patcher('test', {'get_message': lambda name: 'Hello {}!'.format(name)}) def caller(parsed): cherrypy.request.json = parsed result = _make_jsonrpc_handler(services.get_services(), precall=precall)(self=None) return result return caller
def override(self, service_patcher): class MockCrud: pass mr = self.mr = MockCrud() for name in ['create', 'update', 'delete']: setattr(mr, name, Session.crud.crud_notifies(self.make_crud_method(name), delay=0.5)) for name in ['read', 'count']: setattr(mr, name, Session.crud.crud_subscribes(self.make_crud_method(name))) service_patcher('crud', mr)
def test_get_method(wsd, service_patcher): service_patcher('foo', { 'bar': lambda: 'Hello World!', 'baz': 'not a function', '_private': lambda: 'private method' }) assert wsd.get_method('foo.bar')() == 'Hello World!' pytest.raises(Exception, wsd.get_method, 'foo.baz') pytest.raises(Exception, wsd.get_method, 'foo.baf') pytest.raises(Exception, wsd.get_method, 'foo._private')
def test_get_method(wsd, service_patcher): service_patcher( 'foo', { 'bar': lambda: 'Hello World!', 'baz': 'not a function', '_private': lambda: 'private method' }) assert wsd.get_method('foo.bar')() == 'Hello World!' pytest.raises(Exception, wsd.get_method, 'foo.baz') pytest.raises(Exception, wsd.get_method, 'foo.baf') pytest.raises(Exception, wsd.get_method, 'foo._private')
def test_explicit_call_resets_cache(service_patcher, wsd): service_patcher('foo', {'bar': lambda: 'Hello World'}) message = { 'method': 'foo.bar', 'client': 'client-1', 'callback': 'callback-2' } wsd.handle_message(message) assert 'callback-2' in wsd.cached_fingerprints['client-1'] assert WebSocket.send.call_count == 1 wsd.handle_message(message) assert WebSocket.send.call_count == 2
def override(self, service_patcher): class MockCrud: pass mr = self.mr = MockCrud() for name in ['create', 'update', 'delete']: setattr(mr, name, Session.crud.crud_notifies(self.make_crud_method(name))) for name in ['read', 'count']: setattr(mr, name, Session.crud.crud_subscribes(self.make_crud_method(name))) service_patcher('crud', mr)
def handler(ws, wsd, service_patcher, monkeypatch): service_patcher('remote', ws) service_patcher('foo', { 'bar': Mock(return_value='baz'), 'err': Mock(side_effect=Exception) }) ws.subscribe = Mock() ws.call = Mock(return_value=12345) monkeypatch.setattr(log, 'error', Mock()) monkeypatch.setattr(threadlocal, 'reset', Mock(side_effect=threadlocal.reset)) wsd.send = Mock() wsd.internal_action = Mock() wsd.update_triggers = Mock() return wsd
def override(self, service_patcher, config_patcher): config_patcher(1, 'ws.call_timeout') service_patcher('test', self)
def override(self, service_patcher): service_patcher('testservice', self)