| import pytest
|
| from fastapi.testclient import TestClient
|
| from app.main import app
|
| from io import BytesIO
|
|
|
| client = TestClient(app)
|
|
|
| def test_two_object_size_success():
|
|
|
| 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_height1": 10.0,
|
| "product_width1": 15.0,
|
| "product_length1": 2.0,
|
| "product_height2": 12.0,
|
| "product_width2": 18.0,
|
| "product_length2": 2.5
|
| }
|
|
|
| response = client.post("/api/v1/walletsize", files=files, data=data)
|
| assert response.status_code == 200
|
| assert response.headers["content-type"] == "image/png"
|
|
|
| def test_two_object_size_invalid_dimensions():
|
| 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_height1": "invalid",
|
| "product_width1": 15.0,
|
| "product_length1": 2.0,
|
| "product_height2": 12.0,
|
| "product_width2": 18.0,
|
| "product_length2": 2.5
|
| }
|
|
|
| response = client.post("/api/v1/walletsize", files=files, data=data)
|
| assert response.status_code == 400
|
| assert "Invalid dimensions" in response.json()["detail"]
|
|
|
| def test_two_object_size_invalid_file_type():
|
| test_file1 = BytesIO(b"not an image 1")
|
| test_file1.name = "test1.txt"
|
| test_file2 = BytesIO(b"not an image 2")
|
| test_file2.name = "test2.txt"
|
|
|
| files = [
|
| ("garment_images", ("test1.txt", test_file1, "text/plain")),
|
| ("garment_images", ("test2.txt", test_file2, "text/plain"))
|
| ]
|
| data = {
|
| "product_height1": 10.0,
|
| "product_width1": 15.0,
|
| "product_length1": 2.0,
|
| "product_height2": 12.0,
|
| "product_width2": 18.0,
|
| "product_length2": 2.5
|
| }
|
|
|
| response = client.post("/api/v1/walletsize", files=files, data=data)
|
| assert response.status_code == 400
|
| assert "Invalid file type" in response.json()["detail"]
|
|
|
| def test_two_object_size_missing_file():
|
| data = {
|
| "product_height1": 10.0,
|
| "product_width1": 15.0,
|
| "product_length1": 2.0,
|
| "product_height2": 12.0,
|
| "product_width2": 18.0,
|
| "product_length2": 2.5
|
| }
|
|
|
| response = client.post("/api/v1/walletsize", data=data)
|
| assert response.status_code == 422
|
|
|
| def test_two_object_size_single_file():
|
| 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_height1": 10.0,
|
| "product_width1": 15.0,
|
| "product_length1": 2.0,
|
| "product_height2": 12.0,
|
| "product_width2": 18.0,
|
| "product_length2": 2.5
|
| }
|
|
|
| response = client.post("/api/v1/walletsize", files=files, data=data)
|
| assert response.status_code == 400
|
| assert "Exactly two front shot images of wallet" in response.json()["detail"]
|
|
|
| def test_two_object_size_three_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"
|
| test_image3 = BytesIO(b"fake image data 3")
|
| test_image3.name = "test_image3.jpg"
|
|
|
| files = [
|
| ("garment_images", ("test_image1.jpg", test_image1, "image/jpeg")),
|
| ("garment_images", ("test_image2.jpg", test_image2, "image/jpeg")),
|
| ("garment_images", ("test_image3.jpg", test_image3, "image/jpeg"))
|
| ]
|
| data = {
|
| "product_height1": 10.0,
|
| "product_width1": 15.0,
|
| "product_length1": 2.0,
|
| "product_height2": 12.0,
|
| "product_width2": 18.0,
|
| "product_length2": 2.5
|
| }
|
|
|
| response = client.post("/api/v1/walletsize", files=files, data=data)
|
| assert response.status_code == 400
|
| assert "Exactly two front shot images of wallet" in response.json()["detail"] |