#!/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!")