#!/usr/bin/env python3 """ Test the view_session route directly """ import requests import time def test_view_session_route(): """Test the view_session route""" print("๐Ÿงช Testing view_session route...") # Give the server a moment to fully start time.sleep(2) base_url = "http://localhost:7860" test_timestamp = "20250924_090627" test_url = f"{base_url}/view_session/{test_timestamp}" try: print(f"๐Ÿ“ก Testing URL: {test_url}") response = requests.get(test_url, timeout=10) print(f"๐Ÿ“Š Response Status: {response.status_code}") print(f"๐Ÿ“‹ Content-Type: {response.headers.get('content-type', 'Not specified')}") print(f"๐Ÿ“ Content Length: {len(response.text)} characters") if response.status_code == 200: if "Session 20250924_090627" in response.text: print("โœ… SUCCESS: View session page loaded correctly!") # Check if images are referenced if "/files/session_20250924_090627/" in response.text: print("โœ… SUCCESS: Image URLs are properly generated!") else: print("โš ๏ธ WARNING: Image URLs might be missing") # Check for expected images expected_images = ["realistic", "artistic", "vintage", "webcam"] found_images = [img for img in expected_images if img.lower() in response.text.lower()] print(f"๐Ÿ–ผ๏ธ Found image references: {found_images}") else: print("โš ๏ธ WARNING: Expected content not found in response") elif response.status_code == 404: print("โŒ ERROR: Session not found (404)") else: print(f"โŒ ERROR: Unexpected status code: {response.status_code}") # Test a file URL directly file_test_url = f"{base_url}/files/session_{test_timestamp}/generated_realistic_{test_timestamp}.jpg" print(f"\n๐Ÿ“ก Testing direct file access: {file_test_url}") file_response = requests.head(file_test_url, timeout=5) print(f"๐Ÿ“Š File Response Status: {file_response.status_code}") if file_response.status_code == 200: print("โœ… SUCCESS: Direct file access works!") else: print(f"โŒ ERROR: Direct file access failed: {file_response.status_code}") except requests.exceptions.ConnectionError: print("โŒ ERROR: Could not connect to the server. Is the app running?") except requests.exceptions.Timeout: print("โŒ ERROR: Request timed out") except Exception as e: print(f"โŒ ERROR: {e}") if __name__ == "__main__": test_view_session_route()