-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_backend_only.py
More file actions
153 lines (136 loc) · 4.9 KB
/
test_backend_only.py
File metadata and controls
153 lines (136 loc) · 4.9 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
#!/usr/bin/env python3
"""
Test just the backend functionality
"""
import requests
import json
import time
import sys
from PIL import Image
import io
def test_backend():
print("🧪 Testing Hatchmark Backend Only")
print("=" * 40)
# Wait for backend to be ready
print("⏳ Waiting for backend to start...")
for i in range(10):
try:
response = requests.get("http://localhost:3002/health", timeout=2)
if response.status_code == 200:
print("✅ Backend is ready!")
break
except:
pass
time.sleep(1)
print(f" Waiting... ({i+1}/10)")
else:
print("❌ Backend failed to start")
return False
# Test 1: Health Check
print("\n1️⃣ Testing Health Check")
try:
response = requests.get("http://localhost:3002/health", timeout=5)
if response.status_code == 200:
data = response.json()
print(f"✅ Health check passed: {data.get('status')}")
else:
print(f"❌ Health check failed: {response.status_code}")
return False
except Exception as e:
print(f"❌ Health check error: {e}")
return False
# Test 2: Upload Initiation
print("\n2️⃣ Testing Upload Initiation")
try:
payload = {"filename": "test-backend.jpg"}
response = requests.post(
"http://localhost:3002/uploads/initiate",
json=payload,
headers={'Content-Type': 'application/json'},
timeout=10
)
if response.status_code == 200:
data = response.json()
if 'uploadUrl' in data and 'objectKey' in data:
print(f"✅ Upload initiation successful")
print(f" Object Key: {data['objectKey']}")
upload_data = data
else:
print(f"❌ Upload response missing fields: {list(data.keys())}")
return False
else:
print(f"❌ Upload initiation failed: {response.status_code}")
print(f" Response: {response.text}")
return False
except Exception as e:
print(f"❌ Upload initiation error: {e}")
return False
# Test 3: Create and Upload Test Image
print("\n3️⃣ Testing File Upload")
try:
# Create a simple test image
img = Image.new('RGB', (100, 100), color='red')
img_buffer = io.BytesIO()
img.save(img_buffer, format='JPEG')
test_image = img_buffer.getvalue()
# Upload to local endpoint
upload_url = upload_data['uploadUrl']
print(f" Upload URL: {upload_url}")
upload_response = requests.put(
upload_url,
data=test_image,
headers={'Content-Type': 'image/jpeg'},
timeout=15
)
if upload_response.status_code == 200:
print("✅ File upload successful")
else:
print(f"❌ File upload failed: {upload_response.status_code}")
print(f" Response: {upload_response.text}")
except Exception as e:
print(f"❌ File upload error: {e}")
# Test 4: Duplicate Check
print("\n4️⃣ Testing Duplicate Check")
try:
files = {'file': ('test.jpg', test_image, 'image/jpeg')}
response = requests.post(
"http://localhost:3002/uploads/check-duplicate",
files=files,
timeout=15
)
if response.status_code == 200:
data = response.json()
print(f"✅ Duplicate check successful")
print(f" Is Duplicate: {data.get('isDuplicate', 'unknown')}")
else:
print(f"❌ Duplicate check failed: {response.status_code}")
print(f" Response: {response.text}")
except Exception as e:
print(f"❌ Duplicate check error: {e}")
# Test 5: Verification
print("\n5️⃣ Testing Verification")
try:
files = {'file': ('test.jpg', test_image, 'image/jpeg')}
response = requests.post(
"http://localhost:3002/verify",
files=files,
timeout=15
)
if response.status_code == 200:
data = response.json()
print(f"✅ Verification successful")
print(f" Status: {data.get('status', 'unknown')}")
print(f" Asset ID: {data.get('assetId', 'none')}")
else:
print(f"❌ Verification failed: {response.status_code}")
print(f" Response: {response.text}")
except Exception as e:
print(f"❌ Verification error: {e}")
print("\n🎉 Backend Testing Complete!")
print("=" * 40)
print("✅ Your backend is working locally!")
print("🌐 Ready to test with Vercel frontend")
return True
if __name__ == "__main__":
success = test_backend()
sys.exit(0 if success else 1)