Skip to content

Commit 224c018

Browse files
committed
fix(dms): remove instance_name from BindingData and auto-create test repositories
1 parent 9e39c4c commit 224c018

2 files changed

Lines changed: 51 additions & 5 deletions

File tree

src/sap_cloud_sdk/dms/config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class BindingData:
1919
uaa: JSON string containing XSUAA authentication credentials
2020
"""
2121

22-
instance_name: str
2322
uri: str
2423
uaa: str
2524

@@ -78,20 +77,23 @@ def _validate_uaa(self) -> None:
7877
f"UAA credentials missing required fields: {', '.join(sorted(missing_fields))}"
7978
)
8079

81-
def to_credentials(self) -> DMSCredentials:
80+
def to_credentials(self, instance_name: str) -> DMSCredentials:
8281
"""Convert the binding data to DMSCredentials.
8382
8483
Parses the UAA JSON and constructs a DMSCredentials object with the necessary information
8584
for authenticating and connecting to the DMS service.
8685
86+
Args:
87+
instance_name: The logical instance name for these credentials.
88+
8789
Returns:
8890
DMSCredentials: The credentials extracted from the binding data
8991
"""
9092
uaa_data: Dict[str, Any] = json.loads(self.uaa)
9193
token_url = uaa_data["url"].rstrip("/") + "/oauth/token"
9294

9395
return DMSCredentials(
94-
instance_name=self.instance_name,
96+
instance_name=instance_name,
9597
uri=self.uri,
9698
client_id=uaa_data["clientid"],
9799
client_secret=uaa_data["clientsecret"],
@@ -114,7 +116,7 @@ def load_sdm_config_from_env_or_mount(instance: Optional[str] = None) -> DMSCred
114116
"""
115117
inst = instance or "default"
116118
binding = BindingData(
117-
uri="", uaa="", instance_name=""
119+
uri="", uaa=""
118120
) # Initialize with empty values; will be populated by resolver
119121

120122
try:
@@ -129,7 +131,7 @@ def load_sdm_config_from_env_or_mount(instance: Optional[str] = None) -> DMSCred
129131
)
130132

131133
binding.validate()
132-
return binding.to_credentials()
134+
return binding.to_credentials(inst)
133135

134136
except Exception as e:
135137
# Rely on the central secret resolver to provide aggregated, generic guidance

tests/dms/integration/conftest.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
from sap_cloud_sdk.dms import create_client
2+
from sap_cloud_sdk.dms.model import InternalRepoRequest
23
import pytest
4+
import logging
35
from pathlib import Path
46
from dotenv import load_dotenv
57

8+
logger = logging.getLogger(__name__)
9+
10+
_SDK_TEST_REPO_PREFIX = "sdk-integration-test-"
11+
612

713
@pytest.fixture(scope="session")
814
def dms_client():
@@ -17,6 +23,44 @@ def dms_client():
1723
pytest.skip(f"DMS integration tests require credentials: {e}")
1824

1925

26+
@pytest.fixture(scope="session", autouse=True)
27+
def _setup_test_repositories(dms_client):
28+
"""Create test repositories for integration tests and clean up after.
29+
30+
Always onboards a standard and a version-enabled repository for the test
31+
session, then deletes them on teardown.
32+
"""
33+
created_repos = []
34+
35+
logger.info("Onboarding test repositories")
36+
repo = dms_client.onboard_repository(
37+
InternalRepoRequest(
38+
displayName=f"{_SDK_TEST_REPO_PREFIX}standard",
39+
description="Auto-created by SDK integration tests",
40+
)
41+
)
42+
created_repos.append(repo.id)
43+
44+
repo = dms_client.onboard_repository(
45+
InternalRepoRequest(
46+
displayName=f"{_SDK_TEST_REPO_PREFIX}versioned",
47+
description="Auto-created by SDK integration tests (versioning)",
48+
isVersionEnabled=True,
49+
)
50+
)
51+
created_repos.append(repo.id)
52+
53+
yield
54+
55+
# Cleanup: delete repositories we created
56+
for repo_id in created_repos:
57+
try:
58+
dms_client.delete_repository(repo_id)
59+
logger.info("Cleaned up test repository %s", repo_id)
60+
except Exception as e:
61+
logger.warning("Failed to clean up test repository %s: %s", repo_id, e)
62+
63+
2064
def _setup_cloud_mode():
2165
"""Common setup for cloud mode integration tests."""
2266
env_file = Path(__file__).parents[3] / ".env_integration_tests"

0 commit comments

Comments
 (0)