dr.botzo/tests/test_markov_ircplugin.py

36 lines
1.2 KiB
Python
Raw Normal View History

"""Test IRC behavior of the markov plugin."""
from unittest import mock
from django.test import TestCase
from ircbot.models import IrcServer
from markov.ircplugin import Markov
class MarkovTestCase(TestCase):
"""Test the markov plugin."""
fixtures = ['tests/fixtures/irc_server_fixture.json']
def setUp(self):
"""Create common objects."""
self.mock_bot = mock.MagicMock()
self.mock_connection = mock.MagicMock()
self.mock_connection.get_nickname.return_value = 'test_bot'
self.mock_connection.server_config = IrcServer.objects.get(pk=1)
self.plugin = Markov(self.mock_bot, self.mock_connection, mock.MagicMock())
def test_learn(self):
"""Test that an IRC event triggers learning as expected."""
mock_event = mock.MagicMock()
mock_event.arguments = ['hello this is a test message']
mock_event.target = '#test'
mock_event.recursing = False
with mock.patch('markov.lib.learn_line') as mock_learn_line:
self.plugin.handle_chatter(self.mock_connection, mock_event)
self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message')