Download tests/api/v1/test_size_comparison.py from zclap/VTO: direct link, hf CLI and curl.
- Browser
- Download file 2.78 kB
-
https://huggingface.co/spaces/zclap/VTO/resolve/main/tests/api/v1/test_size_comparison.py
- Command line
-
hf download hf://spaces/zclap/VTO/tests/api/v1/test_size_comparison.py
-
curl -L -o test_size_comparison.py https://huggingface.co/spaces/zclap/VTO/resolve/main/tests/api/v1/test_size_comparison.py
2.78 kB
| import pytest | |
| from fastapi.testclient import TestClient | |
| from app.main import app | |
| from io import BytesIO | |
| client = TestClient(app) | |
| def test_size_comparison_success(): | |
| # Create a test image file | |
| test_image = BytesIO(b"fake image data") | |
| test_image.name = "test_image.jpg" | |
| # Test data | |
| files = { | |
| "garment_images": ("test_image.jpg", test_image, "image/jpeg") | |
| } | |
| data = { | |
| "product_height": 30.0, | |
| "product_width": 20.0, | |
| "product_length": 15.0 | |
| } | |
| response = client.post("/api/v1/size", files=files, data=data) | |
| assert response.status_code == 200 | |
| assert response.headers["content-type"] == "image/png" | |
| def test_size_comparison_invalid_dimensions(): | |
| test_image = BytesIO(b"fake image data") | |
| test_image.name = "test_image.jpg" | |
| files = { | |
| "garment_images": ("test_image.jpg", test_image, "image/jpeg") | |
| } | |
| data = { | |
| "product_height": "invalid", # Invalid height | |
| "product_width": 20.0, | |
| "product_length": 15.0 | |
| } | |
| response = client.post("/api/v1/size", files=files, data=data) | |
| assert response.status_code == 400 | |
| assert "Invalid dimensions" in response.json()["detail"] | |
| def test_size_comparison_invalid_file_type(): | |
| test_file = BytesIO(b"not an image") | |
| test_file.name = "test.txt" | |
| files = { | |
| "garment_images": ("test.txt", test_file, "text/plain") | |
| } | |
| data = { | |
| "product_height": 30.0, | |
| "product_width": 20.0, | |
| "product_length": 15.0 | |
| } | |
| response = client.post("/api/v1/size", files=files, data=data) | |
| assert response.status_code == 400 | |
| assert "Invalid file type" in response.json()["detail"] | |
| def test_size_comparison_missing_file(): | |
| data = { | |
| "product_height": 30.0, | |
| "product_width": 20.0, | |
| "product_length": 15.0 | |
| } | |
| response = client.post("/api/v1/size", data=data) | |
| assert response.status_code == 422 # FastAPI validation error | |
| def test_size_comparison_multiple_files(): | |
| test_image1 = BytesIO(b"fake image data 1") | |
| test_image1.name = "test_image1.jpg" | |
| test_image2 = BytesIO(b"fake image data 2") | |
| test_image2.name = "test_image2.jpg" | |
| files = [ | |
| ("garment_images", ("test_image1.jpg", test_image1, "image/jpeg")), | |
| ("garment_images", ("test_image2.jpg", test_image2, "image/jpeg")) | |
| ] | |
| data = { | |
| "product_height": 30.0, | |
| "product_width": 20.0, | |
| "product_length": 15.0 | |
| } | |
| response = client.post("/api/v1/size", files=files, data=data) | |
| assert response.status_code == 400 | |
| assert "Exactly one front shot of the image" in response.json()["detail"] |