Skip to content

Commit e69a895

Browse files
committed
test_apply_default_settings
1 parent 45a9af8 commit e69a895

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/router_unit_tests/test_router_endpoints.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,53 @@ async def test_init_vector_store_api_endpoints():
665665
custom_llm_provider="openai"
666666
)
667667

668+
669+
def test_apply_default_settings():
670+
"""
671+
Test the apply_default_settings method.
672+
673+
This test verifies that apply_default_settings correctly initializes
674+
default pre-call checks and doesn't modify existing router state.
675+
"""
676+
# Test with fresh router
677+
router = Router()
678+
initial_optional_callbacks = router.optional_callbacks
679+
680+
# Test that the method runs without error
681+
result = router.apply_default_settings()
682+
683+
# Verify method returns None as expected
684+
assert result is None
685+
686+
# Verify that optional_callbacks remains None if it was initially None
687+
# (since default_pre_call_checks is an empty list)
688+
assert router.optional_callbacks == initial_optional_callbacks
689+
690+
# Test with router that already has some optional_callbacks
691+
router_with_callbacks = Router()
692+
mock_callback = MagicMock()
693+
router_with_callbacks.optional_callbacks = [mock_callback]
694+
695+
# Apply default settings
696+
result = router_with_callbacks.apply_default_settings()
697+
698+
# Verify method returns None
699+
assert result is None
700+
701+
# Verify existing callbacks are preserved (since we're adding empty list)
702+
assert mock_callback in router_with_callbacks.optional_callbacks
703+
704+
# Test that the method is called during router initialization
705+
with patch.object(Router, 'apply_default_settings') as mock_apply:
706+
Router()
707+
mock_apply.assert_called_once()
708+
709+
# Test with mocked add_optional_pre_call_checks to verify internal call
710+
router_test = Router()
711+
with patch.object(router_test, 'add_optional_pre_call_checks') as mock_add_checks:
712+
router_test.apply_default_settings()
713+
714+
# Verify add_optional_pre_call_checks was called with empty list
715+
mock_add_checks.assert_called_once_with([])
716+
717+

0 commit comments

Comments
 (0)