Skip to content

Commit a3f0a3c

Browse files
committed
Update test_bedrock_guardrails.py
1 parent 9119184 commit a3f0a3c

File tree

1 file changed

+0
-137
lines changed

1 file changed

+0
-137
lines changed

tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,143 +1050,6 @@ async def test_bedrock_guardrail_parameter_takes_precedence_over_env(monkeypatch
10501050

10511051
print(f"Parameter precedence test passed. URL: {prepped_request.url}")
10521052

1053-
1054-
@pytest.mark.asyncio
1055-
async def test_bedrock_guardrail_respects_custom_runtime_endpoint(monkeypatch):
1056-
"""Test that BedrockGuardrail respects aws_bedrock_runtime_endpoint when set"""
1057-
1058-
# Clear any existing environment variable to ensure clean test
1059-
monkeypatch.delenv("AWS_BEDROCK_RUNTIME_ENDPOINT", raising=False)
1060-
1061-
# Create guardrail with custom runtime endpoint
1062-
custom_endpoint = "https://custom-bedrock.example.com"
1063-
guardrail = BedrockGuardrail(
1064-
guardrailIdentifier="test-guardrail",
1065-
guardrailVersion="DRAFT",
1066-
aws_bedrock_runtime_endpoint=custom_endpoint,
1067-
)
1068-
1069-
# Mock credentials
1070-
mock_credentials = MagicMock()
1071-
mock_credentials.access_key = "test-access-key"
1072-
mock_credentials.secret_key = "test-secret-key"
1073-
mock_credentials.token = None
1074-
1075-
# Test data
1076-
data = {"source": "INPUT", "content": [{"text": {"text": "test content"}}]}
1077-
optional_params = {}
1078-
aws_region_name = "us-east-1"
1079-
1080-
# Mock the _load_credentials method to avoid actual AWS credential loading
1081-
with patch.object(
1082-
guardrail, "_load_credentials", return_value=(mock_credentials, aws_region_name)
1083-
):
1084-
# Call _prepare_request which internally calls get_runtime_endpoint
1085-
prepped_request = guardrail._prepare_request(
1086-
credentials=mock_credentials,
1087-
data=data,
1088-
optional_params=optional_params,
1089-
aws_region_name=aws_region_name,
1090-
)
1091-
1092-
# Verify that the custom endpoint is used in the URL
1093-
expected_url = f"{custom_endpoint}/guardrail/{guardrail.guardrailIdentifier}/version/{guardrail.guardrailVersion}/apply"
1094-
assert (
1095-
prepped_request.url == expected_url
1096-
), f"Expected URL to contain custom endpoint. Got: {prepped_request.url}"
1097-
1098-
print(f"Custom runtime endpoint test passed. URL: {prepped_request.url}")
1099-
1100-
1101-
@pytest.mark.asyncio
1102-
async def test_bedrock_guardrail_respects_env_runtime_endpoint(monkeypatch):
1103-
"""Test that BedrockGuardrail respects AWS_BEDROCK_RUNTIME_ENDPOINT environment variable"""
1104-
1105-
custom_endpoint = "https://env-bedrock.example.com"
1106-
1107-
# Set the environment variable
1108-
monkeypatch.setenv("AWS_BEDROCK_RUNTIME_ENDPOINT", custom_endpoint)
1109-
1110-
# Create guardrail without explicit aws_bedrock_runtime_endpoint
1111-
guardrail = BedrockGuardrail(
1112-
guardrailIdentifier="test-guardrail", guardrailVersion="DRAFT"
1113-
)
1114-
1115-
# Mock credentials
1116-
mock_credentials = MagicMock()
1117-
mock_credentials.access_key = "test-access-key"
1118-
mock_credentials.secret_key = "test-secret-key"
1119-
mock_credentials.token = None
1120-
1121-
# Test data
1122-
data = {"source": "INPUT", "content": [{"text": {"text": "test content"}}]}
1123-
optional_params = {}
1124-
aws_region_name = "us-east-1"
1125-
1126-
# Mock the _load_credentials method
1127-
with patch.object(
1128-
guardrail, "_load_credentials", return_value=(mock_credentials, aws_region_name)
1129-
):
1130-
# Call _prepare_request which internally calls get_runtime_endpoint
1131-
prepped_request = guardrail._prepare_request(
1132-
credentials=mock_credentials,
1133-
data=data,
1134-
optional_params=optional_params,
1135-
aws_region_name=aws_region_name,
1136-
)
1137-
1138-
# Verify that the custom endpoint from environment is used in the URL
1139-
expected_url = f"{custom_endpoint}/guardrail/{guardrail.guardrailIdentifier}/version/{guardrail.guardrailVersion}/apply"
1140-
assert (
1141-
prepped_request.url == expected_url
1142-
), f"Expected URL to contain env endpoint. Got: {prepped_request.url}"
1143-
1144-
print(f"Environment runtime endpoint test passed. URL: {prepped_request.url}")
1145-
1146-
1147-
@pytest.mark.asyncio
1148-
async def test_bedrock_guardrail_uses_default_endpoint_when_no_custom_set(monkeypatch):
1149-
"""Test that BedrockGuardrail uses default endpoint when no custom endpoint is set"""
1150-
1151-
# Ensure no environment variable is set
1152-
monkeypatch.delenv("AWS_BEDROCK_RUNTIME_ENDPOINT", raising=False)
1153-
1154-
# Create guardrail without any custom endpoint
1155-
guardrail = BedrockGuardrail(
1156-
guardrailIdentifier="test-guardrail", guardrailVersion="DRAFT"
1157-
)
1158-
1159-
# Mock credentials
1160-
mock_credentials = MagicMock()
1161-
mock_credentials.access_key = "test-access-key"
1162-
mock_credentials.secret_key = "test-secret-key"
1163-
mock_credentials.token = None
1164-
1165-
# Test data
1166-
data = {"source": "INPUT", "content": [{"text": {"text": "test content"}}]}
1167-
optional_params = {}
1168-
aws_region_name = "us-west-2"
1169-
1170-
# Mock the _load_credentials method
1171-
with patch.object(
1172-
guardrail, "_load_credentials", return_value=(mock_credentials, aws_region_name)
1173-
):
1174-
# Call _prepare_request which internally calls get_runtime_endpoint
1175-
prepped_request = guardrail._prepare_request(
1176-
credentials=mock_credentials,
1177-
data=data,
1178-
optional_params=optional_params,
1179-
aws_region_name=aws_region_name,
1180-
)
1181-
1182-
# Verify that the default endpoint is used
1183-
expected_url = f"https://bedrock-runtime.{aws_region_name}.amazonaws.com/guardrail/{guardrail.guardrailIdentifier}/version/{guardrail.guardrailVersion}/apply"
1184-
assert (
1185-
prepped_request.url == expected_url
1186-
), f"Expected default URL. Got: {prepped_request.url}"
1187-
1188-
print(f"Default endpoint test passed. URL: {prepped_request.url}")
1189-
11901053
@pytest.mark.asyncio
11911054
async def test_bedrock_guardrail_200_with_exception_in_output_raises_and_logs_failure():
11921055
"""

0 commit comments

Comments
 (0)