mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
test(rubrik): cover event_hook default coercion
Regression tests for the case where the upstream caller (initialize_guardrail) passes event_hook=None and the logger should still fall back to post_call, and the sanity case where an explicitly-set non-None event_hook is preserved.
This commit is contained in:
parent
12ebe8bebc
commit
a0b69aa54a
1 changed files with 18 additions and 0 deletions
|
|
@ -186,6 +186,24 @@ class TestInitialization:
|
|||
assert handler._flush_task is not None
|
||||
handler._flush_task.cancel()
|
||||
|
||||
def test_event_hook_defaults_to_post_call_when_none_passed(self, mock_env):
|
||||
"""`initialize_guardrail` always passes ``event_hook=litellm_params.mode``
|
||||
(which is ``None`` when the user omits ``mode``). The logger must coerce
|
||||
a None ``event_hook`` to ``post_call`` rather than leaving it as None,
|
||||
which would otherwise cause the guardrail to run on every event hook."""
|
||||
from litellm.types.guardrails import GuardrailEventHooks
|
||||
|
||||
with patch("asyncio.create_task", Mock()):
|
||||
handler = RubrikLogger(event_hook=None)
|
||||
assert handler.event_hook == GuardrailEventHooks.post_call
|
||||
|
||||
def test_explicit_event_hook_preserved(self, mock_env):
|
||||
from litellm.types.guardrails import GuardrailEventHooks
|
||||
|
||||
with patch("asyncio.create_task", Mock()):
|
||||
handler = RubrikLogger(event_hook=GuardrailEventHooks.pre_call)
|
||||
assert handler.event_hook == GuardrailEventHooks.pre_call
|
||||
|
||||
def test_headers_with_api_key(self, handler):
|
||||
assert handler._headers["Authorization"] == "Bearer test-api-key"
|
||||
assert handler._headers["Content-Type"] == "application/json"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue