-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_supabase_storage.py
More file actions
72 lines (57 loc) · 1.94 KB
/
test_supabase_storage.py
File metadata and controls
72 lines (57 loc) · 1.94 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
#!/usr/bin/env python3
"""
Test script for Supabase storage functionality.
"""
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), 'app'))
from app.services.supabase_storage import upload_file_to_supabase, create_signed_url
import io
from PIL import Image
def create_test_image():
"""Create a simple test image."""
# Create a simple 100x100 test image
img = Image.new('RGB', (100, 100), color='red')
img_buffer = io.BytesIO()
img.save(img_buffer, format='PNG')
return img_buffer.getvalue()
def test_supabase_upload():
"""Test uploading a file to Supabase storage."""
print("Testing Supabase storage upload...")
# Create test image data
test_image_data = create_test_image()
# Test upload
upload_url = upload_file_to_supabase(
file_data=test_image_data,
file_name="test_upload.png",
bucket="images",
content_type="image/png"
)
if upload_url:
print(f"✅ Upload successful! URL: {upload_url}")
return upload_url
else:
print("❌ Upload failed!")
return None
def test_signed_url(file_path):
"""Test creating a signed URL."""
print(f"Testing signed URL creation for: {file_path}")
signed_url = create_signed_url(file_path, bucket="images", expires_in=3600)
if signed_url:
print(f"✅ Signed URL created: {signed_url}")
return signed_url
else:
print("❌ Signed URL creation failed!")
return None
if __name__ == "__main__":
print("🧪 Supabase Storage Test")
print("=" * 40)
# Test upload
upload_url = test_supabase_upload()
if upload_url:
# Extract file path from URL for signed URL test
file_path = upload_url.split('/')[-1]
print(f"\nExtracted file path: {file_path}")
# Test signed URL
signed_url = test_signed_url(f"plots/{file_path}")
print("\n🏁 Test completed!")