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

Fix occational test_yelling failures #546

Merged
merged 1 commit into from
Oct 3, 2020
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
38 changes: 17 additions & 21 deletions test/test_yelling.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
10 changes: 1 addition & 9 deletions uqcsbot/scripts/yelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down