Skip to content

Commit

Permalink
Fix occational test_yelling failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleysigma committed Oct 3, 2020
1 parent b833be1 commit 2147f7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
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

0 comments on commit 2147f7d

Please sign in to comment.