Create test_app.py

This commit is contained in:
DarkShy
2025-08-23 04:02:45 +03:00
committed by GitHub
parent b3b4b44958
commit 20b80731c0

42
test_app.py Normal file
View File

@@ -0,0 +1,42 @@
import pytest
import asyncio
from aioresponses import aioresponses
from app import fetch_image, DERPYBOORU_API_SEARCH, DERPIBOORU_TOKEN
@pytest.mark.asyncio
async def test_fetch_image_found():
# Мокаем API-ответ с одним изображением
tags = ["safe", "pony"]
with aioresponses() as m:
m.get(
f"{DERPYBOORU_API_SEARCH}",
payload={
"images": [
{
"representations": {"full": "https://test.img/full.png"},
"uploader": "tester",
"view_url": "https://derpibooru.org/images/1",
"tags": ["pony", "cute"]
}
]
}
)
async with asyncio.get_event_loop().run_until_complete:
result = await fetch_image(tags)
assert result is not None
url, author, source, img_tags = result
assert url == "https://test.img/full.png"
assert author == "tester"
assert source == "https://derpibooru.org/images/1"
assert "pony" in img_tags
@pytest.mark.asyncio
async def test_fetch_image_not_found():
tags = ["nonexistenttag123"]
with aioresponses() as m:
m.get(
f"{DERPYBOORU_API_SEARCH}",
payload={"images": []}
)
result = await fetch_image(tags)
assert result is None