49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
|
"""Test IRC behavior of the dice plugin."""
|
|||
|
import re
|
|||
|
from unittest import mock
|
|||
|
|
|||
|
from django.test import TestCase
|
|||
|
|
|||
|
import dice.ircplugin
|
|||
|
from ircbot.models import IrcServer
|
|||
|
|
|||
|
|
|||
|
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 = dice.ircplugin.Dice(self.mock_bot, self.mock_connection, mock.MagicMock())
|
|||
|
|
|||
|
def test_cypher_roll_strings(self):
|
|||
|
"""Simulate incoming Cypher System requests."""
|
|||
|
mock_event = mock.MagicMock()
|
|||
|
mock_event.arguments = ['!cypher T3']
|
|||
|
mock_event.source = 'test!test@test'
|
|||
|
mock_event.target = '#test'
|
|||
|
mock_event.recursing = False
|
|||
|
|
|||
|
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, '!cypher T3')
|
|||
|
with mock.patch('random.SystemRandom.randint', return_value=17):
|
|||
|
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
|
|||
|
self.mock_bot.reply.assert_called_with(
|
|||
|
mock_event,
|
|||
|
'test: your check 9succeeded, with +1 damage! 14(d20=17 vs. diff. 3)'
|
|||
|
)
|
|||
|
|
|||
|
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, '!cypher +1')
|
|||
|
with mock.patch('random.SystemRandom.randint', return_value=17):
|
|||
|
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
|
|||
|
self.mock_bot.reply.assert_called_with(
|
|||
|
mock_event,
|
|||
|
'test: your check beats a difficulty 4 task, with +1 damage! 14(d20=17 with +1 levels)'
|
|||
|
)
|