Skip to content

Commit 05a7213

Browse files
authored
fix: instance name usage on set ai core config (#26)
1 parent d907b23 commit 05a7213

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sap-cloud-sdk"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "SAP Cloud SDK for Python"
55
readme = "README.md"
66
license = "Apache-2.0"

src/sap_cloud_sdk/aicore/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ def set_aicore_config(instance_name: str = "aicore-instance") -> None:
110110
- serviceurls (JSON with AI_API_URL) -> AICORE_BASE_URL
111111
"""
112112
# Load secrets
113-
client_id = _get_secret("AICORE_CLIENT_ID", "clientid")
114-
client_secret = _get_secret("AICORE_CLIENT_SECRET", "clientsecret")
115-
auth_url = _get_secret("AICORE_AUTH_URL", "url")
113+
client_id = _get_secret("AICORE_CLIENT_ID", "clientid", instance_name=instance_name)
114+
client_secret = _get_secret(
115+
"AICORE_CLIENT_SECRET", "clientsecret", instance_name=instance_name
116+
)
117+
auth_url = _get_secret("AICORE_AUTH_URL", "url", instance_name=instance_name)
116118
base_url = _get_aicore_base_url(instance_name)
117-
resource_group = _get_secret("AICORE_RESOURCE_GROUP", default="default")
119+
resource_group = _get_secret(
120+
"AICORE_RESOURCE_GROUP", default="default", instance_name=instance_name
121+
)
118122

119123
# Ensure AICORE_AUTH_URL has /oauth/token suffix
120124
if auth_url and not auth_url.endswith("/oauth/token"):

tests/aicore/unit/test_aicore.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,15 @@ def test_set_config_custom_instance_name(self):
526526

527527
set_aicore_config(instance_name=instance_name)
528528

529-
# Verify instance_name was passed to _get_secret calls
530-
# The _get_secret function is called without instance_name parameter
531-
# because set_aicore_config doesn't pass it (it uses default)
532-
# So we just verify _get_base_url received the instance_name
529+
# Verify instance_name was passed to _get_aicore_base_url
533530
mock_get_base_url.assert_called_with(instance_name)
534531

532+
# Verify instance_name was passed to all _get_secret calls
533+
for c in mock_get_secret.call_args_list:
534+
assert c.kwargs.get("instance_name") == instance_name, (
535+
f"_get_secret call for {c.args[0]} missing instance_name={instance_name}"
536+
)
537+
535538
def test_set_config_calls_get_secret_with_correct_parameters(self):
536539
"""Test that _get_secret is called with correct parameters for each secret."""
537540
with patch("sap_cloud_sdk.aicore._get_secret") as mock_get_secret, patch(
@@ -542,22 +545,21 @@ def test_set_config_calls_get_secret_with_correct_parameters(self):
542545

543546
set_aicore_config()
544547

545-
# Verify _get_secret was called with correct parameters
546-
calls = mock_get_secret.call_args_list
547-
assert any(
548-
call[0][0] == "AICORE_CLIENT_ID" and call[0][1] == "clientid"
549-
for call in calls
548+
default_instance = "aicore-instance"
549+
# Verify _get_secret was called with correct parameters including instance_name
550+
mock_get_secret.assert_any_call(
551+
"AICORE_CLIENT_ID", "clientid", instance_name=default_instance
550552
)
551-
assert any(
552-
call[0][0] == "AICORE_CLIENT_SECRET" and call[0][1] == "clientsecret"
553-
for call in calls
553+
mock_get_secret.assert_any_call(
554+
"AICORE_CLIENT_SECRET", "clientsecret", instance_name=default_instance
554555
)
555-
assert any(
556-
call[0][0] == "AICORE_AUTH_URL" and call[0][1] == "url" for call in calls
556+
mock_get_secret.assert_any_call(
557+
"AICORE_AUTH_URL", "url", instance_name=default_instance
557558
)
558-
assert any(
559-
call[0][0] == "AICORE_RESOURCE_GROUP" and call[1].get("default") == "default"
560-
for call in calls
559+
mock_get_secret.assert_any_call(
560+
"AICORE_RESOURCE_GROUP",
561+
default="default",
562+
instance_name=default_instance,
561563
)
562564

563565
def test_set_config_logs_configuration(self):

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)