Skip to content

Commit

Permalink
Fully set up Django factories
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Jan 31, 2018
1 parent 6dc79e0 commit 38f33ed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
3 changes: 3 additions & 0 deletions chatterbot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
'''
STATEMENT_TEXT_MAX_LENGTH = 400

# The maximum length of characters that the name of a tag can contain
TAG_NAME_MAX_LENGTH = 50

DEFAULT_DJANGO_APP_NAME = 'django_chatterbot'
7 changes: 1 addition & 6 deletions chatterbot/ext/django_chatterbot/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,6 @@ class AbstractBaseResponse(models.Model):
on_delete=models.CASCADE
)

created_at = models.DateTimeField(
default=timezone.now,
help_text='The date and time that this statement was created at.'
)

created_at = models.DateTimeField(
default=timezone.now,
help_text='The date and time that this response was created at.'
Expand Down Expand Up @@ -251,7 +246,7 @@ class AbstractBaseTag(models.Model):
"""

name = models.SlugField(
max_length=50
max_length=constants.TAG_NAME_MAX_LENGTH
)

statements = models.ManyToManyField(
Expand Down
31 changes: 27 additions & 4 deletions chatterbot/ext/django_chatterbot/factories.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
"""
These factories are used to generate fake data for testing.
"""
import factory
from chatterbot.ext.django_chatterbot import models
from chatterbot import constants
from factory.django import DjangoModelFactory
from factory import fuzzy


class StatementFactory(DjangoModelFactory):

text = fuzzy.FuzzyText(length=50)
text = factory.Faker(
'text',
max_nb_chars=constants.STATEMENT_TEXT_MAX_LENGTH
)

class Meta:
model = 'chatterbot.ext.django_chatterbot.Statement'
model = models.Statement


class ResponseFactory(DjangoModelFactory):

statement = factory.SubFactory(StatementFactory)

response = factory.SubFactory(StatementFactory)

class Meta:
model = models.Response


class ConversationFactory(DjangoModelFactory):

class Meta:
model = 'chatterbot.ext.django_chatterbot.Conversation'
model = models.Conversation


class TagFactory(DjangoModelFactory):

name = factory.Faker('word')

class Meta:
model = models.Tag

0 comments on commit 38f33ed

Please sign in to comment.