def test_list_jobs_output_json(): with mock.patch('databricks_cli.jobs.cli.list_jobs') as list_jobs_mock: with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock: list_jobs_mock.return_value = LIST_RETURN runner = CliRunner() runner.invoke(cli.list_cli, ['--output', 'json']) assert echo_mock.call_args[0][0] == pretty_format(LIST_RETURN)
def get_output_cli(api_client, run_id): """ Gets the output of a run The output schema is documented https://docs.databricks.com/api/latest/jobs.html#runs-get-output """ click.echo(pretty_format(RunsApi(api_client).get_run_output(run_id)))
def get_cli(api_client, instance_pool_id): """ Retrieves metadata about an instance pool. """ click.echo( pretty_format( InstancePoolsApi(api_client).get_instance_pool(instance_pool_id)))
def get_cli(api_client, policy_id): """ Retrieves metadata about a cluster policy. """ click.echo( pretty_format( ClusterPolicyApi(api_client).get_cluster_policy(policy_id)))
def get_cli(api_client, run_id): """ Gets the metadata about a run in json form. The output schema is documented https://docs.databricks.com/api/latest/jobs.html#runs-get. """ click.echo(pretty_format(RunsApi(api_client).get_run(run_id)))
def test_cluster_events_output_json(cluster_api_mock): with mock.patch('databricks_cli.clusters.cli.click.echo') as echo_mock: cluster_api_mock.get_events.return_value = EVENTS_RETURN runner = CliRunner() runner.invoke(cli.cluster_events_cli, ['--cluster-id', CLUSTER_ID, '--output', 'json']) assert echo_mock.call_args[0][0] == pretty_format(EVENTS_RETURN)
def get_cli(api_client, job_id, version): """ Describes the metadata for a job. """ check_version(api_client, version) click.echo(pretty_format( JobsApi(api_client).get_job(job_id, version=version)))
def test_cluster_status_cli(libraries_api_mock): libraries_api_mock.cluster_status.return_value = CLUSTER_STATUS_RETURN runner = CliRunner() res = runner.invoke(cli.cluster_status_cli, ['--cluster-id', TEST_CLUSTER_ID]) libraries_api_mock.cluster_status.assert_called_with(TEST_CLUSTER_ID) assert_cli_output(res.output, pretty_format(CLUSTER_STATUS_RETURN))
def test_create_cli_json(cluster_api_mock): with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock: cluster_api_mock.create_cluster.return_value = CREATE_RETURN runner = CliRunner() runner.invoke(cli.create_cli, ['--json', CREATE_JSON]) assert cluster_api_mock.create_cluster.call_args[0][0] == json.loads(CREATE_JSON) assert echo_mock.call_args[0][0] == pretty_format(CREATE_RETURN)
def test_list_clusters_output_json(): with mock.patch( 'databricks_cli.clusters.cli.list_clusters') as list_clusters_mock: with mock.patch('databricks_cli.clusters.cli.click.echo') as echo_mock: list_clusters_mock.return_value = LIST_RETURN get_callback(cli.list_cli)('json') assert echo_mock.call_args[0][0] == pretty_format(LIST_RETURN)
def create_token_cli(api_client, lifetime_seconds, comment): """ Create and return a token. This call returns the error QUOTA_EXCEEDED if the caller exceeds the token quota, which is 600. """ content = TokensApi(api_client).create(lifetime_seconds, comment) click.echo(pretty_format(content))
def test_get_cli(runs_api_mock): with mock.patch('databricks_cli.runs.cli.click.echo') as echo_mock: runs_api_mock.get_run.return_value = {} runner = CliRunner() runner.invoke(cli.get_cli, ['--run-id', 1, "--version", "2.1"]) assert runs_api_mock.get_run.call_args[0][0] == 1 assert echo_mock.call_args[0][0] == pretty_format({})
def spark_versions_cli(): """ Lists possible Databricks Runtime versions for a cluster. The output format is specified in https://docs.databricks.com/api/latest/clusters.html#spark-versions """ click.echo(pretty_format(spark_versions()))
def list_node_types_cli(): """ Lists possible node types for a cluster. The output format is specified in https://docs.databricks.com/api/latest/clusters.html#list-node-types """ click.echo(pretty_format(list_node_types()))
def test_cancel_cli(): with mock.patch('databricks_cli.runs.cli.cancel_run') as cancel_run_mock: with mock.patch('databricks_cli.runs.cli.click.echo') as echo_mock: cancel_run_mock.return_value = {} runner = CliRunner() runner.invoke(cli.cancel_cli, ['--run-id', 1]) assert cancel_run_mock.call_args[0][0] == 1 assert echo_mock.call_args[0][0] == pretty_format({})
def test_list_cli_with_cluster_id(): with mock.patch('databricks_cli.libraries.cli.cluster_status' ) as cluster_status_mock: cluster_status_mock.return_value = CLUSTER_STATUS_RETURN runner = CliRunner() res = runner.invoke(cli.list_cli, ['--cluster-id', TEST_CLUSTER_ID]) cluster_status_mock.assert_called_with(TEST_CLUSTER_ID) assert_cli_output(res.output, pretty_format(CLUSTER_STATUS_RETURN))
def test_list_group_parents_cli(group_api_mock): with mock.patch('databricks_cli.groups.cli.click.echo') as echo_mock: group_api_mock.list_parents.return_value = GROUP_PARENTS runner = CliRunner() runner.invoke(cli.list_parents_cli, ['--group-name', TEST_GROUP]) group_api_mock.list_parents.assert_called_once_with( 'group', TEST_GROUP) echo_mock.assert_called_once_with(pretty_format(GROUP_PARENTS))
def test_get_job_21(jobs_api_mock): with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock: jobs_api_mock.get_job.return_value = LIST_21_RETURN['jobs'][0] runner = CliRunner() runner.invoke(cli.get_cli, ['--job-id', '1', '--version', '2.1']) assert jobs_api_mock.get_job.call_args == mock.call('1', version='2.1') assert echo_mock.call_args[0][0] == pretty_format( LIST_21_RETURN['jobs'][0])
def get_repo_cli(api_client, repo_id, path): """ Gets the repo. """ id_from_param_or_path = (repo_id if repo_id is not None else ReposApi(api_client).get_repo_id(path)) content = ReposApi(api_client).get(id_from_param_or_path) click.echo(pretty_format(content))
def list_zones_cli(): """ Lists zones where clusters can be created. The output format is specified in https://docs.databricks.com/api/latest/clusters.html#list-zones """ click.echo(pretty_format(list_zones()))
def test_submit_cli_json(): with mock.patch('databricks_cli.runs.cli.submit_run') as submit_run_mock: with mock.patch('databricks_cli.runs.cli.click.echo') as echo_mock: submit_run_mock.return_value = SUBMIT_RETURN runner = CliRunner() runner.invoke(cli.submit_cli, ['--json', SUBMIT_JSON]) assert submit_run_mock.call_args[0][0] == json.loads(SUBMIT_JSON) assert echo_mock.call_args[0][0] == pretty_format(SUBMIT_RETURN)
def list_acls(api_client, scope, output): """ Lists the ACLs set on the given secret scope. """ acls_json = SecretApi(api_client).list_acls(scope) if OutputClickType.is_json(output): click.echo(pretty_format(acls_json)) else: click.echo(tabulate(_acls_to_table(acls_json), headers=ACL_HEADER))
def list_scopes(api_client, output): """ Lists all secret scopes. """ scopes_json = SecretApi(api_client).list_scopes() if OutputClickType.is_json(output): click.echo(pretty_format(scopes_json)) else: click.echo(tabulate(_scopes_to_table(scopes_json), headers=SCOPE_HEADER))
def test_list_cli_without_cluster_id(): with mock.patch('databricks_cli.libraries.cli.all_cluster_statuses') as \ all_cluster_statuses_mock: all_cluster_statuses_mock.return_value = ALL_CLUSTER_STATUSES_RETURN runner = CliRunner() res = runner.invoke(cli.list_cli) all_cluster_statuses_mock.assert_called_once() assert_cli_output(res.output, pretty_format(ALL_CLUSTER_STATUSES_RETURN))
def list_cli(api_client): """ Lists all pipelines and their statuses. Usage: databricks pipelines list """ click.echo(pretty_format(PipelinesApi(api_client).list()))
def test_create_cli_json(): with mock.patch('databricks_cli.clusters.cli.create_cluster' ) as create_cluster_mock: with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock: create_cluster_mock.return_value = CREATE_RETURN get_callback(cli.create_cli)(None, CREATE_JSON) assert create_cluster_mock.call_args[0][0] == json.loads( CREATE_JSON) assert echo_mock.call_args[0][0] == pretty_format(CREATE_RETURN)
def update_repo_cli(api_client, repo_id, branch, tag, path): """ Checks out the repo to the given branch or tag. This call returns an error if the branch or tag doesn't exist. """ id_from_param_or_path = (repo_id if repo_id is not None else ReposApi(api_client).get_repo_id(path)) content = ReposApi(api_client).update(id_from_param_or_path, branch, tag) click.echo(pretty_format(content))
def revoke_cli(api_client, token_id): """ Revoke an access token. This call returns the error RESOURCE_DOES_NOT_EXIST if a token with the specified ID is not valid. """ content = TokensApi(api_client).revoke(token_id) click.echo(pretty_format(content))
def get_cli(api_client, pipeline_id): """ Gets a delta pipeline's current spec and status. Usage: databricks pipelines get --pipeline-id 1234 """ _validate_pipeline_id(pipeline_id) click.echo(pretty_format(PipelinesApi(api_client).get(pipeline_id)))
def get_acl(api_client, scope, principal, output): """ Describes the details about the given ACL for the principal and secret scope. """ acl_json = SecretApi(api_client).get_acl(scope, principal) if OutputClickType.is_json(output): click.echo(pretty_format(acl_json)) else: acl_list = _acls_to_table({'items': [acl_json]}) click.echo(tabulate(acl_list, headers=ACL_HEADER))