Ejemplo n.º 1
0
def test_timeseries_layer_backward(mocker, visserver, rasterdata_list):
    # Setup
    visserver.ingest.return_value = "http://bogus_url.com/test_data1"
    visserver.get_params.return_value = {'foo': 'bar'}

    tsl = layers.TimeSeriesLayer('tsl', None, rasterdata_list)

    # Don't try to make any remote calls! We set 'create' to True here
    # Because _remote's API is generated dynamically by the nbextension's
    # get_protocol.
    mocker.patch.object(tsl, '_remote', create=True)

    vis_options = mocker.patch.object(tsl, 'vis_options')
    vis_options.serialize.return_value = {'vis': 'options'}

    assert tsl.query_params == {'foo': 'bar'}

    visserver.ingest.return_value = "http://bogus_url.com/test_data2"
    visserver.get_params.return_value = {'foo': 'bar1'}

    tsl.forward()

    ingest_preback = visserver.ingest.call_count
    param_preback = visserver.get_params.call_count

    tsl.backward()

    assert visserver.ingest.call_count == ingest_preback
    assert visserver.get_params.call_count == param_preback + 1
Ejemplo n.º 2
0
def test_timeseries_layer_idx(mocker, visserver, rasterdata_list):
    # Setup
    visserver.ingest.return_value = "http://bogus_url.com/test_data1"

    tsl = layers.TimeSeriesLayer('tsl', None, rasterdata_list)

    # Don't try to make any remote calls! We set 'create' to True here
    # Because _remote's API is generated dynamically by the nbextension's
    # get_protocol.
    mocker.patch.object(tsl, '_remote', create=True)
    vis_options = mocker.patch.object(tsl, 'vis_options')
    vis_options.serialize.return_value = {'vis': 'options'}

    visserver.ingest.return_value = "http://bogus_url.com/test_data3"
    visserver.get_params.return_value = {'query': 'params'}

    prev_name = tsl.name

    tsl.idx(2)

    cur_name = tsl.name
    assert visserver.ingest.call_count == 2
    assert visserver.get_params.call_count == 1
    assert tsl._remote.replace_layer.call_count == 1

    tsl._remote.replace_layer.assert_called_with(
        prev_name, cur_name, "http://bogus_url.com/test_data3",
        {'vis': 'options'}, {'query': 'params'})
Ejemplo n.º 3
0
def test_timeseries_layer(visserver, rasterdata_list):
    tsl = layers.TimeSeriesLayer('tsl', None, rasterdata_list)

    assert tsl.name == 'tsl'
    assert len(tsl.data) == 3
    assert tsl.current.name == "test_data1.tif"
    assert visserver.ingest.call_count == 1
Ejemplo n.º 4
0
def test_timeseries_out_of_range(visserver, rasterdata_list):
    tsl = layers.TimeSeriesLayer('tsl', None, rasterdata_list)

    with pytest.raises(IndexError):
        tsl.idx(-1)

    with pytest.raises(IndexError):
        tsl.idx(4)
Ejemplo n.º 5
0
def test_timeseries_layer(visserver, rasterdata_list):
    tsl = layers.TimeSeriesLayer('tsl', None, rasterdata_list)

    assert tsl.name == '{}_{}_{}'.format(
        'tsl', rasterdata_list[0].name,
        hash(tsl.vis_options) + sys.maxsize + 1)
    assert len(tsl.data) == 3
    assert tsl.current.name == "test_data1"
    assert visserver.ingest.call_count == 1
Ejemplo n.º 6
0
def test_timeseries_layer_forward(mocker, visserver, rasterdata_list):
    # Setup
    visserver.ingest.return_value = "http://bogus_url.com/test_data1.tif"
    visserver.get_params.return_value = {'foo': 'bar'}

    tsl = layers.TimeSeriesLayer('tsl', None, rasterdata_list)

    # Don't try to make any remote calls! We set 'create' to True here
    # Because _remote's API is generated dynamically by the nbextension's
    # get_protocol.
    mocker.patch.object(tsl, '_remote', create=True)

    # Test
    assert tsl.current.name == "test_data1.tif"
    assert visserver.ingest.call_count == 1

    # Check that params are set,  and that we got them from the visserver
    assert tsl.params == {'foo': 'bar'}
    assert visserver.get_params.call_count == 1

    # Setup
    visserver.ingest.return_value = "http://bogus_url.com/test_data2.tif"
    visserver.get_params.return_value = {'foo': 'bar1'}

    tsl.forward()

    # Test
    assert tsl.current.name == "test_data2.tif"
    assert visserver.ingest.call_count == 2

    # replace_wms_layer is called to update the visual layer on the geojs map
    assert tsl._remote.replace_wms_layer.call_count == 1
    assert visserver.get_params.call_count == 2
    tsl._remote.replace_wms_layer.assert_called_with(
        "tsl", "http://bogus_url.com/test_data2.tif", {'foo': 'bar1'})

    # Setup
    visserver.ingest.return_value = "http://bogus_url.com/test_data3.tif"
    visserver.get_params.return_value = {'foo': 'bar2'}

    tsl.forward()

    # Test
    assert tsl.current.name == "test_data3.tif"
    assert visserver.ingest.call_count == 3

    # replace_wms_layer is called to update the visual layer on the geojs map
    assert tsl._remote.replace_wms_layer.call_count == 2
    assert visserver.get_params.call_count == 3
    tsl._remote.replace_wms_layer.assert_called_with(
        "tsl", "http://bogus_url.com/test_data3.tif", {'foo': 'bar2'})
Ejemplo n.º 7
0
def test_layer_reprs(visserver):
    assert str(layers.GeonotebookLayer('gnbl', None, None)) == \
        "<GeonotebookLayer('gnbl')>"
    assert str(layers.AnnotationLayer('al', None, None)) == \
        "<AnnotationLayer('al')>"
    assert str(layers.NoDataLayer('ndl', None, None)) == "<NoDataLayer('ndl')>"
    assert str(layers.DataLayer('dl', None, None, vis_url='bogus')) == \
        "<DataLayer('dl')>"
    assert str(layers.SimpleLayer('sl', None, None, vis_url='bogus')) == \
        "<SimpleLayer('sl')>"
    assert str(
        layers.TimeSeriesLayer('tsl', None, [RDMock(name='bogus_data')])
    ) == \
        "<TimeSeriesLayer('tsl')>"
Ejemplo n.º 8
0
def test_timeseries_layer_idx(mocker, visserver, rasterdata_list):
    # Setup
    visserver.ingest.return_value = "http://bogus_url.com/test_data1.tif"
    visserver.get_params.return_value = {'foo': 'bar'}

    tsl = layers.TimeSeriesLayer('tsl', None, rasterdata_list)

    # Don't try to make any remote calls! We set 'create' to True here
    # Because _remote's API is generated dynamically by the nbextension's
    # get_protocol.
    mocker.patch.object(tsl, '_remote', create=True)
    assert tsl.params == {'foo': 'bar'}

    visserver.ingest.return_value = "http://bogus_url.com/test_data3.tif"
    visserver.get_params.return_value = {'foo': 'bar2'}

    tsl.idx(2)

    assert visserver.ingest.call_count == 2
    assert visserver.get_params.call_count == 2
    assert tsl._remote.replace_wms_layer.call_count == 1
    tsl._remote.replace_wms_layer.assert_called_with(
        "tsl", "http://bogus_url.com/test_data3.tif", {'foo': 'bar2'})