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])
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")
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"})
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())
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)
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])
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)
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()
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' })
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()
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)
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')
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")
async def run_notebook_cell(): self.server_ready.wait() client = rockets.Client("ws://" + self.server_url) assert_equal(client.request("ping"), "pong")
def test_no_param(): client = rockets.Client(server_url) assert_equal(client.request('ping'), 'pong')
def test_method_not_found(): client = rockets.Client(server_url) client.notify("pong")
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')
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())
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")
async def run_notebook_cell(): self.server_ready.wait() client = rockets.Client('ws://'+self.server_url) client.notify('hello')
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')
def test_connect_https(): client = rockets.Client("https://" + server_url) assert_equal(client.url, "wss://" + server_url) assert_false(client.connected())
async def run_notebook_cell(): self.server_ready.wait() client = rockets.Client('ws://'+self.server_url) assert_equal(client.request('ping'), 'pong')
def test_invalid_args(): client = rockets.Client(server_url) client.batch('foo', 'bar')
def test_empty_request(): client = rockets.Client(server_url) client.batch([], [])
async def run_notebook_cell(): self.server_ready.wait() client = rockets.Client("ws://" + self.server_url) client.notify("hello")
def test_param(): client = rockets.Client(server_url) assert_equal(client.request('double', [2]), 4)
def test_connect(): client = rockets.Client(server_url) assert_equal(client.url, 'ws://' + server_url) assert_false(client.connected())
def test_param_as_not_a_list(): client = rockets.Client(server_url) assert_equal(client.request('double', 2), 4)
def test_invalid_args(): client = rockets.Client(server_url) client.batch("foo", "bar")