Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_command_data_argument(self):
out = StringIO()
statements_before = Statement.objects.exists()
call_command('train', stdout=out)
statements_after = Statement.objects.exists()
self.assertFalse(statements_before)
self.assertTrue(statements_after)
def test_command_data_argument(self):
out = StringIO()
statements_before = Statement.objects.exists()
call_command('train', stdout=out)
statements_after = Statement.objects.exists()
self.assertFalse(statements_before)
self.assertTrue(statements_after)
def test_output_adapter(self):
from chatterbot.output import OutputAdapter
adapter = OutputAdapter(self.chatbot)
statement = Statement(text='_')
result = adapter.process_response(statement)
self.assertEqual(result.text, '_')
def test_update_adds_new_statement(self):
statement = Statement(text="New statement")
self.adapter.update(statement)
results = list(self.adapter.filter(text="New statement"))
self.assertEqual(len(results), 1)
self.assertEqual(results[0].text, statement.text)
def setUp(self):
super().setUp()
from datetime import datetime
from pytz import UTC
now = datetime(2020, 2, 15, 3, 14, 10, 0, UTC)
self.object = StatementObject(text='_', created_at=now)
self.model = StatementModel(text='_', created_at=now)
# Simulate both statements being saved
self.model.save()
self.object.id = self.model.id
class StatementAdmin(admin.ModelAdmin):
list_display = ('text', )
list_filter = ('text', )
search_fields = ('text', )
class ResponseAdmin(admin.ModelAdmin):
list_display = ('statement', 'occurrence', )
class ConversationAdmin(admin.ModelAdmin):
pass
admin.site.register(Statement, StatementAdmin)
admin.site.register(Response, ResponseAdmin)
admin.site.register(Conversation, ConversationAdmin)
def remove(self, statement_text):
"""
Removes the statement that matches the input text.
Removes any responses from statements if the response text matches the
input text.
"""
from chatterbot.ext.django_chatterbot.models import Statement
from chatterbot.ext.django_chatterbot.models import Response
from django.db.models import Q
statements = Statement.objects.filter(text=statement_text)
responses = Response.objects.filter(
Q(statement__text=statement_text) | Q(response__text=statement_text)
)
responses.delete()
statements.delete()
from django.contrib import admin
from chatterbot.ext.django_chatterbot.model_admin import StatementAdmin, TagAdmin
from chatterbot.ext.django_chatterbot.models import Statement, Tag
admin.site.register(Statement, StatementAdmin)
admin.site.register(Tag, TagAdmin)
def find(self, statement_text):
from chatterbot.ext.django_chatterbot.models import Statement
try:
return Statement.objects.get(text=statement_text)
except Statement.DoesNotExist as e:
self.logger.info(str(e))
return None
def count(self):
from chatterbot.ext.django_chatterbot.models import Statement
return Statement.objects.count()