Compare commits

..

2 Commits

5 changed files with 63 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# Generated by Django 3.2.18 on 2023-02-19 23:14
# Generated by Django 3.2.18 on 2023-02-20 00:09
from django.db import migrations, models
import django.db.models.deletion

View File

@ -0,0 +1,24 @@
"""Generated by Django 3.2.18 on 2023-02-19 23:15."""
from django.db import migrations
def link_markovcontext_to_ircchannel(apps, schema_editor):
"""Link the markov targets to a hopefully matching channel, by name."""
IrcChannel = apps.get_model('ircbot', 'IrcChannel')
MarkovTarget = apps.get_model('markov', 'MarkovTarget')
for target in MarkovTarget.objects.all():
channel = IrcChannel.objects.get(name=target.name)
target.channel = channel
target.save()
class Migration(migrations.Migration):
"""Populate the markov target to IRC channel link."""
dependencies = [
('markov', '0005_markovtarget_channel'),
]
operations = [
migrations.RunPython(link_markovcontext_to_ircchannel)
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.2.18 on 2023-02-20 00:11
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('ircbot', '0019_ircchannel_discord_bridge'),
('markov', '0006_link_markovtarget_to_ircchannel'),
]
operations = [
migrations.AlterField(
model_name='markovtarget',
name='channel',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ircbot.ircchannel'),
),
]

View File

@ -23,7 +23,7 @@ class MarkovTarget(models.Model):
name = models.CharField(max_length=200, unique=True)
context = models.ForeignKey(MarkovContext, on_delete=models.CASCADE)
channel = models.ForeignKey(IrcChannel, null=True, on_delete=models.CASCADE)
channel = models.ForeignKey(IrcChannel, on_delete=models.CASCADE)
chatter_chance = models.IntegerField(default=0)

17
tests/test_markov_lib.py Normal file
View File

@ -0,0 +1,17 @@
"""Test markov utility methods."""
from django.test import TestCase
from markov.lib import get_word_out_of_states, learn_line
from markov.models import MarkovContext, MarkovState
class MarkovLibTestCase(TestCase):
"""Test library methods used by the Markov plugin."""
fixtures = ['tests/fixtures/irc_server_fixture.json', 'tests/fixtures/markov_fixture.json']
def test_learn_and_get(self):
"""Test that we can learn some lines and get a word back."""
learn_line("the elephant goes ERRRRRRRRRRRRR", MarkovContext.objects.get(pk=1))
word = get_word_out_of_states(MarkovState.objects.all())
self.assertIn(word, ['the', 'elephant', 'goes', 'ERRRRRRRRRRRRR', '__stop'])