def test_notification(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.notify', new=mock_rpc_notify): app = brayns.Client('localhost:8200') app.inspect_notify(array=[1, 2])
def test_object_properties(): with patch('brayns.utils.http_request', new=mock_http_request): app = brayns.Client('localhost:8200') assert_equal(app.test_object.integer, TEST_OBJECT['integer']) assert_equal(app.test_object.number, TEST_OBJECT['number']) assert_equal(app.test_object.string, TEST_OBJECT['string']) assert_equal(app.test_object.boolean, TEST_OBJECT['boolean'])
def test_rpc_one_parameter(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect assert_equal(inspect.getdoc(app.test_rpc), TEST_RPC_ONE_PARAMETER['description']) assert_true(app.test_rpc(doit=False, name='foo'))
def test_rpc_only_return(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect assert_equal(inspect.getdoc(app.test_rpc_return), TEST_RPC_ONLY_RETURN['description']) assert_true(app.test_rpc_return())
def test_object_properties_enum_with_title(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.batch_request', new=mock_batch_request): app = brayns.Client('localhost:8200') assert_equal(app.test_object.enum_title, TEST_OBJECT['enum_title']) assert_true(hasattr(app, 'MY_ENUM_MINE')) assert_true(hasattr(app, 'MY_ENUM_YOURS'))
def test_object_commit(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.request', new=mock_rpc_request_object_commit): app = brayns.Client('localhost:8200') app._ws_connected = True app.test_object.integer = 42 app.test_object.commit()
def test_object_properties_enum(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.batch_request', new=mock_batch_request): app = brayns.Client('localhost:8200') assert_equal(app.test_object.enum, TEST_OBJECT['enum']) assert_true(hasattr(app, 'ENUM_VALUE_A')) assert_true(hasattr(app, 'ENUM_VALUE_B'))
def test_array(): with patch('rockets.Client.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.request', new=mock_rpc_request), \ patch('rockets.Client.batch', new=mock_batch): app = brayns.Client('localhost:8200') assert_equal(app.test_array, TEST_ARRAY)
def test_open_ui(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('webbrowser.open', new=mock_webbrowser_open): app = brayns.Client('localhost:8200') app.open_ui()
def test_image_not_base64(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch): app = brayns.Client('localhost:8200') setattr(app, 'snapshot', mock_snapshot) app.image(size=[50, 50], format='jpg')
def test_rpc_array_parameter(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect assert_true(inspect.getdoc(app.inspect).startswith(TEST_RPC_ARRAY_PARAMETER['description'])) assert_true(app.inspect(xy=[1,2]))
def test_object_properties_array(): with patch('rockets.Client.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.request', new=mock_rpc_request), \ patch('rockets.Client.batch', new=mock_batch): app = brayns.Client('localhost:8200') assert_equal(app.test_object.array, TEST_OBJECT['array'])
def test_notification(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.notify', new=mock_rpc_notify): app = brayns.Client('localhost:8200') app.test_notify_single_arg(doit=False, name='foo')
def test_rpc_no_type(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') assert_false(hasattr(app, 'test-rpc-no-type'))
def test_init(): with patch('brayns.utils.http_request', new=mock_http_request): app = brayns.Client('localhost:8200') assert_equal(app.url(), 'http://localhost:8200/') assert_equal(app.version.as_dict(), TEST_VERSION) assert_equal(str(app), 'Brayns version 0.7.0 running on http://localhost:8200/')
def test_object_properties_enum_array(): with patch('brayns.utils.http_request', new=mock_http_request): app = brayns.Client('localhost:8200') assert_equal(app.test_object.enum_array, TEST_OBJECT['enum_array']) assert_true(hasattr(app, 'ENUM_ARRAY_ONE')) assert_true(hasattr(app, 'ENUM_ARRAY_TWO')) assert_true(hasattr(app, 'ENUM_ARRAY_THREE'))
def test_rpc_one_of_parameter_weird_casings(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') assert_true(hasattr(app, 'StereofullMode')) assert_true(hasattr(app, 'MonoFullMode')) assert_true(hasattr(app, 'TruthfulMode')) assert_true(hasattr(app, 'MeaningFulMode'))
def test_object_commit(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.request', new=mock_rpc_request), \ patch('rockets.AsyncClient.connected', new=mock_connected): app = brayns.Client('localhost:8200') app.test_object.integer = 42 app.test_object.commit()
def test_init(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.request', new=mock_rpc_request), \ patch('rockets.Client.batch', new=mock_batch): app = brayns.Client('localhost:8200') assert_equal(app.http_url, 'http://localhost:8200/') assert_equal(app.version.as_dict(), TEST_VERSION) assert_equal(str(app), 'Brayns version 1.0.1 running on http://localhost:8200/')
def test_synchronous_request(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect assert_equal(inspect.getdoc(app.test_request_single_arg), TEST_RPC_ONE_PARAMETER['description']) assert_equal(app.test_request_single_arg(doit=False, name='foo'), None) assert_equal(app.test_request_single_arg(doit=True, name='foo'), 'foo')
def test_weird_casings(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') assert_true(hasattr(app, 'StereofullMode')) assert_true(hasattr(app, 'MonoFullMode')) assert_true(hasattr(app, 'TruthfulMode')) assert_true(hasattr(app, 'MeaningFulMode'))
def test_rpc_one_of_parameter(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('brayns.RpcClient.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect assert_true(inspect.getdoc(app.set_camera).startswith(TEST_RPC_ONEOF_PARAMETER['description'])) assert_true(hasattr(app, 'PerspectiveCamera')) param = app.PerspectiveCamera() param.fov = 10.2 assert_true(app.set_camera(param))
def test_synchronous_request(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect assert_equal(inspect.getdoc(app.test_rpc_return), TEST_RPC_ONLY_RETURN['description']) assert_equal(app.test_rpc_return(), 42)
def test_set_colormap(): with patch('brayns.utils.http_request', new=mock_http_request): app = brayns.Client('localhost:8200') setattr(app, 'transfer_function', MockTransferFunction()) app.set_colormap(colormap_size=123, data_range=(0, 42)) assert_equal(len(app.transfer_function.contribution), 123) assert_equal(len(app.transfer_function.diffuse), 123) assert_equal(len(app.transfer_function.emission), 0) assert_equal(app.transfer_function.range, (0, 42)) assert_true(app.transfer_function.commit_called)
def test_notification(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.notify', new=mock_rpc_notify): app = brayns.Client('localhost:8200') perspective = app.PerspectiveCamera() perspective.fov = 10.2 app.set_camera_no_return(perspective) assert_true(hasattr(app, 'PanoramicCamera')) panoramic = app.PanoramicCamera() app.set_camera_no_return(panoramic)
def test_set_colormap(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch): app = brayns.Client('localhost:8200') setattr(app, 'transfer_function', MockTransferFunction()) palette = [[0, 1, 0], [0, 0.5, 0.1]] app.set_colormap(palette, data_range=(0, 42)) assert_equal(len(app.transfer_function.contribution), 2) assert_equal(len(app.transfer_function.diffuse), 2) assert_equal(len(app.transfer_function.emission), 0) assert_equal(app.transfer_function.range, (0, 42)) assert_true(app.transfer_function.commit_called)
def test_synchronous_request(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect doc = inspect.getdoc(app.inspect) assert_true(doc.startswith(TEST_RPC_ARRAY_PARAMETER['description'])) assert_true( doc.find(TEST_RPC_ARRAY_PARAMETER['params'][0]['description']) != -1) assert_true(app.inspect(array=[1, 2])) assert_false(app.inspect(array=[3, 4]))
def test_notifications(): with patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.request', new=mock_rpc_request), \ patch('rockets.Client.batch', new=mock_batch): app = brayns.Client(server_url) def _on_message(message): assert_equal(app.test_object.string, 'changed') close_server.set_result(True) asyncio.get_event_loop().stop() app.rockets_client.ws_observable.subscribe(_on_message) assert_equal(app.test_object.string, 'foobar') send_message.set_result(True) asyncio.get_event_loop().run_forever()
def test_synchronous_request(): with patch('rockets.AsyncClient.connected', new=mock_connected), \ patch('brayns.utils.http_request', new=mock_http_request), \ patch('rockets.Client.batch', new=mock_batch), \ patch('rockets.Client.request', new=mock_rpc_request): app = brayns.Client('localhost:8200') import inspect assert_true( inspect.getdoc(app.set_camera).startswith( TEST_RPC_ONEOF_PARAMETER['description'])) assert_true(hasattr(app, 'PerspectiveCamera')) perspective = app.PerspectiveCamera() perspective.fov = 10.2 assert_equal(app.set_camera(perspective), perspective.fov) assert_true(hasattr(app, 'PanoramicCamera')) panoramic = app.PanoramicCamera() assert_equal(app.set_camera(panoramic), 0)
def test_init_no_registry(): with patch('brayns.utils.http_request', new=mock_http_request_no_registry): brayns.Client('localhost:8200')