bytedance-1 / test_view_session.py
drdata's picture
Upload folder using huggingface_hub
e993e6d verified
#!/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()