import pytest from fastapi.testclient import TestClient from backend.main import app from backend.calendar_generator import CalendarGenerator from datetime import datetime client = TestClient(app) def test_calendar_generator(): generator = CalendarGenerator() ics_content = generator.generate_ics("Test Med", "twice daily", "7 days") assert "BEGIN:VCALENDAR" in ics_content assert "SUMMARY:Take Test Med" in ics_content assert "END:VCALENDAR" in ics_content def test_interaction_endpoint_mock(): # Mocking the Gemini response would be ideal, but for now we test the endpoint structure # This test assumes the backend handles the request correctly even if Gemini is mocked or fails gracefully response = client.post("/check-interactions", json={"medicines": ["Aspirin", "Warfarin"]}) # Since we are using a real API key in the code, this might actually hit Gemini if network is allowed. # If network is restricted, it should handle the error gracefully. assert response.status_code in [200, 500] if response.status_code == 200: data = response.json() assert "interactions" in data def test_calendar_endpoint(): response = client.post("/generate-calendar", json={ "medicine_name": "Amoxicillin", "frequency": "TID", "duration": "5 days" }) assert response.status_code == 200 data = response.json() assert "download_url" in data assert data["download_url"].startswith("/export/calendar/")