File size: 4,344 Bytes
9021fab |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
#!/usr/bin/env python3
"""
Simple test script for the Smart Document Analysis Platform
"""
import unittest
import os
import tempfile
import json
from app import app
class TestSmartDocumentAnalysis(unittest.TestCase):
def setUp(self):
"""Set up test client"""
self.app = app.test_client()
self.app.testing = True
def test_index_page(self):
"""Test that the main page loads"""
response = self.app.get('/')
self.assertEqual(response.status_code, 200)
self.assertIn(b'Smart Document Analysis Platform', response.data)
def test_upload_no_file(self):
"""Test upload endpoint with no file"""
response = self.app.post('/upload')
data = json.loads(response.data)
self.assertFalse(data['success'])
self.assertIn('No file provided', data['error'])
def test_upload_url_no_url(self):
"""Test upload from URL with no URL"""
response = self.app.post('/upload-url',
json={},
content_type='application/json')
data = json.loads(response.data)
self.assertFalse(data['success'])
self.assertIn('No URL provided', data['error'])
def test_ask_no_question(self):
"""Test ask endpoint with no question"""
response = self.app.post('/ask',
json={'cache_id': 'test'},
content_type='application/json')
data = json.loads(response.data)
self.assertFalse(data['success'])
self.assertIn('Missing question or cache_id', data['error'])
def test_ask_no_cache_id(self):
"""Test ask endpoint with no cache_id"""
response = self.app.post('/ask',
json={'question': 'test'},
content_type='application/json')
data = json.loads(response.data)
self.assertFalse(data['success'])
self.assertIn('Missing question or cache_id', data['error'])
def test_list_caches(self):
"""Test listing caches"""
response = self.app.get('/caches')
data = json.loads(response.data)
self.assertTrue(data['success'])
self.assertIn('caches', data)
def test_delete_nonexistent_cache(self):
"""Test deleting a cache that doesn't exist"""
response = self.app.delete('/cache/nonexistent')
data = json.loads(response.data)
self.assertFalse(data['success'])
self.assertIn('Cache not found', data['error'])
def test_environment_setup():
"""Test that environment is properly configured"""
print("π§ Testing environment setup...")
# Check if .env file exists
if os.path.exists('.env'):
print("β
.env file found")
else:
print("β οΈ .env file not found - you'll need to create one")
# Check if API key is set
api_key = os.getenv('GOOGLE_API_KEY')
if api_key and api_key != 'your_gemini_api_key_here':
print("β
GOOGLE_API_KEY is set")
else:
print("β οΈ GOOGLE_API_KEY not set - please add it to .env file")
# Check if required packages are installed
try:
import flask
print("β
Flask is installed")
except ImportError:
print("β Flask is not installed")
try:
import google.genai
print("β
Google GenAI is installed")
except ImportError:
print("β Google GenAI is not installed")
try:
import httpx
print("β
httpx is installed")
except ImportError:
print("β httpx is not installed")
if __name__ == '__main__':
print("π§ͺ Running Smart Document Analysis Platform Tests")
print("=" * 60)
# Run environment tests
test_environment_setup()
print("\n" + "=" * 60)
print("Running unit tests...")
# Run unit tests
unittest.main(argv=[''], exit=False, verbosity=2)
print("\nπ Testing completed!")
print("\nπ Next steps:")
print(" 1. Set up your GOOGLE_API_KEY in .env file")
print(" 2. Run 'python app.py' to start the application")
print(" 3. Open http://localhost:5000 in your browser")
print(" 4. Try uploading a PDF and asking questions!") |