-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug_trap.py
More file actions
44 lines (35 loc) · 1.18 KB
/
debug_trap.py
File metadata and controls
44 lines (35 loc) · 1.18 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
"""
Debug test for trap endpoint
"""
import requests
import io
from PIL import Image
# Test configuration
API_BASE = "http://localhost:8000"
TRAP_ENDPOINT = f"{API_BASE}/trap"
def create_sample_image(width=256, height=256) -> bytes:
"""Create a sample RGB image for testing."""
img = Image.new('RGB', (width, height), color='red')
# Add some variation
pixels = img.load()
for i in range(0, width, 10):
for j in range(0, height, 10):
pixels[i, j] = (100 + (i % 155), 100 + (j % 155), 100 + ((i+j) % 155))
buffer = io.BytesIO()
img.save(buffer, format='PNG')
return buffer.getvalue()
def test_generate_json():
"""Test generate endpoint"""
image_bytes = create_sample_image()
files = {'file': ('test_image.png', image_bytes, 'image/png')}
data = {
'variants': 20,
'intensity': 50,
'format': 'json'
}
response = requests.post(f"{TRAP_ENDPOINT}/generate", files=files, data=data)
print(f"Status: {response.status_code}")
print(f"Content-Type: {response.headers.get('content-type')}")
print(f"Response: {response.text[:500]}")
if __name__ == "__main__":
test_generate_json()