Update test_main.py

This commit is contained in:
Boroumand, Amir A 2024-04-22 14:04:08 -04:00
parent 7c27abe4bc
commit a1424abc2c

View File

@ -1,16 +1,19 @@
"""API Tests"""
from fastapi.testclient import TestClient
from main import app
client = TestClient(app)
file_name = "sunflower.jpg"
FILE_NAME = "sunflower.jpg"
def test_read_main():
response = client.post("/api/v1/detect", files={"file": (file_name, open(file_name, "rb"), "image/jpeg")})
"""Tests that POST /api/v1/detect returns 200 OK with valid request body"""
response = client.post("/api/v1/detect", files={"file": (FILE_NAME, open(FILE_NAME, "rb"), "image/jpeg")})
assert response.status_code == 200
assert response.json() == {"file_name": file_name, "is_nsfw": False, "confidence_percentage": 100.0}
assert response.json() == {"file_name": FILE_NAME, "is_nsfw": False, "confidence_percentage": 100.0}
def test_invalid_input():
"""Tests that POST /api/v1/detect returns 422 with empty request body"""
response = client.post("/api/v1/detect", files={})
assert response.status_code == 422
assert response.status_code == 422