Exemplo n.º 1
0
def get_associated_resource(subscription_id, feature_id, resource_type, pretty,
                            dest):
    '''Request resources for a particular subscription/feature combination.'''
    cl = clientv1()
    if resource_type in ['target-quad', 'source-quad']:
        msg_format = 'Requesting {} for {}/{}, destination directory is: {}'
        click.echo(msg_format.format(
            resource_type,
            subscription_id,
            feature_id,
            dest
        ))

    resource = cl.get_associated_resource_for_analytic_feature(subscription_id,
                                                               feature_id,
                                                               resource_type)

    if resource_type == 'source-image-info':
        echo_json_response(resource, pretty)

    if resource_type in ['target-quad', 'source-quad']:
        writer = write_to_file(dest, None)
        writer(resource)
        click.echo('{} written, available at: {}/{}'.format(
            resource_type,
            dest,
            resource.name
        ))
def test_write_to_file(tmpdir):
    body = Mock()
    body.name = 'foobar'
    body.write.return_value = None
    utils.write_to_file(str(tmpdir))(body)
    path, callback = body.write.call_args[0]
    expected = tmpdir.join(body.name)
    assert str(expected) == path
    assert callback is None

    expected.write('')
    callback = Mock()
    callback.return_value = None
    utils.write_to_file(str(tmpdir), overwrite=False)(body)
    utils.write_to_file(str(tmpdir), callback=callback, overwrite=False)(body)
    assert body.write.call_count == 1
    assert callback.call_args[1]['skip'] == body
Exemplo n.º 3
0
def test_write_to_file(tmpdir):
    body = Mock()
    body.name = 'foobar'
    body.write.return_value = None
    utils.write_to_file(str(tmpdir))(body)
    path, callback = body.write.call_args[0]
    expected = tmpdir.join(body.name)
    assert str(expected) == path
    assert callback is None

    expected.write('')
    callback = Mock()
    callback.return_value = None
    utils.write_to_file(str(tmpdir), overwrite=False)(body)
    utils.write_to_file(str(tmpdir), callback=callback, overwrite=False)(body)
    assert body.write.call_count == 1
    assert callback.call_args[1]['skip'] == body
Exemplo n.º 4
0
def get_associated_resource(subscription_id, feature_id, resource_type, pretty,
                            dest):
    '''Request resources for a particular subscription/feature combination.'''
    # Note that this command will not work for a custom analytics URL, as the
    # underlying API call is a redirect to the Data API and Mosaics API.
    # See https://github.com/kennethreitz/requests/issues/2949 for more info.
    cl = analytics_client_v1()
    if resource_type in ['target-quad', 'source-quad']:
        msg_format = 'Requesting {} for {}/{}, destination directory is: {}'
        click.echo(
            msg_format.format(resource_type, subscription_id, feature_id,
                              dest))

    resource = cl.get_associated_resource_for_analytic_feature(
        subscription_id, feature_id, resource_type)

    if resource_type == 'source-image-info':
        echo_json_response(resource, pretty)

    if resource_type in ['target-quad', 'source-quad']:
        writer = write_to_file(dest, None)
        writer(resource)
        click.echo('{} written, available at: {}/{}'.format(
            resource_type, dest, resource.name))