diff --git a/chatterbot/ext/django_chatterbot/models.py b/chatterbot/ext/django_chatterbot/models.py index 98f0f6df0..87984da99 100644 --- a/chatterbot/ext/django_chatterbot/models.py +++ b/chatterbot/ext/django_chatterbot/models.py @@ -146,3 +146,15 @@ def __str__(self): statement if len(statement) <= 20 else statement[:17] + '...', response if len(response) <= 40 else response[:37] + '...' ) + + def serialize(self): + """ + :returns: A dictionary representation of the statement object. + :rtype: dict + """ + data = {} + + data['text'] = self.response.text + data['occurrence'] = self.occurrence + + return data diff --git a/tests_django/integration_tests/test_statement_integration.py b/tests_django/integration_tests/test_statement_integration.py index 32ee9f3a1..8b29d5a4c 100644 --- a/tests_django/integration_tests/test_statement_integration.py +++ b/tests_django/integration_tests/test_statement_integration.py @@ -3,6 +3,7 @@ from chatterbot.conversation import Statement as StatementObject from chatterbot.conversation import Response as ResponseObject from chatterbot.ext.django_chatterbot.models import Statement as StatementModel +from chatterbot.ext.django_chatterbot.models import Response as ResponseModel class StatementIntegrationTestCase(TestCase): @@ -82,3 +83,25 @@ def test_serialize(self): def test_response_statement_cache(self): self.assertTrue(hasattr(self.object, 'response_statement_cache')) self.assertTrue(hasattr(self.model, 'response_statement_cache')) + + +class ResponseIntegrationTestCase(TestCase): + + """ + Test case to make sure that the Django Response model + and ChatterBot Response object have a common interface. + """ + + def setUp(self): + super(ResponseIntegrationTestCase, self).setUp() + date_created = timezone.now() + statement_object = StatementObject(text='_', created_at=date_created) + statement_model = StatementModel.objects.create(text='_', created_at=date_created) + self.object = ResponseObject(statement_object.text) + self.model = ResponseModel(statement=statement_model, response=statement_model) + + def test_serialize(self): + object_data = self.object.serialize() + model_data = self.model.serialize() + + self.assertEqual(object_data, model_data)