presightlite / tests /test_invalid_image.py
sabareesh4317
Initial deployment (clean)
8b8fa39
Raw History Blame Contribute Delete
1.6 kB
import os
import sys
import asyncio
from unittest.mock import MagicMock, patch
# Add project root to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from backend.gemini_analyzer import GeminiPrescriptionAnalyzer, GeminiPrescription
import pytest
@pytest.mark.asyncio
async def test_invalid_image_detection():
print("🧪 Testing Invalid Image Detection...")
# Mock the Gemini client
mock_response = MagicMock()
mock_response.text = """
{
"medical_context": {
"is_prescription": false,
"diagnosis": "",
"symptoms": "",
"allergies": ""
},
"patient_info": {},
"healthcare_provider": {},
"prescription_details": {},
"medicines": [],
"special_instructions": "This image does not appear to be a prescription."
}
"""
with patch('google.generativeai.GenerativeModel') as MockModel:
mock_client = MockModel.return_value
mock_client.generate_content.return_value = mock_response
analyzer = GeminiPrescriptionAnalyzer(api_key="dummy_key")
# Test with dummy text
result = analyzer.analyze_prescription(raw_text="dummy", image_path="dummy.jpg")
print(f"Is Prescription: {result.is_prescription}")
if result.is_prescription is False:
print("✅ Successfully detected invalid image")
else:
print("❌ Failed to detect invalid image")
if __name__ == "__main__":
asyncio.run(test_invalid_image_detection())