Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

206 follow up checkbox default value #270

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions django_comments_xtd/conf/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ def username(u):
# Rewrite this function to make the web API use a different logic.
# Should return an URL.
COMMENTS_XTD_API_GET_USER_AVATAR = "django_comments_xtd.utils.get_user_avatar"

COMMENTS_XTD_DEFAULT_FOLLOW_UP = False
1 change: 1 addition & 0 deletions django_comments_xtd/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, *args, **kwargs):
self.fields['followup'].widget.attrs['id'] = (
'id_followup%s' % followup_suffix)
self.fields['followup'].widget.attrs['class'] = "custom-control-input"
self.fields['followup'].initial = settings.COMMENTS_XTD_DEFAULT_FOLLOW_UP

def get_comment_model(self):
return TmpXtdComment
Expand Down
20 changes: 20 additions & 0 deletions django_comments_xtd/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from django_comments_xtd.forms import XtdCommentForm
from django_comments_xtd.tests.models import Article

try:
from unittest.mock import patch
except ImportError:
from mock import patch


class GetFormTestCase(TestCase):

Expand Down Expand Up @@ -40,3 +45,18 @@ def test_get_comment_create_data(self):

# it does have the new field 'followup'
self.assertTrue("followup" in comment)

@patch.multiple('django_comments_xtd.conf.settings',
COMMENTS_XTD_DEFAULT_FOLLOW_UP=False)
def test_followup_prechecked(self):
# Have to update form ubject to re-initialize 'followup' checkbox with settings.
self.form = django_comments.get_form()(self.article)
self.assertEqual(self.form.fields['followup'].initial, False)

@patch.multiple('django_comments_xtd.conf.settings',
COMMENTS_XTD_DEFAULT_FOLLOW_UP=True)
def test_followup_preunchecked(self):
# Have to update form ubject to re-initialize 'followup' checkbox with settings.
self.form = django_comments.get_form()(self.article)
self.assertEqual(self.form.fields['followup'].initial, True)