Skip to content

Commit

Permalink
Pin API 2.1 for certain endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vsamoilov committed Jul 22, 2024
1 parent b0750eb commit 8bb0443
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .codegen/service.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ class {{.PascalName}}API:{{if .Description}}
{{- "}" -}}
{{- end -}}
{{- end }}'
{{- else if (eq .Path "/api/2.2/jobs/create") -}}
'/api/2.1/jobs/create'
{{- else if (eq .Path "/api/2.2/jobs/update") -}}
'/api/2.1/jobs/update'
{{- else if (eq .Path "/api/2.2/jobs/list") -}}
'/api/2.1/jobs/list'
{{- else if (eq .Path "/api/2.2/jobs/get") -}}
'/api/2.1/jobs/get'
{{- else if (eq .Path "/api/2.2/jobs/reset") -}}
'/api/2.1/jobs/reset'
{{- else if (eq .Path "/api/2.2/jobs/runs/list") -}}
'/api/2.1/jobs/runs/list'
{{- else -}}
'{{.Path}}'
{{- end -}}
Expand Down
100 changes: 100 additions & 0 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from databricks.sdk import WorkspaceClient


# Test cases below are checking that we pinned API 2.1 for certain endpoints, DO NOT REMOVE OR CHANGE THEM. https://databricks.atlassian.net/browse/JOBS-19298
def test_jobs_create(config, requests_mock):
requests_mock.post("http://localhost/api/2.1/jobs/create",
request_headers={
'Accept': 'application/json',
'Content-Type': 'application/json',
},
text="null",
)

w = WorkspaceClient(config=config)
w.jobs.create()

assert requests_mock.call_count == 1
assert requests_mock.called


def test_jobs_update(config, requests_mock):
requests_mock.post("http://localhost/api/2.1/jobs/update",
request_headers={
'Accept': 'application/json',
'Content-Type': 'application/json',
},
text="null",
)

w = WorkspaceClient(config=config)
w.jobs.update(job_id="job_id")

assert requests_mock.call_count == 1
assert requests_mock.called


def test_jobs_list(config, requests_mock):
requests_mock.get("http://localhost/api/2.1/jobs/list",
request_headers={
'Accept': 'application/json',
},
text="null",
)

w = WorkspaceClient(config=config)
for _ in w.jobs.list():
pass

assert requests_mock.call_count == 1
assert requests_mock.called


def test_jobs_get(config, requests_mock):
requests_mock.get("http://localhost/api/2.1/jobs/get",
request_headers={
'Accept': 'application/json',
},
text="null",
)

w = WorkspaceClient(config=config)
w.jobs.get(job_id="job_id")

assert requests_mock.call_count == 1
assert requests_mock.called


def test_jobs_reset(config, requests_mock):
requests_mock.post("http://localhost/api/2.1/jobs/reset",
request_headers={
'Accept': 'application/json',
'Content-Type': 'application/json',
},
text="null",
)

w = WorkspaceClient(config=config)
w.jobs.reset(job_id="job_id", new_settings=None)

assert requests_mock.call_count == 1
assert requests_mock.called


def test_jobs_runs_list(config, requests_mock):
requests_mock.get("http://localhost/api/2.1/jobs/runs/list",
request_headers={
'Accept': 'application/json',
},
text="null",
)

w = WorkspaceClient(config=config)
for _ in w.jobs.list_runs(job_id="job_id"):
pass

assert requests_mock.call_count == 1
assert requests_mock.called


# End of test cases for API 2.1 pinning

0 comments on commit 8bb0443

Please sign in to comment.