示例#1
0
def test_error_on_connection_lost():
    client = rockets.Client(server_url)
    # do one request, which closes the server, so the second request will throw an error
    assert_equal(client.request("ping"), "pong")
    request_1 = rockets.Request("double", [2])
    request_2 = rockets.Request("double", [4])
    client.batch([request_1, request_2])
示例#2
0
def test_method_not_found():
    client = rockets.Client(server_url)
    try:
        client.request("foo")
    except rockets.RequestError as e:
        assert_equal(e.code, -32601)
        assert_equal(e.message, "Method not found")
示例#3
0
def test_method_not_found():
    client = rockets.Client(server_url)
    request = rockets.Request("foo", ["bar"])
    responses = client.batch([request])
    assert_equal(len(responses), 1)
    response = responses[0]
    assert_equal(response.result, None)
    assert_equal(response.error, {"code": -32601, "message": "Method not found"})
示例#4
0
def test_double_disconnect():
    client = rockets.Client(server_url)
    client.connect()
    assert_true(client.connected())
    client.disconnect()
    assert_false(client.connected())
    client.disconnect()
    assert_false(client.connected())
示例#5
0
def test_subsequent_request():
    start_test_server = websockets.serve(server_handle_two_requests,
                                         "localhost")
    test_server = asyncio.get_event_loop().run_until_complete(
        start_test_server)
    client = rockets.Client("localhost:" +
                            str(test_server.sockets[0].getsockname()[1]))
    assert_equal(client.request("ping"), "pong")
    assert_equal(client.request("double", 2), 4)
示例#6
0
def test_batch():
    client = rockets.Client(server_url)
    request_1 = rockets.Request("double", [2])
    request_2 = rockets.Request("double", [4])
    notification = rockets.Notification("foobar")
    responses = client.batch([request_1, request_2, notification])
    assert_equal(len(responses), 2)
    results = list(map(lambda x: x.result, responses))
    assert_equal(results, [4, 8])
示例#7
0
def test_subsequent_request():
    start_test_server = websockets.serve(server_handle_two_requests,
                                         'localhost')
    test_server = asyncio.get_event_loop().run_until_complete(
        start_test_server)
    client = rockets.Client('localhost:' +
                            str(test_server.sockets[0].getsockname()[1]))
    assert_equal(client.request('ping'), 'pong')
    assert_equal(client.request('double', 2), 4)
示例#8
0
def test_subscribe():
    client = rockets.Client(server_url)
    client.connect()

    def _on_message(message):
        assert_equal(message, "Hello Rockets!")
        asyncio.get_event_loop().stop()

    client.ws_observable.subscribe(_on_message)
    client.send("Rockets")
    asyncio.get_event_loop().run_forever()
示例#9
0
def test_method_not_found():
    client = rockets.Client(server_url)
    request = rockets.Request('foo', ['bar'])
    responses = client.batch([request])
    assert_equal(len(responses), 1)
    response = responses[0]
    assert_equal(response.result, None)
    assert_equal(response.error, {
        'code': -32601,
        'message': 'Method not found'
    })
示例#10
0
def test_notifications():
    client = rockets.Client(server_url)
    client.connect()

    def _on_message(message):
        assert_equal(message.method, "Hello")
        asyncio.get_event_loop().stop()

    client.notifications.subscribe(_on_message)
    client.send("Something")
    client.notify("NotifyMe")
    client.send("Rockets")
    asyncio.get_event_loop().run_forever()
示例#11
0
    def __init__(self, url, loop=None):
        """
        Create a new client instance by connecting to the given URL.

        :param str url: a string 'hostname:port' to connect to a running Brayns instance
        :param asyncio.AbstractEventLoop loop: Event loop where this client should run in
        """
        super().__init__(url)

        self.rockets_client = rockets.Client(url, subprotocols=['rockets'], loop=loop)

        registry, requests = build_schema_requests_from_registry(self.http_url)
        schemas = self.rockets_client.batch(requests)
        super()._build_api(registry, requests, schemas)
示例#12
0
    def test_invalid_environment(self):
        self.server_ready.wait()
        client = rockets.Client('ws://'+self.server_url)

        async def run_notebook_cell(client):
            try:
                client.request('ping')
                return False
            except RuntimeError:
                return True

        called = asyncio.get_event_loop().run_until_complete(run_notebook_cell(client))
        assert_true(called)

        # unblock server thread
        client.notify('hello')
示例#13
0
    def test_invalid_environment(self):
        self.server_ready.wait()
        client = rockets.Client("ws://" + self.server_url)

        async def run_notebook_cell(client):
            client.request("ping")

        try:
            asyncio.get_event_loop().run_until_complete(
                run_notebook_cell(client))
            got_exception = False
        except RuntimeError:
            got_exception = True

        assert_true(got_exception)

        # unblock server thread
        client.notify("hello")
示例#14
0
 async def run_notebook_cell():
     self.server_ready.wait()
     client = rockets.Client("ws://" + self.server_url)
     assert_equal(client.request("ping"), "pong")
示例#15
0
def test_no_param():
    client = rockets.Client(server_url)
    assert_equal(client.request('ping'), 'pong')
示例#16
0
def test_method_not_found():
    client = rockets.Client(server_url)
    client.notify("pong")
示例#17
0
def test_error_on_connection_lost():
    client = rockets.Client(server_url)
    # do one request, which finishes the server, so the second request will throw an error
    assert_equal(client.request('ping'), 'pong')
    client.request('ping')
示例#18
0
def test_no_param():
    client = rockets.Client(server_url)
    client.notify("hello")
    asyncio.get_event_loop().run_until_complete(got_hello)
    assert_true(got_hello.result())
示例#19
0
def test_param():
    client = rockets.Client(server_url)
    client.notify("echo", {"name": "world"})
    asyncio.get_event_loop().run_until_complete(echo_param)
    assert_equal(echo_param.result(), "world")
示例#20
0
 async def run_notebook_cell():
     self.server_ready.wait()
     client = rockets.Client('ws://'+self.server_url)
     client.notify('hello')
示例#21
0
def test_param():
    client = rockets.Client(server_url)
    client.notify('echo', {'name': 'world'})
    asyncio.get_event_loop().run_until_complete(echo_param)
    assert_equal(echo_param.result(), 'world')
示例#22
0
def test_connect_https():
    client = rockets.Client("https://" + server_url)
    assert_equal(client.url, "wss://" + server_url)
    assert_false(client.connected())
示例#23
0
 async def run_notebook_cell():
     self.server_ready.wait()
     client = rockets.Client('ws://'+self.server_url)
     assert_equal(client.request('ping'), 'pong')
示例#24
0
def test_invalid_args():
    client = rockets.Client(server_url)
    client.batch('foo', 'bar')
示例#25
0
def test_empty_request():
    client = rockets.Client(server_url)
    client.batch([], [])
示例#26
0
 async def run_notebook_cell():
     self.server_ready.wait()
     client = rockets.Client("ws://" + self.server_url)
     client.notify("hello")
示例#27
0
def test_param():
    client = rockets.Client(server_url)
    assert_equal(client.request('double', [2]), 4)
示例#28
0
def test_connect():
    client = rockets.Client(server_url)
    assert_equal(client.url, 'ws://' + server_url)
    assert_false(client.connected())
示例#29
0
def test_param_as_not_a_list():
    client = rockets.Client(server_url)
    assert_equal(client.request('double', 2), 4)
示例#30
0
def test_invalid_args():
    client = rockets.Client(server_url)
    client.batch("foo", "bar")