def test_databricks_params_token(get_config): get_config.return_value = DatabricksConfig.from_token("host", "mytoken", insecure=False) params = databricks_utils.get_databricks_host_creds() assert params.host == "host" assert params.token == "mytoken" assert not params.ignore_tls_verification
def test_databricks_params_user_password(get_config): get_config.return_value = DatabricksConfig.from_password("host", "user", "pass", insecure=False) params = databricks_utils.get_databricks_host_creds() assert params.host == "host" assert params.username == "user" assert params.password == "pass"
def test_is_valid(self): config = DatabricksConfig.from_password(TEST_HOST, TEST_USER, TEST_PASSWORD) assert config.is_valid config = DatabricksConfig.from_token(TEST_HOST, TEST_TOKEN) assert config.is_valid
def get_config(self): return DatabricksConfig.from_password("host", "user", "pass", insecure=False)
def wrapper(test, *args, **kwargs): config = DatabricksConfig.from_token('test-host', 'test-token') update_and_persist_config(DEFAULT_SECTION, config) config = DatabricksConfig.from_token('test-host-2', 'test-token-2') update_and_persist_config(TEST_PROFILE, config) return test(*args, **kwargs)
def test_is_valid_with_password(self): config = DatabricksConfig.from_password(TEST_HOST, TEST_USER, TEST_PASSWORD) assert config.is_valid_with_password assert not config.is_valid_with_token
def test_from_token(self): config = DatabricksConfig.from_token(TEST_HOST, TEST_TOKEN) assert config.host == TEST_HOST assert config.token == TEST_TOKEN
def get_config(self): return DatabricksConfig.from_token("Override", "Token!")
def get_config(self): # pylint: disable=unused-argument config = DatabricksConfig(host, None, None, token, False) if config.is_valid: return config return None
def test_databricks_params_custom_profile(get_config_for_profile): get_config_for_profile.return_value = \ DatabricksConfig("host", "user", "pass", None, insecure=True) params = rest_utils.get_databricks_http_request_kwargs_or_fail("profile") assert params['verify'] is False get_config_for_profile.assert_called_with("profile")
def test_databricks_params_no_verify(get_config): get_config.return_value = \ DatabricksConfig("host", "user", "pass", None, insecure=True) params = rest_utils.get_databricks_http_request_kwargs_or_fail() assert params['verify'] is False
def _configure_cli_token(profile, insecure): config = get_config_for_profile(profile) host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost()) token = click.prompt(PROMPT_TOKEN, default=config.token) new_config = DatabricksConfig.from_token(host, token, insecure) update_and_persist_config(profile, new_config)
import shutil import tempfile import unittest from uuid import uuid4 from click.testing import CliRunner from cookiecutter.main import cookiecutter from databricks_cli.configure.provider import DatabricksConfig from path import Path from retry import retry CICD_TEMPLATES_URI = "https://github.com/databrickslabs/cicd-templates.git" TEST_HOST = "https:/dbx.cloud.databricks.com" TEST_TOKEN = "dapiDBXTEST" test_dbx_config = DatabricksConfig.from_token(TEST_HOST, TEST_TOKEN) @retry(tries=10, delay=5, backoff=5) def initialize_cookiecutter(project_name): cookiecutter(CICD_TEMPLATES_URI, no_input=True, extra_context={"project_name": project_name}) def invoke_cli_runner(*args, **kwargs): """ Helper method to invoke the CliRunner while asserting that the exit code is actually 0. """ expected_error = kwargs.pop("expected_error") if kwargs.get("expected_error") else None res = CliRunner().invoke(*args, **kwargs)
def test_databricks_params_no_verify(get_config): get_config.return_value = \ DatabricksConfig("host", "user", "pass", None, insecure=True) params = databricks_utils.get_databricks_host_creds() assert params.ignore_tls_verification
def test_from_password(self): config = DatabricksConfig.from_password(TEST_HOST, TEST_USER, TEST_PASSWORD) assert config.host == TEST_HOST assert config.username == TEST_USER assert config.password == TEST_PASSWORD
def test_get_config_throw_exception_if_profile_invalid(): invalid_config = DatabricksConfig.from_token(None, None) update_and_persist_config(DEFAULT_SECTION, invalid_config) with pytest.raises(InvalidConfigurationError): get_config()
def test_is_valid_with_token(self): config = DatabricksConfig.from_token(TEST_HOST, TEST_TOKEN) assert not config.is_valid_with_password assert config.is_valid_with_token
def get_config(self): return DatabricksConfig("host", "user", "pass", None, insecure=False)
def configure(version): profile = get_profile_from_context() config = ProfileConfigProvider(profile).get_config() if profile else get_config() new_config = config or DatabricksConfig.empty() new_config.jobs_api_version = version update_and_persist_config(profile, new_config)