Skip to content

Commit

Permalink
Avoid duplication of mention id in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
unode committed Sep 13, 2022
1 parent 641b918 commit 3fc88ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tests/unit_tests/event_handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
from mmpy_bot.plugins import PluginManager
from mmpy_bot.wrappers import WebHookEvent

BOT_ID = "qmw86q7qsjriura9jos75i4why"


def create_message(
text="hello",
mentions=["qmw86q7qsjriura9jos75i4why"],
mentions=[BOT_ID],
channel_type="O",
sender_name="betty",
channel_name="off-topic",
Expand Down
10 changes: 5 additions & 5 deletions tests/unit_tests/function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mmpy_bot.webhook_server import NoResponse
from mmpy_bot.wrappers import WebHookEvent

from .event_handler_test import create_message
from .event_handler_test import BOT_ID, create_message


class TestFunction:
Expand Down Expand Up @@ -142,7 +142,7 @@ def mocked_reply(message, response):
f(create_message(), "-f --arg2=no --nonexistent-arg")
mock_function.assert_called_once()

@mock.patch("mmpy_bot.driver.Driver.user_id", "qmw86q7qsjriura9jos75i4why")
@mock.patch("mmpy_bot.driver.Driver.user_id", BOT_ID)
def test_needs_mention(self): # noqa
wrapped = mock.create_autospec(example_listener)
wrapped.__qualname__ = "wrapped"
Expand All @@ -151,7 +151,7 @@ def test_needs_mention(self): # noqa
f.plugin.initialize(Driver(), PluginManager([f.plugin]), Settings())

# The default message mentions the specified user ID, so should be called
f(create_message(mentions=["qmw86q7qsjriura9jos75i4why"]))
f(create_message(mentions=[BOT_ID]))
wrapped.assert_called_once()
wrapped.reset_mock()

Expand All @@ -163,14 +163,14 @@ def test_needs_mention(self): # noqa
f(create_message(mentions=[], channel_type="D"))
wrapped.assert_called_once()

@mock.patch("mmpy_bot.driver.Driver.user_id", "qmw86q7qsjriura9jos75i4why")
@mock.patch("mmpy_bot.driver.Driver.user_id", BOT_ID)
def test_direct_only(self):
wrapped = mock.create_autospec(example_listener)
wrapped.__qualname__ = "wrapped"
f = listen_to("", direct_only=True)(wrapped)

# A mention is not a direct message, so shouldn't trigger
f(create_message(mentions=["qmw86q7qsjriura9jos75i4why"], channel_type="O"))
f(create_message(mentions=[BOT_ID], channel_type="O"))
wrapped.assert_not_called()

f(create_message(mentions=[], channel_type="D"))
Expand Down

0 comments on commit 3fc88ca

Please sign in to comment.