Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.12 Support #19

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
9 changes: 6 additions & 3 deletions cs2posts/bot/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ def create_text(chat: Chat) -> str:

return (f"<b>Options</b>\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.")


Expand Down
2 changes: 1 addition & 1 deletion cs2posts/bot/spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<b>Strike ({chat.strikes}/{max_strikes})</b> Chat is now <b>banned</b> for spamming (Timeout: {int(timout/60)} mins)."
return f"<b>Strike ({chat.strikes}/{max_strikes})</b> Chat is now <b>banned</b> for spamming (Timeout: {int(timout / 60)} mins)."


class SpamProtector:
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions tests/bot/test_cs2bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/bot/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
25 changes: 16 additions & 9 deletions tests/bot/test_spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading