~netlandish/django-wiki

8798972f44e89866d84194b406ed2581c5ba8501 — Benjamin Bach 6 years ago 312e561 + 59de1fd
Merge pull request #808 from atombrella/forms_tests

Increased test coverage for UserCreation and DeleteForm.
2 files changed, 30 insertions(+), 7 deletions(-)

M src/wiki/forms.py
A tests/core/test_forms.py
M src/wiki/forms.py => src/wiki/forms.py +3 -7
@@ 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()

A tests/core/test_forms.py => tests/core/test_forms.py +27 -0
@@ 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."]
        )