vr180-converter / scripts /test_app.py
Prithwis's picture
Force update scripts\test_app.py - 1757355566
2c584b2 verified
#!/usr/bin/env python3
"""
Simple test script for VR180 Converter API
"""
import requests
import json
import os
import time
def test_health():
"""Test health endpoint"""
try:
response = requests.get('http://localhost:5000/api/health')
print(f"Health check: {response.status_code}")
print(f"Response: {response.json()}")
return response.status_code == 200
except Exception as e:
print(f"Health check failed: {e}")
return False
def test_upload():
"""Test file upload"""
try:
# Create a simple test video file (1 second of black frames)
import cv2
import numpy as np
# Create a simple test video
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('test_video.mp4', fourcc, 30.0, (640, 480))
for i in range(30): # 1 second at 30fps
frame = np.zeros((480, 640, 3), dtype=np.uint8)
out.write(frame)
out.release()
# Upload the test video
with open('test_video.mp4', 'rb') as f:
files = {'video': f}
response = requests.post('http://localhost:5000/api/upload', files=files)
print(f"Upload test: {response.status_code}")
print(f"Response: {response.json()}")
# Clean up
os.remove('test_video.mp4')
return response.status_code == 200
except Exception as e:
print(f"Upload test failed: {e}")
return False
def main():
print("Testing VR180 Converter API...")
print("=" * 40)
# Test health endpoint
if test_health():
print("βœ“ Health check passed")
else:
print("βœ— Health check failed")
return
# Test upload endpoint
if test_upload():
print("βœ“ Upload test passed")
else:
print("βœ— Upload test failed")
return
print("=" * 40)
print("All tests passed! API is working correctly.")
if __name__ == "__main__":
main()