Spaces:
Sleeping
Sleeping
File size: 2,848 Bytes
e993e6d |
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 |
#!/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() |