Skip to content

Commit da70d1c

Browse files
fix(adms): add use_admin_service parameter to async get_status
The async _AsyncJobApi.get_status was hard-coded to DocumentService, so async callers polling a DELETE_USER_DATA job (started against AdminService via start_delete_user_data) hit the wrong path and got a 404. Sync sibling already accepted use_admin_service: bool — restore parity. Add an async unit test that asserts AdminService routing when use_admin_service=True.
1 parent ec9a502 commit da70d1c

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/sap_cloud_sdk/adms/client.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,10 +1454,25 @@ async def start_delete_user_data(
14541454
return JobOutput.from_dict(resp.json())
14551455

14561456
@record_metrics(Module.ADMS, Operation.ADMS_JOBS_GET_STATUS)
1457-
async def get_status(self, job_id: str) -> JobOutput:
1458-
"""Poll job status (async) — call until :meth:`JobOutput.job_status.is_terminal`."""
1457+
async def get_status(
1458+
self,
1459+
job_id: str,
1460+
*,
1461+
use_admin_service: bool = False,
1462+
) -> JobOutput:
1463+
"""Poll the status of a running job (async).
1464+
1465+
Args:
1466+
job_id: The ``job_id`` from :meth:`start_zip_download` or
1467+
:meth:`start_delete_user_data`.
1468+
use_admin_service: Set ``True`` when polling a ``DELETE_USER_DATA`` job.
1469+
1470+
Returns:
1471+
Current :class:`~sap_cloud_sdk.adms._models.JobOutput`.
1472+
"""
1473+
service = _ADMIN_SERVICE_PATH if use_admin_service else _SERVICE_PATH
14591474
path = f"JobStatus(JobID='{job_id}')"
1460-
resp = await self._http.get(path, service_base=_SERVICE_PATH)
1475+
resp = await self._http.get(path, service_base=service)
14611476
return JobOutput.from_dict(resp.json())
14621477

14631478

tests/adms/unit/test_client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,27 @@ async def test_get_status(self, config):
524524
assert output.job_id == "job-abc"
525525
assert output.job_status == JobStatus.IN_PROGRESS
526526

527+
@pytest.mark.asyncio
528+
async def test_get_status_admin_service(self, config):
529+
"""``use_admin_service=True`` must route through AdminService for DELETE_USER_DATA polling."""
530+
fetcher = _make_token_fetcher(config)
531+
mock_client = AsyncMock(spec=httpx.AsyncClient)
532+
mock_client.request.return_value = _make_httpx_response(200, {
533+
"JobID": "job-del",
534+
"JobStatus": "COMPLETED",
535+
})
536+
537+
http = AsyncAdmsHttp(config=config, token_fetcher=fetcher, client=mock_client)
538+
http._csrf_tokens = {"": "x"}
539+
540+
from sap_cloud_sdk.adms.client import _AsyncJobApi as _AsyncJobApi
541+
api = _AsyncJobApi(http)
542+
543+
await api.get_status("job-del", use_admin_service=True)
544+
545+
called_url = mock_client.request.call_args.kwargs["url"]
546+
assert "AdminService" in str(called_url)
547+
527548

528549
# ── _DocumentApi (sync) ────────────────────────────────────────────────────────
529550

0 commit comments

Comments
 (0)