mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
A name bound twice keeps only the second binding. In `tests/` that is nearly always a repeated import, harmless but misleading, and the same rule is what catches the cases that are not harmless: a local that shadows an import the module still calls, and a second `def test_x` that quietly replaces the first. 311 of the 344 sites were repeated imports and came out with ruff's own fix. The remaining 33 needed a decision. Four modules imported a name they never used because a local definition below already shadowed it. Two comprehensions bound `call` over `unittest.mock.call`, which those modules import and use. One test rebound the two module handles its nested reload closure had captured. One class attribute shadowed an unused `status` import. The load-test fixtures move to a conftest, which is how pytest is meant to share them, so the test module no longer imports three fixture names it never calls. The nine `prisma_client` parameters keep a narrow `noqa`: pytest resolves that fixture by name before the body runs, so the parameter never shadows anything.
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
import os
|
|
import sys
|
|
|
|
import pytest
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
import io
|
|
|
|
sys.path.insert(
|
|
0, os.path.abspath("../..")
|
|
) # Adds-the parent directory to the system path
|
|
|
|
from litellm.proxy import proxy_server
|
|
from litellm.proxy.common_utils.encrypt_decrypt_utils import (
|
|
decrypt_value_helper,
|
|
encrypt_value_helper,
|
|
)
|
|
|
|
|
|
def test_encrypt_decrypt_with_master_key():
|
|
setattr(proxy_server, "master_key", "sk-1234")
|
|
assert decrypt_value_helper(encrypt_value_helper("test"), key="test_key") == "test"
|
|
assert decrypt_value_helper(encrypt_value_helper(10), key="test_key") == 10
|
|
assert decrypt_value_helper(encrypt_value_helper(True), key="test_key") is True
|
|
assert decrypt_value_helper(encrypt_value_helper(None), key="test_key") is None
|
|
assert decrypt_value_helper(encrypt_value_helper({"rpm": 10}), key="test_key") == {
|
|
"rpm": 10
|
|
}
|
|
|
|
# encryption should actually occur for strings
|
|
assert encrypt_value_helper("test") != "test"
|
|
|
|
|
|
def test_encrypt_decrypt_with_salt_key():
|
|
os.environ["LITELLM_SALT_KEY"] = "sk-salt-key2222"
|
|
print(f"LITELLM_SALT_KEY: {os.environ['LITELLM_SALT_KEY']}")
|
|
assert decrypt_value_helper(encrypt_value_helper("test"), key="test_key") == "test"
|
|
assert decrypt_value_helper(encrypt_value_helper(10), key="test_key") == 10
|
|
assert decrypt_value_helper(encrypt_value_helper(True), key="test_key") is True
|
|
assert decrypt_value_helper(encrypt_value_helper(None), key="test_key") is None
|
|
assert decrypt_value_helper(encrypt_value_helper({"rpm": 10}), key="test_key") == {
|
|
"rpm": 10
|
|
}
|
|
|
|
# encryption should actually occur for strings
|
|
assert encrypt_value_helper("test") != "test"
|
|
|
|
os.environ.pop("LITELLM_SALT_KEY", None)
|