Skip to content

Commit

Permalink
Add Django training view
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Nov 6, 2016
1 parent ad80f8c commit 77bb447
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
9 changes: 7 additions & 2 deletions chatterbot/ext/django_chatterbot/urls.py
@@ -1,12 +1,17 @@
from django.conf.urls import url
from django.contrib import admin
from .views import ChatterBotView
from chatterbot.ext.django_chatterbot import views


urlpatterns = [
url(
r'^$',
ChatterBotView.as_view(),
views.ChatterBotView.as_view(),
name='chatterbot',
),
url(
r'^/train/$',
views.ChatterBotTrainingView.as_view(),
name='train',
),
]
13 changes: 13 additions & 0 deletions chatterbot/ext/django_chatterbot/views.py
Expand Up @@ -68,3 +68,16 @@ def delete(self, request, *args, **kwargs):
# Return a method not allowed response
return JsonResponse(data, status=405)


class ChatterBotTrainingView(ChatterBotViewMixin, View):

def post(self, request, *args, **kwargs):

if request.is_ajax():
input_data = json.loads(request.read().decode('utf-8'))
else:
input_data = json.loads(request.body.decode('utf-8'))

self.chatterbot.train(input_data)

return JsonResponse(status=200)
Empty file added docs/django/training.rst
Empty file.
Empty file.
19 changes: 16 additions & 3 deletions examples/django_app/tests/test_views.py
@@ -1,12 +1,12 @@
from django.test import TestCase
from django.core.exceptions import ValidationError
from chatterbot.ext.django_chatterbot.views import ChatterBotView
from chatterbot.ext.django_chatterbot.views import ChatterBotView, ChatterBotTrainingView


class ViewTestCase(TestCase):
class ChatterBotViewTestCase(TestCase):

def setUp(self):
super(ViewTestCase, self).setUp()
super(ChatterBotViewTestCase, self).setUp()
self.view = ChatterBotView()

def test_validate_text(self):
Expand All @@ -22,3 +22,16 @@ def test_validate_invalid_text(self):
self.view.validate({
'type': 'classmethod'
})


class TrainingViewTestCase(TestCase):

def setUp(self):
super(TrainingViewTestCase, self).setUp()
self.view = ChatterBotTrainingView()

def test_invalid_training_data(self):
pass

def test_valid_training_data(self):
pass

0 comments on commit 77bb447

Please sign in to comment.