File size: 1,154 Bytes
a638e13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import os

url = "http://localhost:8000/image/convert"
input_dir = "image/input"
file_path = os.path.join(input_dir, "test_quality.jpg")
output_dir = "image/output"

# Ensure directories exist
os.makedirs(input_dir, exist_ok=True)
os.makedirs(output_dir, exist_ok=True)

# Create test image
from PIL import Image
Image.new('RGB', (100, 100), color='red').save(file_path)

# Test case 1: Quality 50, Scale 0.5
data = {
    "id": "test_quality.jpg",
    "to_format": "jpg",
    "quality": 50,
    "scale": 0.5
}

try:
    response = requests.post(url, data=data)
    if response.status_code == 200:
        result = response.json()
        print(f"Success: {result}")
        
        # Verify output file
        output_file = os.path.join(output_dir, result['new_filename'])
        if os.path.exists(output_file):
            print(f"Output file created: {output_file}")
            print(f"Output file size: {os.path.getsize(output_file)} bytes")
        else:
            print("Error: Output file not found")
    else:
        print(f"Failed: {response.status_code} - {response.text}")
except Exception as e:
    print(f"Error: {e}")