Skip to content

Commit f752885

Browse files
committed
Merge branch 'api-client-refactor' into deco-23621
2 parents 384834a + 33c7df7 commit f752885

File tree

5 files changed

+24
-33
lines changed

5 files changed

+24
-33
lines changed

databricks/sdk/_base_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from types import TracebackType
44
from typing import (Any, BinaryIO, Callable, Dict, Iterable, Iterator, List,
55
Optional, Type, Union)
6-
import urllib.parse
76

87
import requests
98
import requests.adapters

databricks/sdk/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
OIDC_TOKEN_PATH = "/oidc/v1/token"
1919

2020

21-
2221
class ApiClient:
2322

2423
def __init__(self, cfg: Config):

tests/fixture_server.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ def __getattr__(self, item):
2929
yield 'http://{0}:{1}'.format(*srv.server_address)
3030
finally:
3131
srv.shutdown()
32-
33-

tests/test_base_client.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from http.server import BaseHTTPRequestHandler
2-
from typing import List, Iterator
2+
from typing import Iterator, List
33

44
import pytest
55
import requests
66

7-
from databricks.sdk._base_client import _BaseClient, _StreamingResponse
87
from databricks.sdk import errors, useragent
8+
from databricks.sdk._base_client import _BaseClient, _StreamingResponse
99
from databricks.sdk.core import DatabricksError
1010

1111
from .clock import FakeClock
@@ -59,7 +59,7 @@ def test_streaming_response_read_closes(config):
5959
@pytest.mark.parametrize('status_code,headers,body,expected_error', [
6060
(400, {}, {
6161
"message":
62-
"errorMessage",
62+
"errorMessage",
6363
"details": [{
6464
"type": DatabricksError._error_info_type,
6565
"reason": "error reason",
@@ -88,23 +88,21 @@ def test_streaming_response_read_closes(config):
8888
(401, {}, {
8989
'error_code': 'UNAUTHORIZED',
9090
'message': 'errorMessage',
91-
},
92-
errors.Unauthenticated('errorMessage', error_code='UNAUTHORIZED')),
91+
}, errors.Unauthenticated('errorMessage', error_code='UNAUTHORIZED')),
9392
(403, {}, {
9493
'error_code': 'FORBIDDEN',
9594
'message': 'errorMessage',
96-
},
97-
errors.PermissionDenied('errorMessage', error_code='FORBIDDEN')),
95+
}, errors.PermissionDenied('errorMessage', error_code='FORBIDDEN')),
9896
(429, {}, {
9997
'error_code': 'TOO_MANY_REQUESTS',
10098
'message': 'errorMessage',
10199
}, errors.TooManyRequests('errorMessage', error_code='TOO_MANY_REQUESTS', retry_after_secs=1)),
102100
(429, {
103101
'Retry-After': '100'
104102
}, {
105-
'error_code': 'TOO_MANY_REQUESTS',
106-
'message': 'errorMessage',
107-
}, errors.TooManyRequests('errorMessage', error_code='TOO_MANY_REQUESTS', retry_after_secs=100)),
103+
'error_code': 'TOO_MANY_REQUESTS',
104+
'message': 'errorMessage',
105+
}, errors.TooManyRequests('errorMessage', error_code='TOO_MANY_REQUESTS', retry_after_secs=100)),
108106
(503, {}, {
109107
'error_code': 'TEMPORARILY_UNAVAILABLE',
110108
'message': 'errorMessage',
@@ -113,9 +111,9 @@ def test_streaming_response_read_closes(config):
113111
(503, {
114112
'Retry-After': '100'
115113
}, {
116-
'error_code': 'TEMPORARILY_UNAVAILABLE',
117-
'message': 'errorMessage',
118-
},
114+
'error_code': 'TEMPORARILY_UNAVAILABLE',
115+
'message': 'errorMessage',
116+
},
119117
errors.TemporarilyUnavailable('errorMessage', error_code='TEMPORARILY_UNAVAILABLE',
120118
retry_after_secs=100)),
121119
(404, {}, {
@@ -217,7 +215,7 @@ def inner(h: BaseHTTPRequestHandler):
217215
with http_fixture_server(inner) as host:
218216
api_client = _BaseClient(retry_timeout_seconds=1, clock=FakeClock())
219217
with pytest.raises(TimeoutError):
220-
res = api_client.do('GET', f'{host}/foo')
218+
api_client.do('GET', f'{host}/foo')
221219

222220
assert len(requests) == 1
223221

@@ -278,5 +276,3 @@ def inner(h: BaseHTTPRequestHandler):
278276
assert 'foo' in res
279277

280278
assert len(requests) == 2
281-
282-

tests/test_core.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import contextlib
2-
import functools
31
import os
42
import pathlib
53
import platform
64
import random
75
import string
8-
import typing
96
from datetime import datetime
107
from http.server import BaseHTTPRequestHandler
118

@@ -25,8 +22,8 @@
2522
from databricks.sdk.service.iam import AccessControlRequest
2623
from databricks.sdk.version import __version__
2724

28-
from .fixture_server import http_fixture_server
2925
from .conftest import noop_credentials
26+
from .fixture_server import http_fixture_server
3027

3128

3229
def test_parse_dsn():
@@ -300,18 +297,20 @@ def test_deletes(config, requests_mock):
300297
assert res is None
301298

302299

303-
@pytest.mark.parametrize('status_code,headers,body,expected_error', [
304-
(401, {}, {
300+
@pytest.mark.parametrize(
301+
'status_code,headers,body,expected_error',
302+
[(401, {}, {
305303
'error_code': 'UNAUTHORIZED',
306304
'message': 'errorMessage',
307305
},
308-
errors.Unauthenticated('errorMessage. Config: host=http://localhost, auth_type=noop', error_code='UNAUTHORIZED')),
309-
(403, {}, {
310-
'error_code': 'FORBIDDEN',
311-
'message': 'errorMessage',
312-
},
313-
errors.PermissionDenied('errorMessage. Config: host=http://localhost, auth_type=noop', error_code='FORBIDDEN')),
314-
])
306+
errors.Unauthenticated('errorMessage. Config: host=http://localhost, auth_type=noop',
307+
error_code='UNAUTHORIZED')),
308+
(403, {}, {
309+
'error_code': 'FORBIDDEN',
310+
'message': 'errorMessage',
311+
},
312+
errors.PermissionDenied('errorMessage. Config: host=http://localhost, auth_type=noop',
313+
error_code='FORBIDDEN')), ])
315314
def test_error(config, requests_mock, status_code, headers, body, expected_error):
316315
client = ApiClient(config)
317316
requests_mock.get("/test", json=body, status_code=status_code, headers=headers)

0 commit comments

Comments
 (0)