Skip to content

Commit 6e4de9d

Browse files
authored
fix(dms): auto-create test repositories for integration tests in dms (#162)
1 parent 9e39c4c commit 6e4de9d

8 files changed

Lines changed: 60 additions & 10 deletions

File tree

docs/INTEGRATION_TESTS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ CLOUD_SDK_CFG_DATA_ANONYMIZATION_DEFAULT_DESTINATION_NAME=your-client-certificat
9696

9797
The destination must be configured with `ClientCertificateAuthentication` and reference a certificate bundle containing the client certificate and private key.
9898

99+
### DMS Integration Tests
100+
101+
For DMS (Document Management Service) integration tests, configure the following variables in `.env_integration_tests`:
102+
103+
```bash
104+
# DMS Configuration
105+
CLOUD_SDK_CFG_SDM_DEFAULT_URI=https://your-sdm-api-uri-here
106+
CLOUD_SDK_CFG_SDM_DEFAULT_UAA='{"url":"https://your-auth-url","clientid":"your-client-id","clientsecret":"your-client-secret","identityzone":"your-identity-zone"}'
107+
```
108+
109+
**Note**: The test fixture automatically onboards test repositories (standard and version-enabled) at session start and cleans them up on teardown. No pre-existing repositories are required.
110+
99111
### ADMS Integration Tests
100112

101113
For ADMS (Advanced Document Management Service) integration tests, configure the following variables in `.env_integration_tests`:
@@ -145,6 +157,7 @@ uv run pytest tests/core/integration/auditlog -v
145157
uv run pytest tests/core/integration/data_anonymization -v
146158
uv run pytest tests/objectstore/integration/ -v
147159
uv run pytest tests/destination/integration/ -v
160+
uv run pytest tests/dms/integration/ -v
148161
uv run pytest tests/agent_memory/integration/ -v
149162
uv run pytest tests/adms/integration/ -v
150163
uv run pytest tests/agentgateway/integration/ -v

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.26.0"
3+
version = "0.26.1"
44
description = "SAP Cloud SDK for Python"
55
readme = "README.md"
66
license = "Apache-2.0"

src/sap_cloud_sdk/dms/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ def __init__(
110110
read_timeout=read_timeout,
111111
)
112112
self._telemetry_source: Optional[Module] = None
113-
logger.debug(
114-
"DMSClient initialized for instance '%s'", credentials.instance_name
115-
)
113+
logger.debug("DMSClient initialized")
116114

117115
@record_metrics(Module.DMS, Operation.DMS_ONBOARD_REPOSITORY)
118116
def onboard_repository(

src/sap_cloud_sdk/dms/config.py

Lines changed: 1 addition & 3 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

@@ -91,7 +90,6 @@ def to_credentials(self) -> DMSCredentials:
9190
token_url = uaa_data["url"].rstrip("/") + "/oauth/token"
9291

9392
return DMSCredentials(
94-
instance_name=self.instance_name,
9593
uri=self.uri,
9694
client_id=uaa_data["clientid"],
9795
client_secret=uaa_data["clientsecret"],
@@ -114,7 +112,7 @@ def load_sdm_config_from_env_or_mount(instance: Optional[str] = None) -> DMSCred
114112
"""
115113
inst = instance or "default"
116114
binding = BindingData(
117-
uri="", uaa="", instance_name=""
115+
uri="", uaa=""
118116
) # Initialize with empty values; will be populated by resolver
119117

120118
try:

src/sap_cloud_sdk/dms/model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def _to_dict_drop_none(obj: Any) -> dict[str, Any]:
3030
class DMSCredentials:
3131
"""Credentials for authenticating with the DMS service."""
3232

33-
instance_name: str
3433
uri: str
3534
client_id: str
3635
client_secret: str

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"

tests/dms/unit/test_client_admin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def client():
7272
mock_http = Mock()
7373
MockHttp.return_value = mock_http
7474
creds = DMSCredentials(
75-
instance_name="test-instance",
7675
uri="https://api.example.com",
7776
client_id="test-client",
7877
client_secret="test-secret",

tests/dms/unit/test_client_cmis.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def _mock_response(data):
100100
def client():
101101
"""Create a DMSClient with a mocked HttpInvoker."""
102102
creds = DMSCredentials(
103-
instance_name="test-instance",
104103
uri="https://api.example.com",
105104
client_id="test-client",
106105
client_secret="test-secret",

0 commit comments

Comments
 (0)