-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_image_voiceover.py
More file actions
152 lines (125 loc) Β· 5.14 KB
/
test_image_voiceover.py
File metadata and controls
152 lines (125 loc) Β· 5.14 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
"""
Test script for image-to-video voiceover functionality.
"""
import requests
import time
import json
import sys
import os
# Test configuration
API_BASE_URL = "http://localhost:8080"
# Sample test data - you would replace these with actual URLs
TEST_CASES = [
{
"name": "Image with voiceover",
"description": "Test creating video from image with zoom effect",
"data": {
"image_url": "https://sample-videos.com/zip/10/jpg/mp4/SampleJPGImage_30mbmb.jpg",
"audio_url": "https://sample-videos.com/zip/10/mp3/mp4/SampleAudio_0.4mb_mp3.mp3",
"zoom_factor": 1.15
}
},
{
"name": "Video with voiceover (existing functionality)",
"description": "Test existing video functionality still works",
"data": {
"video_url": "https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4",
"audio_url": "https://sample-videos.com/zip/10/mp3/mp4/SampleAudio_0.4mb_mp3.mp3",
"zoom_factor": 1.1
}
}
]
def test_endpoint(test_case):
"""Test a single endpoint."""
print(f"\n{'='*60}")
print(f"Testing: {test_case['name']}")
print(f"Description: {test_case['description']}")
print(f"{'='*60}")
try:
# Submit job
print("π€ Submitting job...")
response = requests.post(f"{API_BASE_URL}/add-voiceover",
json=test_case['data'],
headers={'Content-Type': 'application/json'})
if response.status_code != 202:
print(f"β Job submission failed: {response.status_code}")
print(f"Response: {response.text}")
return False
job_info = response.json()
job_id = job_info['job_id']
print(f"β
Job submitted successfully: {job_id}")
# Monitor job progress
print("β³ Monitoring job progress...")
max_wait = 300 # 5 minutes max
start_time = time.time()
while time.time() - start_time < max_wait:
status_response = requests.get(f"{API_BASE_URL}/job-status/{job_id}")
if status_response.status_code != 200:
print(f"β Failed to check job status: {status_response.status_code}")
return False
status_data = status_response.json()
print(f"π Status: {status_data['status']} | Progress: {status_data.get('progress', 0)}% | {status_data.get('status_message', 'Processing...')}")
if status_data['status'] == 'completed':
print(f"β
Job completed successfully!")
print(f"π Output file: {status_data.get('output_path', 'N/A')}")
# Try to download the result
download_response = requests.get(f"{API_BASE_URL}/download/{job_id}")
if download_response.status_code == 200:
output_filename = f"test_output_{job_id}.mp4"
with open(output_filename, 'wb') as f:
f.write(download_response.content)
print(f"πΎ Downloaded result to: {output_filename}")
return True
elif status_data['status'] == 'failed':
print(f"β Job failed: {status_data.get('error', 'Unknown error')}")
return False
# Wait before next check
time.sleep(5)
print(f"β° Job timed out after {max_wait} seconds")
return False
except Exception as e:
print(f"β Test failed with exception: {e}")
return False
def main():
"""Run all tests."""
print("π Starting Image Voiceover Tests")
print(f"API Base URL: {API_BASE_URL}")
# Check if server is running
try:
health_response = requests.get(f"{API_BASE_URL}/health", timeout=5)
if health_response.status_code != 200:
print(f"β Server not healthy: {health_response.status_code}")
return False
print("β
Server is running and healthy")
except Exception as e:
print(f"β Cannot connect to server: {e}")
print("Make sure the server is running with: python app.py")
return False
# Run tests
results = []
for test_case in TEST_CASES:
success = test_endpoint(test_case)
results.append({
'name': test_case['name'],
'success': success
})
# Summary
print(f"\n{'='*60}")
print("π TEST SUMMARY")
print(f"{'='*60}")
total_tests = len(results)
passed_tests = sum(1 for r in results if r['success'])
for result in results:
status = "β
PASS" if result['success'] else "β FAIL"
print(f"{status}: {result['name']}")
print(f"\nResults: {passed_tests}/{total_tests} tests passed")
if passed_tests == total_tests:
print("π All tests passed!")
return True
else:
print("β οΈ Some tests failed!")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)