diff --git a/test/test_yelling.py b/test/test_yelling.py index ad618e8e..fd9daef6 100644 --- a/test/test_yelling.py +++ b/test/test_yelling.py @@ -1,4 +1,4 @@ -from test.conftest import MockUQCSBot, TEST_CHANNEL_ID +from test.conftest import MockUQCSBot, TEST_CHANNEL_ID, TEST_USER_ID from unittest.mock import patch from typing import Mapping, TypeVar, Generator, Any, List @@ -30,92 +30,88 @@ def count_lowercase_msgs(uqcsbot): @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: True) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_minuscule(uqcsbot: MockUQCSBot): """ test minuscule string """ - uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute") + uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 2 @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: True) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_majuscule(uqcsbot: MockUQCSBot): """ test majuscule string """ - uqcsbot.post_message(TEST_CHANNEL_ID, "WINTERMUTE") + uqcsbot.post_message(TEST_CHANNEL_ID, "WINTERMUTE", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 1 @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: True) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_mixed(uqcsbot: MockUQCSBot): """ test mixed case string """ - uqcsbot.post_message(TEST_CHANNEL_ID, "wiNTErMUTe") + uqcsbot.post_message(TEST_CHANNEL_ID, "wiNTErMUTe", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 2 @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: False) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_channel(uqcsbot: MockUQCSBot): """ tests outside of #yeling """ - uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute") + uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 1 @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: True) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_thread_discreet_minuscule(uqcsbot: MockUQCSBot): """ test minuscule string reply to thread """ - uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER") + uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 1 thread = float(uqcsbot.test_messages.get(TEST_CHANNEL_ID, [])[-1].get('ts', 0)) - uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute", reply_broadcast=False, thread_ts=thread) + uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute", + reply_broadcast=False, thread_ts=thread, user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 3 @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: True) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_thread_discreet_majuscule(uqcsbot: MockUQCSBot): """ test majuscule string reply to thread """ - uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER") + uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 1 thread = float(uqcsbot.test_messages.get(TEST_CHANNEL_ID, [])[-1].get('ts', 0)) - uqcsbot.post_message(TEST_CHANNEL_ID, "WINTERMUTE", reply_broadcast=False, thread_ts=thread) + uqcsbot.post_message(TEST_CHANNEL_ID, "WINTERMUTE", + reply_broadcast=False, thread_ts=thread, user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 2 @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: True) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_thread_blatant_minuscule(uqcsbot: MockUQCSBot): """ test minuscule string reply to thread and channel """ - uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER") + uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 1 thread = float(uqcsbot.test_messages.get(TEST_CHANNEL_ID, [])[-1].get('ts', 0)) - uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute", reply_broadcast=True, thread_ts=thread) + uqcsbot.post_message(TEST_CHANNEL_ID, "wintermute", + reply_broadcast=True, thread_ts=thread, user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 3 @patch("uqcsbot.scripts.yelling.in_yelling", new=lambda chan: True) -@patch("uqcsbot.scripts.yelling.is_human", new=lambda chan: True) def test_thread_blatant_majuscule(uqcsbot: MockUQCSBot): """ test majuscule string reply to thread and channel """ - uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER") + uqcsbot.post_message(TEST_CHANNEL_ID, "NEUROMANCER", user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 1 thread = float(uqcsbot.test_messages.get(TEST_CHANNEL_ID, [])[-1].get('ts', 0)) - uqcsbot.post_message(TEST_CHANNEL_ID, "WINTERMUTE", reply_broadcast=True, thread_ts=thread) + uqcsbot.post_message(TEST_CHANNEL_ID, "WINTERMUTE", + reply_broadcast=True, thread_ts=thread, user=TEST_USER_ID) assert count_lowercase_msgs(uqcsbot) == 2 diff --git a/uqcsbot/scripts/yelling.py b/uqcsbot/scripts/yelling.py index 9dc57af3..d1426e97 100644 --- a/uqcsbot/scripts/yelling.py +++ b/uqcsbot/scripts/yelling.py @@ -13,14 +13,6 @@ def in_yelling(channel): return chan and (chan.name == "yelling" or chan.name == "cheering") -def is_human(user): - """ - checks that the user is not a bot - exists for test mocking - """ - return user is not None and not user.is_bot - - def mutate_minuscule(message: str) -> str: """ Randomly mutates 40% of minuscule letters to other minuscule letters @@ -62,7 +54,7 @@ def yelling(event: dict): # ensure user proper user = bot.users.get(event.get("user")) - if not is_human(user): + if user is None or user.is_bot: return # ignore emoji