77from databricks .sdk .oauth import Token
88from databricks .sdk .service .serving import DataPlaneInfo
99
10- cp_token = Token (access_token = "control plane token" ,
11- token_type = "type" ,
12- expiry = datetime .now () + timedelta (hours = 1 ))
13- dp_token = Token (access_token = "data plane token" ,
14- token_type = "type" ,
15- expiry = datetime .now () + timedelta (hours = 1 ))
10+ cp_token = Token (access_token = "control plane token" , token_type = "type" , expiry = datetime .now () + timedelta (hours = 1 ))
11+ dp_token = Token (access_token = "data plane token" , token_type = "type" , expiry = datetime .now () + timedelta (hours = 1 ))
1612
1713
1814def success_callable (token : oauth .Token ):
@@ -24,10 +20,9 @@ def success() -> oauth.Token:
2420
2521
2622def test_endpoint_token_source_get_token (config ):
27- token_source = data_plane .DataPlaneEndpointTokenSource (config .host ,
28- success_callable (cp_token ),
29- "authDetails" ,
30- disable_async = True )
23+ token_source = data_plane .DataPlaneEndpointTokenSource (
24+ config .host , success_callable (cp_token ), "authDetails" , disable_async = True
25+ )
3126
3227 with patch ("databricks.sdk.oauth.retrieve_token" , return_value = dp_token ) as retrieve_token :
3328 token_source .token ()
@@ -36,18 +31,18 @@ def test_endpoint_token_source_get_token(config):
3631 args , kwargs = retrieve_token .call_args
3732
3833 assert kwargs ["token_url" ] == config .host + "/oidc/v1/token"
39- assert kwargs ["params" ] == parse .urlencode ({
40- "grant_type" : "urn:ietf:params:oauth:grant-type:jwt-bearer" ,
41- "authorization_details" : "authDetails" ,
42- "assertion" : cp_token .access_token
43- })
34+ assert kwargs ["params" ] == parse .urlencode (
35+ {
36+ "grant_type" : "urn:ietf:params:oauth:grant-type:jwt-bearer" ,
37+ "authorization_details" : "authDetails" ,
38+ "assertion" : cp_token .access_token ,
39+ }
40+ )
4441 assert kwargs ["headers" ] == {"Content-Type" : "application/x-www-form-urlencoded" }
4542
4643
4744def test_token_source_get_token_not_existing (config ):
48- token_source = data_plane .DataPlaneTokenSource (config .host ,
49- success_callable (cp_token ),
50- disable_async = True )
45+ token_source = data_plane .DataPlaneTokenSource (config .host , success_callable (cp_token ), disable_async = True )
5146
5247 with patch ("databricks.sdk.oauth.retrieve_token" , return_value = dp_token ) as retrieve_token :
5348 result_token = token_source .token (endpoint = "endpoint" , auth_details = "authDetails" )
@@ -67,9 +62,7 @@ def token(self):
6762
6863
6964def test_token_source_get_token_existing (config ):
70- another_token = Token (access_token = "another token" ,
71- token_type = "type" ,
72- expiry = datetime .now () + timedelta (hours = 1 ))
65+ another_token = Token (access_token = "another token" , token_type = "type" , expiry = datetime .now () + timedelta (hours = 1 ))
7366 token_source = data_plane .DataPlaneTokenSource (config .host , success_callable (token ), disable_async = True )
7467 token_source ._token_sources ["endpoint:authDetails" ] = MockEndpointTokenSource (another_token )
7568
0 commit comments