when creating a markov target, tie it to ircbot models

This commit is contained in:
2023-02-19 17:38:25 -06:00
parent 76a052e091
commit 0227b74eee
7 changed files with 111 additions and 31 deletions

View File

@@ -3,7 +3,7 @@ from unittest import mock
from django.test import TestCase
from ircbot.models import IrcServer
from ircbot.models import IrcChannel, IrcServer
from markov.ircplugin import Markov
@@ -100,3 +100,15 @@ class MarkovTestCase(TestCase):
self.plugin.handle_chatter(self.mock_connection, mock_event)
self.assertEqual(mock_learn_line.call_args.args[0], 'hello this is a test message')
def test_autocreate_ircchannel(self):
"""Test that we create the necessary config objects when seeing a target for the first time."""
self.assertEqual(IrcChannel.objects.filter(name='#fakechannel').count(), 0)
context = self.plugin.get_or_create_target_context('#fakechannel')
self.assertEqual(IrcChannel.objects.filter(name='#fakechannel').count(), 1)
self.assertIsNotNone(context)
self.assertIsNotNone(context.markovtarget_set)
self.assertIsNotNone(context.markovtarget_set.all()[0].channel)
self.assertEqual(context.markovtarget_set.all()[0].channel.name, '#fakechannel')
self.assertEqual(context.markovtarget_set.all()[0].name, '#fakechannel')