Example #1
0
def test_outfold_setter(credentials, tmpdir):
    vds = VdsApiBase(credentials['user'], credentials['pw'])
    assert vds.outfold == ''
    new_dir = os.path.join(tmpdir, 'fold1', 'fold2')
    assert not os.path.exists(new_dir)
    vds.set_outfold(new_dir)
    assert os.path.exists(new_dir)
Example #2
0
def test_products(credentials, example_config_area):
    vds = VdsApiBase(credentials['user'], credentials['pw'])
    assert isinstance(vds.products, Products)
    assert all([isinstance(p, Product) for p in vds.products])
    products = getpar_fromtext(example_config_area, 'products')
    prod = vds.products[products]
    assert prod.api_name is not None
    vds.check_valid_products(products)
Example #3
0
def test_rois_getitem(credentials, example_config_ts):

    vds = VdsApiBase(credentials['user'], credentials['pw'])
    assert isinstance(vds.rois, Rois)
    assert all([isinstance(r, Roi) for r in vds.rois])
    roi_str, roi_name = getpar_fromtext(example_config_ts, 'rois')
    assert vds.rois[roi_str].id == int(roi_str)
    assert vds.rois[int(roi_str)].id == int(roi_str)
    assert vds.rois[roi_name].name == roi_name
Example #4
0
def test_show_hide_all():

    vds = VdsApiBase()
    vds.rois.show_all()
    assert all([roi.display for roi in vds.rois])

    vds.rois.hide_all()
    assert all([not roi.display for roi in vds.rois])

    vds.rois.filter(max_id=25010).show_all()
    assert vds.rois[25009].display
    assert vds.rois[25010].display
    assert not vds.rois[25011].display
Example #5
0
def test_roi_update():

    vds = VdsApiBase()
    roi = vds.rois[30596]  # This one is meant to be updated

    roi.update('OldName', description='old rect', display=False)

    assert roi.name == 'OldName'
    assert roi.description == 'old rect'
    assert not roi.display

    roi.update('NewName', description='Same rectangle', display=True)
    assert roi.name == 'NewName'
    assert roi.description == 'Same rectangle'
    assert roi.display
Example #6
0
def test_roi_geojson():
    vds = VdsApiBase()
    roi = vds.rois[25009]

    geojson_should = {'type': 'MultiPolygon',
                      'coordinates': [[[[-5.718384, 66.264645],
                                        [-5.718384, 66.739902],
                                        [-5.267944, 66.739902],
                                        [-5.267944, 66.264645],
                                        [-5.718384, 66.264645]]]]
                      }

    assert roi._geojson is None
    requested_geojson = roi.geojson
    assert requested_geojson == geojson_should
Example #7
0
def test_rois_filter():

    vds = VdsApiBase()
    rois = vds.rois.filter(min_id=25009, max_id=25010)
    assert rois.ids_to_list() == [25009, 25010]

    rois = vds.rois.filter(area_min=1e8, area_max=1e9)
    assert rois.ids_to_list() == [25010, 25011]

    rois = vds.rois.filter(name_regex='Center|Bottom', description_regex='pixels')
    assert rois.ids_to_list() == [25009, 25011]

    rois = vds.rois.filter(created_after=dt.datetime(2020, 8, 16, 12, 58),
                           created_before=dt.datetime(2020, 8, 16, 13, 0))
    assert rois.ids_to_list() == [25010, 25011]
Example #8
0
def test(ctx):
    vds = VdsApiBase(ctx.obj['user'], ctx.obj['passwd'], debug=False)
    if ctx.obj['impersonate']:
        vds.impersonate(ctx.obj['impersonate'])
    for environment in ['maps', 'staging', 'test']:
        try:
            vds.environment = environment
            click.echo(vds)
            start = time.time()
            status_uri = f'http://{vds.host}/api/v2/status/'
            bv = vds.get_content(status_uri)['backend_version']
            click.echo(f"backend version: {bv}")
            vds.logger.info(f'API RESPONSE TIME: {time.time() - start:0.4f} seconds')
        except HTTPError:
            vds.logger.info(f'Not authorized for environment: {environment}')
        click.echo()
    vds.logger.info(' ================== Finished ==================')
Example #9
0
def info(ctx, all_info, user_, product_list, roi):
    vds = VdsApiBase(ctx.obj['user'], ctx.obj['passwd'], debug=False)
    if ctx.obj['environment'] is not None:
        vds.host = ctx.obj['environment']
    if ctx.obj['impersonate']:
        vds.impersonate(ctx.obj['impersonate'])
    bv = vds.get_content(f'http://{vds.host}/api/v2/status/')['backend_version']
    click.echo(f"backend version: {bv}")
    if not (user_ or product_list or roi):
        all_info = True

    if user_ or all_info:
        show = ['id', 'name', 'email', 'roles', 'login_count', 'last_login_at']
        if vds.usr_dict['geojson_area_allowed']['type'] == 'Polygon':
            x, y = zip(*vds.usr_dict['geojson_area_allowed']['coordinates'][0])
        else:
            x, y = None, None
        click.echo('\n######################### USER #########################\n')
        njump = 26  # Hosizontal outline position
        for key in show:
            click.echo(f'{key:>{njump}s} | {vds.usr_dict[key]} ')
        if x is not None and y is not None:
            click.echo(f'\n{"Area extent LON":>{njump}s} | {min(x)} {max(x)}')
            click.echo(f'{"Area extent LAT":>{njump}s} | {min(y)} {max(y)}')

    if product_list or all_info:
        head = '\n ## |             # API name #            |         # Name #        \n'
        click.echo('\n############################ PRODUCTS ############################' + head + '='*len(head))
        for i, p in enumerate(vds.products):
            click.echo(f' {i:02d} | {p.api_name:35s} | {p.name} ')

    if roi or all_info:
        click.echo('\n######################### ROIS #########################')
        click.echo(vds.rois)
        click.echo()
        vds.logger.info(' ================== Finished ==================')
Example #10
0
def test_host_setter(credentials):
    vds = VdsApiBase(credentials['user'], credentials['pw'])
    vds.host = 'staging'
    assert vds.host == 'staging.vandersat.com'
    with pytest.raises(ValueError):
        vds.host = 'nonexisting'
Example #11
0
def test_load_info(credentials):
    vds = VdsApiBase(credentials['user'], credentials['pw'])
    assert type(vds.usr_dict) is dict
    assert type(vds.rois) is Rois
Example #12
0
def test_login_from_environment():
    vds = VdsApiBase()
    assert vds.products is not None
Example #13
0
def test_login(credentials):
    vds = VdsApiBase(credentials['user'], credentials['pw'])
    assert vds.products is not None