Spaces:
Sleeping
Sleeping
File size: 1,603 Bytes
e2a1a46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 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())
|