diff --git a/tests/router_unit_tests/test_router_endpoints.py b/tests/router_unit_tests/test_router_endpoints.py index de1d22d5a8..0b60d5b26f 100644 --- a/tests/router_unit_tests/test_router_endpoints.py +++ b/tests/router_unit_tests/test_router_endpoints.py @@ -665,3 +665,53 @@ async def test_init_vector_store_api_endpoints(): custom_llm_provider="openai" ) + +def test_apply_default_settings(): + """ + Test the apply_default_settings method. + + This test verifies that apply_default_settings correctly initializes + default pre-call checks and doesn't modify existing router state. + """ + # Test with fresh router + router = Router() + initial_optional_callbacks = router.optional_callbacks + + # Test that the method runs without error + result = router.apply_default_settings() + + # Verify method returns None as expected + assert result is None + + # Verify that optional_callbacks remains None if it was initially None + # (since default_pre_call_checks is an empty list) + assert router.optional_callbacks == initial_optional_callbacks + + # Test with router that already has some optional_callbacks + router_with_callbacks = Router() + mock_callback = MagicMock() + router_with_callbacks.optional_callbacks = [mock_callback] + + # Apply default settings + result = router_with_callbacks.apply_default_settings() + + # Verify method returns None + assert result is None + + # Verify existing callbacks are preserved (since we're adding empty list) + assert mock_callback in router_with_callbacks.optional_callbacks + + # Test that the method is called during router initialization + with patch.object(Router, 'apply_default_settings') as mock_apply: + Router() + mock_apply.assert_called_once() + + # Test with mocked add_optional_pre_call_checks to verify internal call + router_test = Router() + with patch.object(router_test, 'add_optional_pre_call_checks') as mock_add_checks: + router_test.apply_default_settings() + + # Verify add_optional_pre_call_checks was called with empty list + mock_add_checks.assert_called_once_with([]) + +