Spaces:
Sleeping
Sleeping
| #!/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() |