Skip to content

Commit

Permalink
fix: app service regression in 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-w committed Aug 19, 2024
1 parent 16abec4 commit 3ada43c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ def get_config_dict(profile: str | None = None, env: bool = True) -> dict | None
# decide which will be the token provider used
token_provider_name = _find_token_provider(profile_credentials) or _find_token_provider(default_credentials)
if not token_provider_name:
raise MISSING_TP_ERROR
if "APP_SERVICE_TS" in os.environ:
token_provider_name = "app_service" # noqa: S105
else:
raise MISSING_TP_ERROR
# merge the profile config with the non-prefixed config
return_config = {}
merged_config = merge_dicts(config.get("config", {}), profile_config.get("config", {}))
Expand Down
57 changes: 39 additions & 18 deletions tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,33 @@ def test_get_config_dict(mock_config_location: dict[Path, None]):
assert config.get_config_dict()["credentials"]["oauth"]["scopes"] == "one:scope,two:scope"


def test_parse_credentials_config(mock_config_location):
with pytest.raises(MissingCredentialsConfigError):
config.parse_credentials_config({})
def test_parse_credentials_config(mock_config_location: dict[Path, None]):
path_list = list(mock_config_location)
user_config = path_list[1]

user_config.write_text("")
with pytest.raises(MissingCredentialsConfigError):
config.parse_credentials_config({"credentials": {}})
config.parse_credentials_config(config.get_config_dict())

user_config.write_text("""
[credentials]
""")
with pytest.raises(MissingFoundryHostError):
config.parse_credentials_config(config.get_config_dict())

user_config.write_text("""
[credentials]
no_domain = 1
""")
with pytest.raises(MissingFoundryHostError):
config.parse_credentials_config({"credentials": {"no_domain": 1}})
config.parse_credentials_config(config.get_config_dict())

user_config.write_text("""
[credentials]
domain = "example.com"
""")
with pytest.raises(TokenProviderConfigError, match="To authenticate with Foundry you need a TokenProvider"):
config.parse_credentials_config({"credentials": {"domain": "example.com"}})
config.parse_credentials_config(config.get_config_dict())
with pytest.raises(
TokenProviderConfigError,
match="The token provider implementation example does not exist",
Expand All @@ -95,32 +110,38 @@ def test_parse_credentials_config(mock_config_location):
with mock.patch("foundry_dev_tools.config.config.check_init") as check_init_mock:
# return the dict 'kwargs'
check_init_mock.side_effect = lambda *args, **kwargs: args[2] # noqa: ARG005
config.parse_credentials_config(
{"credentials": {"domain": "example.com", "jwt": "test"}},
)
user_config.write_text("""
[credentials]
domain = "example.com"
jwt = "test"
""")
config.parse_credentials_config(config.get_config_dict())
check_init_mock.assert_called_with(
JWTTokenProvider,
"credentials",
{"host": Host("example.com"), "jwt": "test"},
)
config.parse_credentials_config(
{
"credentials": {
"domain": "example.com",
"oauth": {"client_id": "test"},
},
},
)
user_config.write_text("""
[credentials]
domain = "example.com"
oauth = {client_id = "test"}
""")
config.parse_credentials_config(config.get_config_dict())
check_init_mock.assert_called_with(
OAuthTokenProvider,
"credentials",
{"host": Host("example.com"), "client_id": "test"},
)

user_config.write_text("""
[credentials]
domain = "example.com"
""")
with (
mock.patch.dict(os.environ, {"APP_SERVICE_TS": "1"}),
pytest.raises(
FoundryConfigError,
match="Could not get Foundry token from flask/dash/streamlit headers.",
),
):
config.parse_credentials_config({"credentials": {"domain": "example.com"}})
config.parse_credentials_config(config.get_config_dict())

0 comments on commit 3ada43c

Please sign in to comment.