Files
dlt/tests/workspace/test_providers.py
rudolfix 06bc05848b (chore) adds hub extra (#3428)
* adds hub extra

* makes hub module more user friendly when hub not installed

* test and lint fixes

* adds plugin version check util function

* adds dlt-runtime to hub extra, minimal import tests

* bumps to dlthub 0.20.0 alpha

* lists pipelines with cli using the same functions as dashboard, dlt pipeline will list pipelines by default

* adds configured propfiles method on context so only profiles with configs or pipelines are listed

* adds list of locations that contained actual configs to provider interface

* improves workspace and profile commands

* test fixes

* fixes tests
2025-12-05 16:15:19 +01:00

38 lines
1.6 KiB
Python

import os
from pathlib import Path
from dlt._workspace.providers import ProfileSecretsTomlProvider
TESTS_CASES_DIR = os.path.join("tests", "workspace", "cases", "provider")
def test_secrets_toml() -> None:
provider = ProfileSecretsTomlProvider(os.path.join(TESTS_CASES_DIR, ".dlt"), "access")
# first access profile, global comes second
assert provider.locations == [
str(Path(TESTS_CASES_DIR).joinpath(".dlt/access.secrets.toml")),
str(Path(TESTS_CASES_DIR).joinpath(".dlt/secrets.toml")),
]
assert provider.present_locations == [
str(Path(TESTS_CASES_DIR).joinpath(".dlt/access.secrets.toml")),
str(Path(TESTS_CASES_DIR).joinpath(".dlt/secrets.toml")),
]
# overrides secrets.toml with profile
assert provider.get_value("api_key", str, None) == ("PASS", "api_key")
# still has secrets.toml keys
assert provider.get_value("log_level", str, None, "runtime") == ("WARNING", "runtime.log_level")
# dev profile will load just secrets.toml
provider = ProfileSecretsTomlProvider(os.path.join(TESTS_CASES_DIR, ".dlt"), "dev")
assert provider.get_value("api_key", str, None) == ("X", "api_key")
def test_secrets_not_present() -> None:
provider = ProfileSecretsTomlProvider(os.path.join(TESTS_CASES_DIR, ".dlt"), "unknown")
# first access profile, global comes second
assert provider.locations == [
str(Path(TESTS_CASES_DIR).joinpath(".dlt/unknown.secrets.toml")),
str(Path(TESTS_CASES_DIR).joinpath(".dlt/secrets.toml")),
]
assert provider.present_locations == [str(Path(TESTS_CASES_DIR).joinpath(".dlt/secrets.toml"))]