Ejemplo n.º 1
0
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])
Ejemplo n.º 2
0
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'])
Ejemplo n.º 3
0
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'))
Ejemplo n.º 4
0
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())
Ejemplo n.º 5
0
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'))
Ejemplo n.º 6
0
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()
Ejemplo n.º 7
0
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'))
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
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')
Ejemplo n.º 11
0
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]))
Ejemplo n.º 12
0
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'])
Ejemplo n.º 13
0
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')
Ejemplo n.º 14
0
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'))
Ejemplo n.º 15
0
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/')
Ejemplo n.º 16
0
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'))
Ejemplo n.º 17
0
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'))
Ejemplo n.º 18
0
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()
Ejemplo n.º 19
0
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/')
Ejemplo n.º 20
0
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')
Ejemplo n.º 21
0
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'))
Ejemplo n.º 22
0
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))
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
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]))
Ejemplo n.º 28
0
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()
Ejemplo n.º 29
0
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)
Ejemplo n.º 30
0
def test_init_no_registry():
    with patch('brayns.utils.http_request', new=mock_http_request_no_registry):
        brayns.Client('localhost:8200')