Add tests
This commit is contained in:
24
tests/test_post.py
Normal file
24
tests/test_post.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import pytest
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from app import post_image
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@patch("app.bot.send_photo", new_callable=AsyncMock)
|
||||
@patch("app.fetch_image", return_value=(
|
||||
"https://example.com/full.png",
|
||||
"tester",
|
||||
"https://derpibooru.org/images/123",
|
||||
["gay", "cute"]
|
||||
))
|
||||
async def test_post_image_success(mock_fetch, mock_send_photo, tmp_path, monkeypatch):
|
||||
"""Тестируем успешную публикацию картинки"""
|
||||
|
||||
# временный файл для sent_images
|
||||
monkeypatch.setattr("app.SENT_IMAGES_FILE", tmp_path / "sent.json")
|
||||
monkeypatch.setattr("app.sent_images", set())
|
||||
|
||||
await post_image(tags=["gay"])
|
||||
|
||||
mock_fetch.assert_called_once()
|
||||
mock_send_photo.assert_awaited_once()
|
||||
Reference in New Issue
Block a user