add test to confirm markov irc plugin behavior
This commit is contained in:
parent
8549c2ef8a
commit
363ec49097
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,7 +15,6 @@ megahal.*
|
||||
dr.botzo.log
|
||||
dr.botzo.markov
|
||||
*.facts
|
||||
*.json
|
||||
*.log
|
||||
*.pyc
|
||||
*.sqlite3
|
||||
|
36
tests/fixtures/irc_server_fixture.json
vendored
Normal file
36
tests/fixtures/irc_server_fixture.json
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
[
|
||||
{
|
||||
"model": "ircbot.ircserver",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"name": "Localhost",
|
||||
"hostname": "localhost",
|
||||
"port": 6697,
|
||||
"password": null,
|
||||
"nickname": "test_bot",
|
||||
"realname": "test_bot",
|
||||
"additional_addressed_nicks": "",
|
||||
"use_ssl": true,
|
||||
"use_ipv6": true,
|
||||
"post_connect": "",
|
||||
"delay_before_joins": 5,
|
||||
"xmlrpc_host": "localhost",
|
||||
"xmlrpc_port": 13132,
|
||||
"replace_irc_control_with_markdown": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "ircbot.ircchannel",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"name": "#test",
|
||||
"server": 1,
|
||||
"autojoin": true,
|
||||
"topic_msg": "",
|
||||
"topic_time": "2022-09-09T18:28:29Z",
|
||||
"topic_by": "",
|
||||
"markov_learn_from_channel": true,
|
||||
"discord_bridge": "bridge"
|
||||
}
|
||||
}
|
||||
]
|
35
tests/test_markov_ircplugin.py
Normal file
35
tests/test_markov_ircplugin.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""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')
|
Loading…
Reference in New Issue
Block a user