/
asbres
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
asbres
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
main
tests/test_api.py
56 строк
1 KB
Александр Семененко
feature: ci cd
16 май 2026, 13:13
16 май 2026, 13:13
01a1e3b
Код
Авторство
О чём код?
from fastapi.testclient import TestClient from fastapi import status from PIL import Image import io from main import app client = TestClient(app) def create_test_image(): image = Image.new("RGB", (100, 100), color="red") buf = io.BytesIO() image.save(buf, format="PNG") buf.seek(0) return buf def test_health(): response = client.get("/health") assert response.status_code == 200 assert response.json()["status"] == "ok" def test_remove_background(): image = create_test_image() response = client.post( "/remove-background", files={"file": ("test.png", image, "image/png")}, ) assert response.status_code == status.HTTP_200_OK assert response.headers["content-type"] == "image/png" def test_get_mask(): image = create_test_image() response = client.post( "/get-mask", files={"file": ("test.png", image, "image/png")}, ) assert response.status_code == status.HTTP_200_OK assert response.headers["content-type"] == "image/png" def test_invalid_file(): response = client.post( "/remove-background", files={"file": ("test.txt", b"hello", "text/plain")}, ) assert response.status_code == 400