Skip to content

Commit 0312d90

Browse files
committed
created fixture clear_cache for clear cache before tests and created fixture zen_api_key for check api_key and get from env and configured fixture scopes
1 parent daf38ef commit 0312d90

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

tests/conftest.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
import os
22

33
import pytest
4+
import httpx
45
from openai import OpenAI
56

67
from zenguard.zenguard import Credentials, SupportedLLMs, ZenGuard, ZenGuardConfig
78

89

9-
@pytest.fixture(scope="session", autouse=True)
10-
def zenguard():
10+
@pytest.fixture(scope="session")
11+
def zen_api_key():
1112
api_key = os.environ.get("ZEN_API_KEY")
1213
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
1515

1616

1717
@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+
2130

31+
@pytest.fixture(scope="module")
32+
def zenguard_openai(zen_api_key):
2233
openai_key = os.environ.get("OPENAI_API_KEY")
2334
assert openai_key, "OPENAI_API_KEY is not set"
2435

2536
openai_client = OpenAI(api_key=openai_key)
2637
config = ZenGuardConfig(
27-
credentials=Credentials(api_key=api_key),
38+
credentials=Credentials(api_key=zen_api_key),
2839
ai_client=openai_client,
2940
llm=SupportedLLMs.CHATGPT,
3041
)

0 commit comments

Comments
 (0)