コード例 #1
0
ファイル: test_jsonrpc.py プロジェクト: robdennis/sideboard
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
コード例 #2
0
 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)
コード例 #3
0
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')
コード例 #4
0
ファイル: test_jsonrpc.py プロジェクト: msg4real/sideboard
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
コード例 #5
0
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')
コード例 #6
0
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
コード例 #7
0
ファイル: test_server.py プロジェクト: msg4real/sideboard
    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)
コード例 #8
0
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
コード例 #9
0
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
コード例 #10
0
 def override(self, service_patcher, config_patcher):
     config_patcher(1, 'ws.call_timeout')
     service_patcher('test', self)
コード例 #11
0
 def override(self, service_patcher):
     service_patcher('testservice', self)
コード例 #12
0
 def override(self, service_patcher, config_patcher):
     config_patcher(1, 'ws.call_timeout')
     service_patcher('test', self)
コード例 #13
0
 def override(self, service_patcher):
     service_patcher('testservice', self)