mirror of
https://github.com/dbv111m/musicgrabber.git
synced 2026-10-19 01:31:29 -05:00
feat(bot): e2e button tests via tgfake local Bot API stand
TELEGRAM_API_URL env redirects the bot to a local tgfake instance (PTB needs base_url WITH the /bot suffix). e2e_tgfake.sh drives /start + every menu button incl. the ex-bugs (menu_help, noop) and asserts the transcript.
This commit is contained in:
1 parent
0607ee488a
commit
b74200985a
2 files changed
+59
-1
No files matched your search
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
# e2e кнопок бота через tgfake — локальный Telegram Bot API стенд без живого
|
||||
# Telegram: https://github.com/EvilFreelancer/tgfake
|
||||
# Требует: tgfake запущен на $TGFAKE_URL (./tgfake -addr 127.0.0.1:18820),
|
||||
# приложение MusicGrabber доступно на $MUSICGRABBER_API_URL.
|
||||
set -euo pipefail
|
||||
TGFAKE_URL=${TGFAKE_URL:-http://127.0.0.1:18820}
|
||||
MUSICGRABBER_API_URL=${MUSICGRABBER_API_URL:-http://127.0.0.1:8765}
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
T=$TGFAKE_URL/sim
|
||||
|
||||
fail() { echo "FAIL: $1"; curl -s "$T/chat/4242?format=text" | tail -25; exit 1; }
|
||||
tap() { curl -s -X POST "$T/callback" -d "{\"label\": \"$1\"}" >/dev/null; sleep 2; }
|
||||
chat() { curl -s "$T/chat/4242?format=text"; }
|
||||
|
||||
curl -s -m 3 "$T/state" >/dev/null || fail "tgfake не отвечает на $TGFAKE_URL"
|
||||
curl -s -X POST "$T/reset" >/dev/null
|
||||
rm -f /tmp/e2e_bot.db
|
||||
TELEGRAM_BOT_TOKEN=123456:AAEtestE2Etoken000000000000000 \
|
||||
TELEGRAM_API_URL=$TGFAKE_URL MUSICGRABBER_API_URL=$MUSICGRABBER_API_URL \
|
||||
TELEGRAM_BOT_DB=/tmp/e2e_bot.db \
|
||||
python3 "$DIR/telegram_bot.py" >/tmp/e2e_bot.log 2>&1 &
|
||||
BOT=$!
|
||||
trap 'kill $BOT 2>/dev/null' EXIT
|
||||
sleep 4
|
||||
|
||||
curl -s -X POST "$T/message" -d '{"text": "/start"}' >/dev/null
|
||||
sleep 2
|
||||
chat | grep -q 'Поиск музыки' || fail "/start не дал меню"
|
||||
|
||||
tap '❓ Помощь'
|
||||
chat | grep -q 'Как пользоваться' || fail "кнопка Помощь не ответила (бага menu_help)"
|
||||
chat | grep -q 'Поиск музыки' || fail "у Помощи нет клавиатуры главного меню"
|
||||
|
||||
tap '⚙️ Настройки'
|
||||
chat | grep -q 'Источник' || fail "Настройки не открылись"
|
||||
|
||||
tap '🔊 Источник: Все источники'
|
||||
chat | grep -q 'Источник: YouTube' || fail "переключение источника не сработало"
|
||||
|
||||
tap '🎼 Качество: Оригинал'
|
||||
chat | grep -q 'Качество: FLAC' || fail "переключение FLAC не сработало"
|
||||
|
||||
tap '◀️ Назад'
|
||||
chat | grep -q 'Выберите действие' || fail "Назад не вернул в меню"
|
||||
|
||||
# noop-строка (завершённая задача в /queue): чат не меняется, но не зависает
|
||||
curl -s -X POST "$T/callback" -d '{"data": "noop"}' >/dev/null
|
||||
sleep 2
|
||||
chat | grep -q 'Выберите действие' || fail "noop сломал сообщение"
|
||||
|
||||
echo "OK: e2e кнопок через tgfake пройден"
|
||||
+7
-1
@@ -977,7 +977,13 @@ def setup_bot():
|
||||
|
||||
# Create application. concurrent_updates: a slow handler (httpx to the app,
|
||||
# up to 30s timeout) must not block answering other button presses.
|
||||
app = Application.builder().token(TELEGRAM_BOT_TOKEN).concurrent_updates(True).build()
|
||||
builder = Application.builder().token(TELEGRAM_BOT_TOKEN).concurrent_updates(True)
|
||||
# Local Bot API stand (e.g. tgfake) for e2e tests without real Telegram
|
||||
api_url = os.getenv("TELEGRAM_API_URL")
|
||||
if api_url:
|
||||
# PTB expects the full prefix incl. /bot (default https://api.telegram.org/bot)
|
||||
builder = builder.base_url(api_url.rstrip("/") + "/bot")
|
||||
app = builder.build()
|
||||
|
||||
# Command handlers
|
||||
app.add_handler(CommandHandler("start", cmd_start))
|
||||
|
||||
Reference in new issue
Block a user