Skip to content

Commit ced9539

Browse files
committed
fix(cbc): address CI failures — ruff format, ty errors, telemetry counts, version bump
- Bump version to 0.54.0 (required by CI for src/ changes) - Fix ruff format violations in _models.py and client.py - Fix ty errors: conftest fixture return type CBCClient, test_models assert-not-None before .version - Update test_module (15→16) and test_operation (161→163) counts for CBC module/operations
1 parent fd0e048 commit ced9539

9 files changed

Lines changed: 51 additions & 28 deletions

File tree

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

‎src/sap_cloud_sdk/cbc/_models.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class Entities(_FrozenModel):
132132
items: list[Entity]
133133

134134

135-
136135
class EntityContent:
137136
"""Configuration content for an entity.
138137
@@ -231,7 +230,11 @@ def get_config_object(self, config_object_id: str) -> ConfigObject | None:
231230
Matching :class:`ConfigObject`, or ``None`` if not found.
232231
"""
233232
return next(
234-
(co for co in self.config_objects if co.config_object_id == config_object_id),
233+
(
234+
co
235+
for co in self.config_objects
236+
if co.config_object_id == config_object_id
237+
),
235238
None,
236239
)
237240

‎src/sap_cloud_sdk/cbc/client.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class _ClientConfig:
106106
replace_subdomain: bool
107107

108108

109-
110109
# ---------------------------------------------------------------------------
111110
# DefaultClient
112111
# ---------------------------------------------------------------------------
@@ -230,9 +229,7 @@ def get_consumption_versions(
230229
tenant_context,
231230
f"/consumptionVersions?appTenantId={tenant_context.app_tenant_id}",
232231
)
233-
return ConsumptionVersions.model_validate(
234-
self._request("GET", url).json()
235-
)
232+
return ConsumptionVersions.model_validate(self._request("GET", url).json())
236233

237234
def _get_entities(
238235
self, tenant_context: TenantContext, consumption_version: str
@@ -365,7 +362,9 @@ def _fetch_entity_data(
365362
)
366363
response_data = self._request("GET", url).json()
367364

368-
api_meta = response_data.get("metadata", {}) if isinstance(response_data, dict) else {}
365+
api_meta = (
366+
response_data.get("metadata", {}) if isinstance(response_data, dict) else {}
367+
)
369368
raw_data = (
370369
response_data["items"]
371370
if isinstance(response_data, dict) and "items" in response_data
@@ -414,7 +413,9 @@ def _request(
414413
request_url=url,
415414
)
416415
error = ApiError.from_response(response.content)
417-
exc_class = CBCServerError if response.status_code >= 500 else CBCClientError
416+
exc_class = (
417+
CBCServerError if response.status_code >= 500 else CBCClientError
418+
)
418419
raise exc_class(error.message, code=error.code, http_context=ctx)
419420

420421
return response

‎tests/cbc/integration/conftest.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import pytest
2020

21-
from sap_cloud_sdk.cbc import DefaultClient, TenantContext, create_client
21+
from sap_cloud_sdk.cbc import CBCClient, TenantContext, create_client
2222
from sap_cloud_sdk.cbc.exceptions import CBCConfigError
2323

2424
ENV_CBC_TENANT_ID = "CLOUD_SDK_CBC_CBC_TENANT_ID"
@@ -37,7 +37,7 @@ def cbc_tenant() -> TenantContext:
3737

3838

3939
@pytest.fixture(scope="session")
40-
def cbc_client() -> DefaultClient:
40+
def cbc_client() -> CBCClient:
4141
try:
4242
return create_client()
4343
except CBCConfigError as exc:

‎tests/cbc/integration/test_e2e_bdd.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def test_configuration_has_config_objects():
5959
pass
6060

6161

62-
@scenario("cbc.feature", "Every entity within each config object has an entity_id and data")
62+
@scenario(
63+
"cbc.feature", "Every entity within each config object has an entity_id and data"
64+
)
6365
def test_every_entity_has_id_and_data():
6466
pass
6567

@@ -124,7 +126,9 @@ def assert_entity_ids(ctx: dict):
124126
config: ConfigData = ctx["config"]
125127
for co in config.config_objects:
126128
for ed in co.entities:
127-
assert ed.entity_id, f"entity_id missing in config_object={co.config_object_id!r}"
129+
assert ed.entity_id, (
130+
f"entity_id missing in config_object={co.config_object_id!r}"
131+
)
128132

129133

130134
@then("every entity data should be accessible as a list or object")

‎tests/cbc/unit/test_client.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
from sap_cloud_sdk.cbc.client import DefaultClient, create_client
1313
from sap_cloud_sdk.cbc.config import ENV_URL, ENV_CERT_PATH, ENV_KEY_PATH
14-
from sap_cloud_sdk.cbc.exceptions import CBCClientError, CBCConfigError, CBCNetworkError, CBCServerError
14+
from sap_cloud_sdk.cbc.exceptions import (
15+
CBCClientError,
16+
CBCConfigError,
17+
CBCNetworkError,
18+
CBCServerError,
19+
)
1520
from sap_cloud_sdk.cbc._models import (
1621
ConfigData,
1722
TenantContext,
@@ -42,7 +47,9 @@ def _mock_response(
4247
)
4348

4449

45-
def _make_client(base_url: str = "https://cbc.example.ondemand.com") -> tuple[DefaultClient, MagicMock]:
50+
def _make_client(
51+
base_url: str = "https://cbc.example.ondemand.com",
52+
) -> tuple[DefaultClient, MagicMock]:
4653
mock_http = MagicMock(spec=httpx.Client)
4754
client = DefaultClient(base_url=base_url, http_client=mock_http)
4855
return client, mock_http
@@ -194,9 +201,7 @@ def test_handles_flat_list_response(self):
194201
class TestGetConfiguration:
195202
def test_resolves_latest_version_when_none_given(self):
196203
client, mock_http = _make_client()
197-
versions_response = _mock_response(
198-
json_body={"items": [{"version": "v2"}]}
199-
)
204+
versions_response = _mock_response(json_body={"items": [{"version": "v2"}]})
200205
entities_response = _mock_response(json_body={"items": []})
201206
mock_http.request.side_effect = [versions_response, entities_response]
202207

@@ -216,7 +221,11 @@ def test_uses_explicit_consumption_version(self):
216221
entities_response = _mock_response(
217222
json_body={
218223
"items": [
219-
{"entityId": "i1", "entityName": "payment-mode", "configurationObjectId": "payment-config"}
224+
{
225+
"entityId": "i1",
226+
"entityName": "payment-mode",
227+
"configurationObjectId": "payment-config",
228+
}
220229
]
221230
}
222231
)

‎tests/cbc/unit/test_models.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def test_returns_latest_by_modified_date(self):
6868
self._version("v2", modified=t2),
6969
]
7070
)
71-
assert v.latest().version == "v2"
71+
result = v.latest()
72+
assert result is not None
73+
assert result.version == "v2"
7274

7375
def test_returns_latest_by_created_date_when_no_modified(self):
7476
t1 = datetime(2024, 1, 1, tzinfo=timezone.utc)
@@ -79,13 +81,15 @@ def test_returns_latest_by_created_date_when_no_modified(self):
7981
self._version("v2", created=t2),
8082
]
8183
)
82-
assert v.latest().version == "v2"
84+
result = v.latest()
85+
assert result is not None
86+
assert result.version == "v2"
8387

8488
def test_returns_last_item_when_no_dates(self):
85-
v = ConsumptionVersions(
86-
items=[self._version("v1"), self._version("v2")]
87-
)
88-
assert v.latest().version == "v2"
89+
v = ConsumptionVersions(items=[self._version("v1"), self._version("v2")])
90+
result = v.latest()
91+
assert result is not None
92+
assert result.version == "v2"
8993

9094

9195
# ---------------------------------------------------------------------------

‎tests/core/unit/telemetry/test_module.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ def test_module_in_collection(self):
5555
def test_all_modules_present(self):
5656
"""Test that all expected modules are present."""
5757
all_modules = list(Module)
58-
assert len(all_modules) == 15
58+
assert len(all_modules) == 16
5959
assert Module.ADMS in all_modules
60+
assert Module.CBC in all_modules
6061
assert Module.AGENT_MEMORY in all_modules
6162
assert Module.AGENTGATEWAY in all_modules
6263
assert Module.AICORE in all_modules

‎tests/core/unit/telemetry/test_operation.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,6 @@ def test_operation_count(self):
216216
all_operations = list(Operation)
217217
# 3 auditlog + 12 destination + 10 certificate + 10 fragment + 8 objectstore
218218
# + 2 extensibility + 7 aicore + 23 dms + 6 agentgateway + 13 agent_memory
219-
# + 5 data_anonymization + 52 adms + 6 print + 1 bootstrap + 3 output_management = 161
220-
assert len(all_operations) == 161
219+
# + 5 data_anonymization + 52 adms + 6 print + 1 bootstrap + 3 output_management
220+
# + 2 cbc = 163
221+
assert len(all_operations) == 163

0 commit comments

Comments
 (0)