mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-04 01:48:57 +00:00
* test: add __init__.py files * refactor: rename test folder to avoid naming conflict * test: update workflows * test: update tests * test: update imports * test: update tests * test: remove unused import * ci(test-litellm.yml): add pytest retry to github workflow * test: fix test
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(
|
|
0, os.path.abspath("../../..")
|
|
) # Adds the parent directory to the system path
|
|
|
|
from litellm.proxy.guardrails.guardrail_registry import InMemoryGuardrailHandler
|
|
from litellm.types.guardrails import SupportedGuardrailIntegrations
|
|
|
|
|
|
def test_initialize_presidio_guardrail():
|
|
"""
|
|
Test that initialize_guardrail correctly uses registered initializers
|
|
for presidio guardrail
|
|
"""
|
|
# Setup test data for a non-custom guardrail (using Presidio as an example)
|
|
test_guardrail = {
|
|
"guardrail_name": "test_presidio_guardrail",
|
|
"litellm_params": {
|
|
"guardrail": SupportedGuardrailIntegrations.PRESIDIO.value,
|
|
"mode": "pre_call",
|
|
"presidio_analyzer_api_base": "https://fakelink.com/v1/presidio/analyze",
|
|
"presidio_anonymizer_api_base": "https://fakelink.com/v1/presidio/anonymize",
|
|
},
|
|
}
|
|
|
|
# Call the initialize_guardrail method
|
|
guardrail_handler = InMemoryGuardrailHandler()
|
|
result = guardrail_handler.initialize_guardrail(
|
|
guardrail=test_guardrail,
|
|
)
|
|
|
|
assert result["guardrail_name"] == "test_presidio_guardrail"
|
|
assert (
|
|
result["litellm_params"].guardrail
|
|
== SupportedGuardrailIntegrations.PRESIDIO.value
|
|
)
|
|
assert result["litellm_params"].mode == "pre_call"
|