-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Django app settings to override ChatterBot settings.
- Loading branch information
1 parent
7b85cc3
commit adc1ed8
Showing
5 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
from django.conf import settings | ||
|
||
|
||
CHATTERBOT = { | ||
'NAME': 'ChatterBot' | ||
CHATTERBOT_SETTINGS = getattr(settings, 'CHATTERBOT', {}) | ||
|
||
CHATTERBOT_DEFAULTS = { | ||
'name': 'ChatterBot', | ||
'storage_adapter': 'chatterbot.adapters.storage.DjangoStorageAdapter', | ||
'input_adapter': 'chatterbot.adapters.input.VariableInputTypeAdapter', | ||
'output_adapter': 'chatterbot.adapters.output.OutputFormatAdapter', | ||
'output_format': 'json' | ||
} | ||
|
||
def patch_all(): | ||
setattr(settings, 'CHATTERBOT', CHATTERBOT) | ||
CHATTERBOT = CHATTERBOT_DEFAULTS.copy() | ||
CHATTERBOT.update(CHATTERBOT_SETTINGS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.test import TestCase | ||
from django.conf import settings | ||
|
||
|
||
class SettingsTestCase(TestCase): | ||
|
||
def test_modified_settings(self): | ||
with self.settings(CHATTERBOT={'name': 'Jim'}): | ||
self.assertIn('name', settings.CHATTERBOT) | ||
self.assertEqual('Jim', settings.CHATTERBOT['name']) | ||
|
||
def test_name_setting(self): | ||
from django.core.urlresolvers import reverse | ||
|
||
api_url = reverse('chatterbot:chatterbot') | ||
response = self.client.get(api_url) | ||
|
||
self.assertEqual(response.status_code, 405) | ||
self.assertIn('detail', response.json()) | ||
self.assertIn('name', response.json()) | ||
self.assertEqual('Django ChatterBot Example', response.json()['name']) |