Repository navigation
Expand file tree
/
Copy pathtest_cli.py
More file actions
72 lines (52 loc) · 2.29 KB
/
Copy pathtest_cli.py
File metadata and controls
72 lines (52 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from dbsqlcli.main import apply_credentials_from_cfg
from databricks.sql.auth.auth import AuthType
CONFIG = {
"credentials": {
"http_path": "config/path/to/endpoint",
"host_name": "config.cloud.databricks.com",
"access_token": "dapi_configRandomAccessKey",
}
}
HTTP_PATH = "arg/path/to/endpoint"
HOST_NAME = "arg.cloud.databricks.com"
ACCESS_TOKEN = "dapi_argRandomAccessKey"
def test_clirc_credentials_are_used():
"""When no credentials are passed to the CLI, read credentials from the config file"""
host_name, http_path, access_token, auth_type = apply_credentials_from_cfg(
None, None, None, None, CONFIG
)
assert http_path == "config/path/to/endpoint"
assert host_name == "config.cloud.databricks.com"
assert access_token == "dapi_configRandomAccessKey"
def test_cli_args_credentials_are_used():
"""When credentials are passed to the CLI, use these instead of the config file."""
host_name, http_path, access_token, auth_type = apply_credentials_from_cfg(
HOST_NAME, HTTP_PATH, ACCESS_TOKEN, AuthType.DATABRICKS_OAUTH.value, CONFIG
)
assert http_path == HTTP_PATH
assert host_name == HOST_NAME
assert access_token == ACCESS_TOKEN
assert auth_type == AuthType.DATABRICKS_OAUTH.value
def test_blended_credentials_are_used():
"""When some credentials are passed ot the CLI, use config file to fill in the gaps."""
credential = CONFIG["credentials"].copy()
credential["auth_type"] = AuthType.DATABRICKS_OAUTH.value
host_name, http_path, access_token, auth_type = apply_credentials_from_cfg(
hostname=None,
http_path=HTTP_PATH,
access_token=None,
auth_type=None,
cfg={"credentials": credential},
)
assert host_name == "config.cloud.databricks.com"
assert http_path == HTTP_PATH
assert access_token == "dapi_configRandomAccessKey"
assert auth_type == AuthType.DATABRICKS_OAUTH.value
def test_passthrough_with_empty_config():
host_name, http_path, access_token, auth_type = apply_credentials_from_cfg(
HOST_NAME, HTTP_PATH, ACCESS_TOKEN, AuthType.DATABRICKS_OAUTH.value, {}
)
assert host_name == HOST_NAME
assert http_path == HTTP_PATH
assert access_token == ACCESS_TOKEN
assert auth_type == AuthType.DATABRICKS_OAUTH.value