dr.botzo/tests/test_dice_ircplugin.py
2025-02-08 23:57:23 -06:00

63 lines
2.5 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""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.source = 'test!test@test'
mock_event.target = '#test'
mock_event.recursing = False
# general task roll
mock_event.arguments = ['!cypher T3']
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, mock_event.arguments[0])
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)'
)
# unknown target roll
mock_event.arguments = ['!cypher +1']
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, mock_event.arguments[0])
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)'
)
# no mod or known difficulty
mock_event.arguments = ['!cypher unmodded attempt']
match = re.search(dice.ircplugin.CYPHER_COMMAND_REGEX, mock_event.arguments[0])
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
with mock.patch('random.SystemRandom.randint', return_value=9):
self.plugin.handle_cypher_roll(self.mock_connection, mock_event, match)
self.mock_bot.reply.assert_called_with(
mock_event,
'test: unmodded attempt beats a difficulty 3 task. 14(d20=9)'
)