diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dde2b33..aeb23ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,11 +17,11 @@ repos: - id: reorder-python-imports args: [--py310-plus, --add-import, 'from __future__ import annotations'] - repo: https://github.com/hhatto/autopep8 - rev: v2.0.4 + rev: v2.2.0 hooks: - id: autopep8 - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 args: ['--ignore=E501'] diff --git a/cs2posts/bot/options.py b/cs2posts/bot/options.py index cbcdffe..efe0cc1 100644 --- a/cs2posts/bot/options.py +++ b/cs2posts/bot/options.py @@ -89,9 +89,12 @@ def create_text(chat: Chat) -> str: return (f"Options\n\n" "Handle the automatically send Counter-Strike post notifications.\n\n" - f"{icon_is_update_interested} - Send Update Posts ({text_enabled_update})\n" - f"{icon_is_news_interested} - Send News Posts ({text_enabled_news})\n" - f"{icon_is_external_news_interested} - Send External News Posts ({text_enabled_external_news})\n\n" + f"{icon_is_update_interested} - Send Update Posts (" + f"{text_enabled_update})\n" + f"{icon_is_news_interested} - Send News Posts (" + f"{text_enabled_news})\n" + f"{icon_is_external_news_interested} - Send External News Posts (" + f"{text_enabled_external_news})\n\n" f"Select an option to change, or press 'Close' to keep everything as it is.") diff --git a/cs2posts/bot/spam.py b/cs2posts/bot/spam.py index e7918ab..7e7eef0 100644 --- a/cs2posts/bot/spam.py +++ b/cs2posts/bot/spam.py @@ -22,7 +22,7 @@ def warning(chat: Chat, max_strikes: int) -> str: @staticmethod def banned(chat: Chat, timout: int, max_strikes: int) -> str: - return f"Strike ({chat.strikes}/{max_strikes}) Chat is now banned for spamming (Timeout: {int(timout/60)} mins)." + return f"Strike ({chat.strikes}/{max_strikes}) Chat is now banned for spamming (Timeout: {int(timout / 60)} mins)." class SpamProtector: diff --git a/requirements-dev.txt b/requirements-dev.txt index 0c65a91..428709c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -9,3 +9,4 @@ pytest-asyncio==0.23.6 pytest-mock==3.14.0 pytest-cov==5.0.0 flake8==7.0.0 +pre-commit diff --git a/tests/bot/test_cs2bot.py b/tests/bot/test_cs2bot.py index 3dd5566..2a2ecdf 100644 --- a/tests/bot/test_cs2bot.py +++ b/tests/bot/test_cs2bot.py @@ -64,14 +64,14 @@ def bot(mocked_crawler, mocked_post_store, mocked_chat_store, mocked_spam_protec def test_cs2_bot_init_no_files(bot): bot.local_chat_store.is_empty.return_value = True - bot.local_chat_store.is_empty.called_once() - bot.local_chat_store.save.called_once() + bot.local_chat_store.is_empty.assert_called() + bot.local_chat_store.save.assert_called() bot.local_post_store.is_empty.return_value = True - bot.local_post_store.is_empty.called_once() - bot.crawler.crawl.called_once() - bot.local_post_store.save.called_once() - bot.local_chat_store.save.called_once() + bot.local_post_store.is_empty.assert_called() + bot.crawler.crawl.assert_called() + bot.local_post_store.save.assert_called() + bot.local_chat_store.save.assert_called() # TODO finish up setup @@ -163,8 +163,8 @@ async def test_cs2_bot_left_chat_member_bot_left(bot): bot.local_chat_store.reset_mock() await bot.left_chat_member(mocked_update, mocked_context) - bot.chats.remove.called_once_with(chat) - bot.local_chat_store.save.called_once() + bot.chats.remove.assert_called_once_with(chat) + bot.local_chat_store.save.assert_called_once() @pytest.mark.asyncio diff --git a/tests/bot/test_message.py b/tests/bot/test_message.py index bd71e05..59b24d5 100644 --- a/tests/bot/test_message.py +++ b/tests/bot/test_message.py @@ -111,5 +111,5 @@ async def test_telegram_message_send_update(mocked_cs2_update_post): await msg.send(bot=mocked_bot, chat_id=1337) - assert mocked_bot.send_photo.not_called - assert mocked_bot.send_message.called + mocked_bot.send_photo.assert_not_called() + mocked_bot.send_message.assert_called() diff --git a/tests/bot/test_spam.py b/tests/bot/test_spam.py index 94cf382..ff36740 100644 --- a/tests/bot/test_spam.py +++ b/tests/bot/test_spam.py @@ -6,6 +6,7 @@ from zoneinfo import ZoneInfo import pytest +from telegram.constants import ParseMode from cs2posts.bot import settings from cs2posts.bot.chats import Chat @@ -139,19 +140,25 @@ async def test_spam_protector_strike(spam_protector, chat): chat.is_banned = False await spam_protector.strike(mock_bot, chat) assert chat.strikes == 1 - assert await mock_bot.send_message.called_once_with( - chat.chat_id, - SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES)) + mock_bot.send_message.assert_called_once_with( + chat_id=chat.chat_id, + text=SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES), + parse_mode=ParseMode.HTML) + mock_bot.reset_mock() await spam_protector.strike(mock_bot, chat) assert chat.strikes == 2 - assert await mock_bot.send_message.called_once_with( - chat.chat_id, - SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES)) + mock_bot.send_message.assert_called_once_with( + chat_id=chat.chat_id, + text=SpamProtectorMessages.warning(chat, settings.CHAT_MAX_STRIKES), + parse_mode=ParseMode.HTML) + mock_bot.reset_mock() await spam_protector.strike(mock_bot, chat) assert chat.strikes == 3 - assert await mock_bot.send_message.called_once_with( - chat.chat_id, - SpamProtectorMessages.banned(chat, settings.CHAT_BAN_TIMEOUT_SECONDS, settings.CHAT_MAX_STRIKES)) + mock_bot.send_message.assert_called_once_with( + chat_id=chat.chat_id, + text=SpamProtectorMessages.banned( + chat, settings.CHAT_BAN_TIMEOUT_SECONDS, settings.CHAT_MAX_STRIKES), + parse_mode=ParseMode.HTML) assert chat.is_banned