Changes to be committed:

new file:   Docker/.dockerfile
	new file:   Docker/.env.example
	new file:   Docker/.gitignore
	new file:   Docker/requirements.txt#
    deleted:    test_app.py
This commit is contained in:
DarkShyMW
2025-08-23 07:44:45 +03:00
parent bf52d4f6d2
commit c301d0b09b
5 changed files with 29 additions and 42 deletions

18
Docker/.dockerfile Normal file
View File

@@ -0,0 +1,18 @@
FROM python:3.12-slim
WORKDIR /app
# Установка зависимостей
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Копируем код
COPY . .
# Переменные окружения (можно переопределить при запуске)
ENV TELEGRAM_TOKEN=""
ENV DERPIBOORU_TOKEN=""
ENV CHANNEL_ID=""
ENV FILTER_ID=56027
CMD ["python", "app.py"]

4
Docker/.env.example Normal file
View File

@@ -0,0 +1,4 @@
TELEGRAM_TOKEN=your-telegram-token-here
DERPIBOORU_TOKEN=your-derpibooru-token-here
CHANNEL_ID=-1002010407572
FILTER_ID=56027

5
Docker/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
venv/
__pycache__/
*.pyc
sent_images.json
bot.log

2
Docker/requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
python-telegram-bot==20.5
aiohttp==3.9.5

View File

@@ -1,42 +0,0 @@
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