Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions databricks_cli/jobs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ def reset_cli(api_client, json_file, json, job_id, version):
with open(json_file, 'r') as f:
json = f.read()
deser_json = json_loads(json)
request_body = {
'job_id': job_id,
'new_settings': deser_json
}
if 'new_settings' in deser_json:
request_body = deser_json
request_body['job_id'] = job_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about checking for new_clusters as the title implies? If you specify a dict with only that key, it would be wrapped in the new_settings field in the else branch. I suspect you may need to check for more than just the new_settings key here to determine what is actually specified.

else:
request_body = {
'job_id': job_id,
'new_settings': deser_json
}
JobsApi(api_client).reset_job(request_body, version=version)


Expand Down
17 changes: 13 additions & 4 deletions tests/jobs/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,24 @@ def test_create_cli_json_file(jobs_api_mock, tmpdir):

RESET_JSON = '{"job_name": "test_job"}'

CORRECT_RESPONSE = {'job_id': 1,
'new_settings': json.loads(RESET_JSON)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be CORRECT_REQUEST_PAYLOAD if I'm reading the test correctly.


@provide_conf
def test_reset_cli_json(jobs_api_mock):
runner = CliRunner()
runner.invoke(cli.reset_cli, ['--json', RESET_JSON, '--job-id', 1])
assert jobs_api_mock.reset_job.call_args[0][0] == {
'job_id': 1,
'new_settings': json.loads(RESET_JSON)
}
assert jobs_api_mock.reset_job.call_args[0][0] == CORRECT_RESPONSE


RESET_JSON_NEW_SETTINGS = '{"new_settings": {"job_name": "test_job"}}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use RESET_JSON to avoid duplication.



@provide_conf
def test_reset_cli_json_new_settings(jobs_api_mock):
runner = CliRunner()
runner.invoke(cli.reset_cli, ['--json', RESET_JSON_NEW_SETTINGS, '--job-id', 1])
assert jobs_api_mock.reset_job.call_args[0][0] == CORRECT_RESPONSE


LIST_RETURN = {
Expand Down