|
|
|
""" |
|
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...") |
|
|
|
|
|
if os.path.exists('.env'): |
|
print("β
.env file found") |
|
else: |
|
print("β οΈ .env file not found - you'll need to create one") |
|
|
|
|
|
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") |
|
|
|
|
|
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) |
|
|
|
|
|
test_environment_setup() |
|
|
|
print("\n" + "=" * 60) |
|
print("Running 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!") |