|
1 | 1 | import os |
2 | 2 |
|
3 | 3 | import pytest |
| 4 | +import httpx |
4 | 5 | from openai import OpenAI |
5 | 6 |
|
6 | 7 | from zenguard.zenguard import Credentials, SupportedLLMs, ZenGuard, ZenGuardConfig |
7 | 8 |
|
8 | 9 |
|
9 | | -@pytest.fixture(scope="session", autouse=True) |
10 | | -def zenguard(): |
| 10 | +@pytest.fixture(scope="session") |
| 11 | +def zen_api_key(): |
11 | 12 | api_key = os.environ.get("ZEN_API_KEY") |
12 | 13 | assert api_key, "ZEN_API_KEY is not set" |
13 | | - config = ZenGuardConfig(credentials=Credentials(api_key=api_key)) |
14 | | - return ZenGuard(config=config) |
| 14 | + return api_key |
15 | 15 |
|
16 | 16 |
|
17 | 17 | @pytest.fixture(scope="session", autouse=True) |
18 | | -def zenguard_openai(): |
19 | | - api_key = os.environ.get("ZEN_API_KEY") |
20 | | - assert api_key, "ZEN_API_KEY is not set" |
| 18 | +def clear_cache(zen_api_key): |
| 19 | + response = httpx.put( |
| 20 | + url="https://api.zenguard.ai/v1/cache/clear", headers={"x-api-key": zen_api_key} |
| 21 | + ) |
| 22 | + response.raise_for_status() |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture(scope="module") |
| 26 | +def zenguard(zen_api_key): |
| 27 | + config = ZenGuardConfig(credentials=Credentials(api_key=zen_api_key)) |
| 28 | + return ZenGuard(config=config) |
| 29 | + |
21 | 30 |
|
| 31 | +@pytest.fixture(scope="module") |
| 32 | +def zenguard_openai(zen_api_key): |
22 | 33 | openai_key = os.environ.get("OPENAI_API_KEY") |
23 | 34 | assert openai_key, "OPENAI_API_KEY is not set" |
24 | 35 |
|
25 | 36 | openai_client = OpenAI(api_key=openai_key) |
26 | 37 | config = ZenGuardConfig( |
27 | | - credentials=Credentials(api_key=api_key), |
| 38 | + credentials=Credentials(api_key=zen_api_key), |
28 | 39 | ai_client=openai_client, |
29 | 40 | llm=SupportedLLMs.CHATGPT, |
30 | 41 | ) |
|
0 commit comments