Spaces:
Runtime error
Runtime error
File size: 797 Bytes
3b3a783 610afda 3b3a783 610afda 3b3a783 610afda 3b3a783 610afda |
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 |
from fastapi.testclient import TestClient
from app import app
import PIL
from PIL import Image
from io import BytesIO
client = TestClient(app)
def test_read_main():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Welcome to Image Generator"}
def test_generate_image_unauthorized():
response = client.post("/generate-image/", json={})
assert response.status_code == 401
assert response.json() == {"detail": "Not authenticated"}
def test_generate_image_authorized():
response = client.post(
"/generate-image/", json={"prompt": "a cute cat"}
)
assert response.status_code == 200
image = Image.open(BytesIO(response.content))
assert type(image) == PIL.JpegImagePlugin.JpegImageFile
test_generate_image_authorized() |