|
1 | 1 | import os
|
| 2 | +import pathlib |
2 | 3 | import platform
|
| 4 | +import random |
| 5 | +import string |
| 6 | +from datetime import datetime |
3 | 7 |
|
4 | 8 | import pytest
|
5 | 9 |
|
6 | 10 | from databricks.sdk import useragent
|
7 | 11 | from databricks.sdk.config import Config, with_product, with_user_agent_extra
|
| 12 | +from databricks.sdk.credentials_provider import Token |
8 | 13 | from databricks.sdk.version import __version__
|
9 | 14 |
|
10 | 15 | from .conftest import noop_credentials, set_az_path
|
@@ -79,6 +84,40 @@ def test_config_copy_deep_copies_user_agent_other_info(config):
|
79 | 84 | useragent._reset_extra(original_extra)
|
80 | 85 |
|
81 | 86 |
|
| 87 | +def test_config_deep_copy(monkeypatch, mocker, tmp_path): |
| 88 | + mocker.patch('databricks.sdk.credentials_provider.CliTokenSource.refresh', |
| 89 | + return_value=Token(access_token='token', |
| 90 | + token_type='Bearer', |
| 91 | + expiry=datetime(2023, 5, 22, 0, 0, 0))) |
| 92 | + |
| 93 | + write_large_dummy_executable(tmp_path) |
| 94 | + monkeypatch.setenv('PATH', tmp_path.as_posix()) |
| 95 | + |
| 96 | + config = Config(host="https://abc123.azuredatabricks.net", auth_type="databricks-cli") |
| 97 | + config_copy = config.deep_copy() |
| 98 | + assert config_copy.host == config.host |
| 99 | + |
| 100 | + |
| 101 | +def write_large_dummy_executable(path: pathlib.Path): |
| 102 | + cli = path.joinpath('databricks') |
| 103 | + |
| 104 | + # Generate a long random string to inflate the file size. |
| 105 | + random_string = ''.join(random.choice(string.ascii_letters) for i in range(1024 * 1024)) |
| 106 | + cli.write_text("""#!/bin/sh |
| 107 | +cat <<EOF |
| 108 | +{ |
| 109 | +"access_token": "...", |
| 110 | +"token_type": "Bearer", |
| 111 | +"expiry": "2023-05-22T00:00:00.000000+00:00" |
| 112 | +} |
| 113 | +EOF |
| 114 | +exit 0 |
| 115 | +""" + random_string) |
| 116 | + cli.chmod(0o755) |
| 117 | + assert cli.stat().st_size >= (1024 * 1024) |
| 118 | + return cli |
| 119 | + |
| 120 | + |
82 | 121 | def test_load_azure_tenant_id_404(requests_mock, monkeypatch):
|
83 | 122 | set_az_path(monkeypatch)
|
84 | 123 | mock = requests_mock.get('https://abc123.azuredatabricks.net/aad/auth', status_code=404)
|
|
0 commit comments