From 59de1fdd840f4a5d0d6cacedd9923be6ef9b08f6 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Tue, 20 Feb 2018 20:50:59 +0100 Subject: [PATCH] Increased test coverage for UserCreation and DeleteForm. This also reverts some auto-pep8 in those two forms. --- src/wiki/forms.py | 10 +++------- tests/core/test_forms.py | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 tests/core/test_forms.py diff --git a/src/wiki/forms.py b/src/wiki/forms.py index 987c22fb..4cf6ef46 100644 --- a/src/wiki/forms.py +++ b/src/wiki/forms.py @@ -408,8 +408,7 @@ class DeleteForm(forms.Form): self.has_children = kwargs.pop('has_children') super().__init__(*args, **kwargs) - confirm = forms.BooleanField(required=False, - label=_('Yes, I am sure')) + confirm = forms.BooleanField(required=False, label=_('Yes, I am sure')) purge = forms.BooleanField( widget=HiddenInput(), required=False, label=_('Purge'), @@ -424,8 +423,7 @@ class DeleteForm(forms.Form): raise forms.ValidationError(gettext('You are not sure enough!')) if cd['revision'] != self.article.current_revision: raise forms.ValidationError( - gettext( - 'While you tried to delete this article, it was modified. TAKE CARE!')) + gettext('While you tried to delete this article, it was modified. TAKE CARE!')) return cd @@ -510,9 +508,7 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm): self.fields['group_write'].widget = forms.HiddenInput() if not self.can_assign: - self.fields['owner_username'].widget = forms.TextInput( - attrs={ - 'readonly': 'true'}) + self.fields['owner_username'].widget = forms.TextInput(attrs={'readonly': 'true'}) self.fields['recursive'].widget = forms.HiddenInput() self.fields['recursive_group'].widget = forms.HiddenInput() self.fields['recursive_owner'].widget = forms.HiddenInput() diff --git a/tests/core/test_forms.py b/tests/core/test_forms.py new file mode 100644 index 00000000..d4d18651 --- /dev/null +++ b/tests/core/test_forms.py @@ -0,0 +1,27 @@ +from django.test import TestCase +from django.utils.translation import gettext + +from tests.base import DjangoClientTestBase, RequireRootArticleMixin +from wiki.forms import DeleteForm, UserCreationForm + + +class DeleteFormTests(RequireRootArticleMixin, DjangoClientTestBase): + def test_not_sure(self): + data = {'purge': True, 'confirm': False} + form = DeleteForm(article=self.root_article, has_children=True, data=data) + self.assertIs(form.is_valid(), False) + self.assertEqual(form.errors['__all__'], [gettext('You are not sure enough!')]) + + +class UserCreationFormTests(TestCase): + def test_honeypot(self): + data = { + 'address': 'Wiki Road 123', 'phone': '12345678', 'email': 'wiki@wiki.com', + 'username': 'WikiMan', 'password1': 'R@ndomString', 'password2': 'R@ndomString' + } + form = UserCreationForm(data=data) + self.assertIs(form.is_valid(), False) + self.assertEqual( + form.errors['__all__'], + ["Thank you, non-human visitor. Please keep trying to fill in the form."] + ) -- 2.45.2