Skip to content

Commit 314fbb3

Browse files
committed
refactor: update tests
1 parent 35beb71 commit 314fbb3

1 file changed

Lines changed: 48 additions & 9 deletions

File tree

tests/core/unit/auditlog_ng/unit/test_create_client.py

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,38 @@ def test_destination_fragment_name_forwarded(self, mock_provider_cls, mock_expor
294294
insecure=True,
295295
)
296296

297+
from sap_cloud_sdk.destination import ConsumptionLevel
298+
297299
call_kwargs = dest_client.get_destination.call_args.kwargs
298300
options = call_kwargs.get("options")
299301
assert options is not None
300302
assert options.fragment_name == "prod"
303+
assert options.fragment_level == ConsumptionLevel.SUBACCOUNT
301304

302-
def test_destination_name_without_instance_and_fragment_falls_through_to_explicit_args_guard(
305+
def test_destination_name_alone_enters_destination_path(
303306
self, mock_provider_cls, mock_exporter_fn
304307
):
305-
"""When destination_instance or fragment_name is missing, the destination path
306-
is not entered and the explicit-args guard raises."""
307-
with pytest.raises(ValueError, match="endpoint, deployment_id, and namespace are required"):
308-
create_client(destination_name="my-audit-dest")
308+
"""destination_name alone enters the destination path (destination_instance
309+
defaults to 'default'); the explicit-args guard is NOT raised."""
310+
mock_provider = Mock()
311+
mock_provider.get_logger.return_value = Mock()
312+
mock_provider_cls.return_value = mock_provider
313+
314+
dest = _make_mock_destination()
315+
dest_client = MagicMock()
316+
dest_client.get_destination.return_value = dest
317+
318+
with patch(
319+
"sap_cloud_sdk.destination.create_client",
320+
return_value=dest_client,
321+
) as mock_dest_factory:
322+
client = create_client(
323+
destination_name="my-audit-dest",
324+
insecure=True,
325+
)
326+
327+
mock_dest_factory.assert_called_once_with(instance=None)
328+
assert isinstance(client, AuditClient)
309329

310330
def test_destination_name_without_fragment_uses_destination_path(
311331
self, mock_provider_cls, mock_exporter_fn
@@ -334,12 +354,31 @@ def test_destination_name_without_fragment_uses_destination_path(
334354
call_kwargs = dest_client.get_destination.call_args.kwargs
335355
assert call_kwargs.get("options") is None
336356

337-
def test_destination_name_without_instance_falls_through_to_explicit_args_guard(
357+
def test_destination_name_without_instance_uses_default_instance(
338358
self, mock_provider_cls, mock_exporter_fn
339359
):
340-
"""fragment_name alone (no destination_instance) still falls through."""
341-
with pytest.raises(ValueError, match="endpoint, deployment_id, and namespace are required"):
342-
create_client(destination_name="my-audit-dest", fragment_name="prod")
360+
"""destination_name with fragment_name but no destination_instance enters the
361+
destination path, calling _dest_create_client with instance=None."""
362+
mock_provider = Mock()
363+
mock_provider.get_logger.return_value = Mock()
364+
mock_provider_cls.return_value = mock_provider
365+
366+
dest = _make_mock_destination()
367+
dest_client = MagicMock()
368+
dest_client.get_destination.return_value = dest
369+
370+
with patch(
371+
"sap_cloud_sdk.destination.create_client",
372+
return_value=dest_client,
373+
) as mock_dest_factory:
374+
client = create_client(
375+
destination_name="my-audit-dest",
376+
fragment_name="prod",
377+
insecure=True,
378+
)
379+
380+
mock_dest_factory.assert_called_once_with(instance=None)
381+
assert isinstance(client, AuditClient)
343382

344383
# ------------------------------------------------------------------
345384
# deploymentRegion fallback

0 commit comments

Comments
 (0)