-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_api.py
More file actions
executable file
Β·169 lines (138 loc) Β· 4.89 KB
/
test_api.py
File metadata and controls
executable file
Β·169 lines (138 loc) Β· 4.89 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python3
"""
Simple test script for the ShortsCreator API
"""
import requests
import time
import json
# API base URL
BASE_URL = "http://localhost:5000"
def test_health():
"""Test the health endpoint"""
print("π Testing health endpoint...")
response = requests.get(f"{BASE_URL}/health")
print(f"Status: {response.status_code}")
print(f"Response: {response.json()}")
return response.status_code == 200
def test_add_subtitles():
"""Test the add subtitles endpoint"""
print("\n㪠Testing add subtitles endpoint...")
# Example request data
data = {
"language": "en",
"url": "https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4", # Sample video URL
"return_subtitles_file": True,
"settings": {
"style": "classic",
"box-color": "#000000",
"outline-width": 10,
"word-color": "#002F6C",
"shadow-offset": 0,
"shadow-color": "#000000",
"max-words-per-line": 4,
"font-size": 100,
"font-family": "Arial-Bold",
"position": "center-center",
"outline-color": "#000000",
"line-color": "#FFF4E9"
}
}
response = requests.post(f"{BASE_URL}/add-subtitles", json=data)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"Job ID: {result['job_id']}")
return result['job_id']
else:
print(f"Error: {response.text}")
return None
def test_split_video():
"""Test the split video endpoint"""
print("\nβοΈ Testing split video endpoint...")
data = {
"url": "https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4",
"start_time": 2.0,
"end_time": 8.0
}
response = requests.post(f"{BASE_URL}/split-video", json=data)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"Job ID: {result['job_id']}")
return result['job_id']
else:
print(f"Error: {response.text}")
return None
def test_join_videos():
"""Test the join videos endpoint"""
print("\nπ Testing join videos endpoint...")
data = {
"urls": [
"https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4",
"https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4"
]
}
response = requests.post(f"{BASE_URL}/join-videos", json=data)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"Job ID: {result['job_id']}")
return result['job_id']
else:
print(f"Error: {response.text}")
return None
def check_job_status(job_id):
"""Check job status"""
print(f"\nπ Checking job status: {job_id}")
max_attempts = 30 # Wait up to 5 minutes
attempt = 0
while attempt < max_attempts:
response = requests.get(f"{BASE_URL}/job-status/{job_id}")
if response.status_code == 200:
result = response.json()
status = result['status']
progress = result.get('progress', 0)
print(f"Status: {status}, Progress: {progress}%")
if status == "completed":
print("β
Job completed successfully!")
return True
elif status == "failed":
print(f"β Job failed: {result.get('error', 'Unknown error')}")
return False
else:
print(f"β³ Job still processing... (attempt {attempt + 1}/{max_attempts})")
time.sleep(10)
else:
print(f"Error checking status: {response.text}")
return False
attempt += 1
print("β° Timeout waiting for job completion")
return False
def main():
"""Run all tests"""
print("π Starting API tests...\n")
# Test health endpoint
if not test_health():
print("β Health check failed. Make sure the API is running.")
return
# Test endpoints
job_ids = []
# Test split video (fastest operation)
job_id = test_split_video()
if job_id:
job_ids.append(("split_video", job_id))
# Test join videos
job_id = test_join_videos()
if job_id:
job_ids.append(("join_videos", job_id))
# Check job statuses
for job_type, job_id in job_ids:
print(f"\n{'='*50}")
print(f"Monitoring {job_type} job...")
check_job_status(job_id)
print(f"\n{'='*50}")
print("π API tests completed!")
print("\nNote: Subtitle generation test is commented out as it requires")
print("a video with actual speech content for meaningful results.")
if __name__ == "__main__":
main()