Skip to content

Commit 2453635

Browse files
committed
fix: use pytest and removed print statements
1 parent ed9ce8a commit 2453635

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

test_rate_limit.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import requests
22
import os
33
import time
4+
import logging
45
from dotenv import load_dotenv
56

67
load_dotenv()
8+
logger = logging.getLogger(__name__)
79
API_KEY = os.getenv("API_KEY")
810
HEADERS = {"X-API-KEY": API_KEY}
911
QUERY_URL = "http://127.0.0.1:8000/api/v1/query"
@@ -13,28 +15,25 @@ def test_limit():
1315
Tests the rate limit for the synchronous /query endpoint.
1416
"""
1517
if not API_KEY:
16-
print("Error: API_KEY not found in environment. Please set it in your .env file.")
18+
logger.error("Error: API_KEY not found in environment. Please set it in your .env file.")
1719
return
1820

19-
print("Sending 6 requests to /api/v1/query to test the 5/minute limit...")
21+
logger.info("Sending 6 requests to /api/v1/query to test the 5/minute limit...")
2022

2123
with requests.Session() as session:
2224
session.headers.update(HEADERS)
2325

2426
for i in range(1, 7):
2527
try:
2628
response = session.post(QUERY_URL, json={"question": f"test {i}"})
27-
print(f"Request {i}: Status Code {response.status_code}")
29+
logger.info(f"Request {i}: Status Code {response.status_code}")
2830

2931
if response.status_code == 429:
30-
print(" -> Successfully received 429 Too Many Requests!")
31-
print(f" -> Retry-After header: {response.headers.get('Retry-After')}")
32+
logger.info(" -> Successfully received 429 Too Many Requests!")
33+
logger.info(f" -> Retry-After header: {response.headers.get('Retry-After')}")
3234

3335
except requests.exceptions.RequestException as e:
34-
print(f"Request {i}: Failed to connect. Is the server running? Error: {e}")
36+
logger.error(f"Request {i}: Failed to connect. Is the server running? Error: {e}")
3537
break
3638

37-
time.sleep(0.1)
38-
39-
if __name__ == "__main__":
40-
test_limit()
39+
time.sleep(0.1)

0 commit comments

Comments
 (0)