Auto-update existing Telegram bot during upgrade

This commit is contained in:
Виталий Литвинов
2026-04-26 10:51:30 +03:00
parent ffea9f5d77
commit 7bb88f2c24
2 changed files with 44 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
BOT_PATH = ROOT / "gotelegram-bot" / "bot.py"
CATALOG_PATH = ROOT / "templates_catalog.json"
INSTALL_PATH = ROOT / "install.sh"
class BotFeatureTests(unittest.TestCase):
@@ -79,6 +80,23 @@ class BotFeatureTests(unittest.TestCase):
self.assertIn("await get_telemt_version()", body)
self.assertNotIn('sh("telemt", "--version")', body)
def test_installer_auto_updates_existing_bot_files(self):
source = INSTALL_PATH.read_text(encoding="utf-8")
auto_body = re.search(
r"auto_update_bot_if_possible\(\).*?(?=\n\n[A-Za-z0-9_]+\(\) |\n\n#)",
source,
flags=re.S,
)
self.assertIsNotNone(auto_body)
auto_text = auto_body.group(0)
self.assertIn('bot_service_status', auto_text)
self.assertIn('bot_install', auto_text)
self.assertIn('cmp -s "$SCRIPT_DIR/gotelegram-bot/bot.py" "$BOT_DIR/bot.py"', auto_text)
self.assertIn('cmp -s "$SCRIPT_DIR/gotelegram-bot/i18n.py" "$BOT_DIR/i18n.py"', auto_text)
self.assertIn('cmp -s "$SCRIPT_DIR/gotelegram-bot/requirements.txt" "$BOT_DIR/requirements.txt"', auto_text)
self.assertIn('auto_migrate_legacy_state || true\n auto_update_bot_if_possible || true\n auto_install_admin_web_if_possible || true', source)
if __name__ == "__main__":
unittest.main()