-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_google_drive.py
More file actions
executable file
·96 lines (82 loc) · 3.58 KB
/
test_google_drive.py
File metadata and controls
executable file
·96 lines (82 loc) · 3.58 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
#!/usr/bin/env python3
"""
Test Google Drive download functionality
"""
import sys
import os
sys.path.append('.')
from app.utils.download_utils import download_file, _convert_google_drive_url, _is_google_drive_url
def test_google_drive_url_conversion():
"""Test Google Drive URL conversion"""
print("🧪 Testing Google Drive URL conversion...")
test_cases = [
{
"name": "Sharing URL",
"input": "https://drive.google.com/file/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/view?usp=sharing",
"expected": "https://drive.google.com/uc?export=download&id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
},
{
"name": "Open URL",
"input": "https://drive.google.com/open?id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
"expected": "https://drive.google.com/uc?export=download&id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
},
{
"name": "Already direct URL",
"input": "https://drive.google.com/uc?export=download&id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
"expected": "https://drive.google.com/uc?export=download&id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
},
{
"name": "Non-Google Drive URL",
"input": "https://example.com/video.mp4",
"expected": "https://example.com/video.mp4"
}
]
for test in test_cases:
result = _convert_google_drive_url(test["input"])
if result == test["expected"]:
print(f"✅ {test['name']}: PASS")
else:
print(f"❌ {test['name']}: FAIL")
print(f" Expected: {test['expected']}")
print(f" Got: {result}")
def test_google_drive_detection():
"""Test Google Drive URL detection"""
print("\n🔍 Testing Google Drive URL detection...")
test_cases = [
("https://drive.google.com/file/d/1234/view", True),
("https://docs.google.com/document/d/1234", True),
("https://googleapis.com/drive/v3/files/1234", True),
("https://example.com/video.mp4", False),
("https://youtube.com/watch?v=1234", False)
]
for url, expected in test_cases:
result = _is_google_drive_url(url)
if result == expected:
print(f"✅ {url}: {'Google Drive' if expected else 'Not Google Drive'}")
else:
print(f"❌ {url}: FAIL - Expected {expected}, got {result}")
def test_download_sample():
"""Test downloading a sample file (if available)"""
print("\n📥 Testing sample download...")
print("Note: This test requires a valid public Google Drive video file URL")
print("Skipping actual download test - would require real Google Drive URL")
def main():
"""Run all tests"""
print("🎬 Google Drive Download Tests")
print("=" * 40)
test_google_drive_url_conversion()
test_google_drive_detection()
test_download_sample()
print("\n" + "=" * 40)
print("📋 Google Drive URL Formats Supported:")
print("✅ https://drive.google.com/file/d/FILE_ID/view?usp=sharing")
print("✅ https://drive.google.com/open?id=FILE_ID")
print("✅ https://drive.google.com/uc?export=download&id=FILE_ID")
print("✅ https://docs.google.com/document/d/FILE_ID")
print("\n📋 Features Added:")
print("✅ Automatic URL conversion for Google Drive")
print("✅ Virus scan warning bypass for large files")
print("✅ Improved content type validation")
print("✅ Better error handling for Google Drive edge cases")
if __name__ == "__main__":
main()