email-Assistant-Using-Ai / sample_test.py
Gaurav3134's picture
Upload 43 files
0387a1c verified
from __future__ import annotations
"""
Sample test case (manual integration check).
1) Run the API:
uvicorn main:app --reload --host 127.0.0.1 --port 8000
2) Run:
python sample_test.py
"""
import json
import os
import urllib.request
BASE_URL = os.environ.get("BASE_URL", "http://127.0.0.1:8000")
def post_json(path: str, payload: dict) -> dict:
body = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(
BASE_URL + path,
data=body,
headers={"Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(req, timeout=30) as resp: # nosec - local dev call
return json.loads(resp.read().decode("utf-8"))
def main() -> None:
email = {
"from_email": "customer@example.com",
"subject": "Need help resetting my password",
"body": "Hi, I cannot log in. Please help me reset my password. Thanks!",
}
print("POST /classify")
print(post_json("/classify", email))
print()
print("POST /generate-reply")
print(post_json("/generate-reply", {**email, "tone": "formal"}))
if __name__ == "__main__":
main()