Ticket #12972: flatpages_admin_trunk.diff

File flatpages_admin_trunk.diff, 2.1 KB (added by jabapyth, 5 years ago)

now with tests!

  • django/contrib/flatpages/admin.py

     
    33from django.contrib.flatpages.models import FlatPage
    44from django.utils.translation import ugettext_lazy as _
    55
     6from django.conf import settings
    67
     8URL_REGEX = r'^/[-\w/]+$'
     9if settings.APPEND_SLASH and 'django.middleware.common.CommonMiddleware' in settings.MIDDLEWARE_CLASSES:
     10    URL_REGEX = r'^/[-\w/]+/$'
     11
    712class FlatpageForm(forms.ModelForm):
    8     url = forms.RegexField(label=_("URL"), max_length=100, regex=r'^[-\w/]+$',
     13    url = forms.RegexField(label=_("URL"), max_length=100, regex=URL_REGEX,
    914        help_text = _("Example: '/about/contact/'. Make sure to have leading"
    1015                      " and trailing slashes."),
    1116        error_message = _("This value must contain only letters, numbers,"
  • tests/regressiontests/flatpage_tests/tests.py

     
     1# -*- coding: utf-8 -*-
     2from django.test import TestCase
     3from django.core.exceptions import ValidationError
     4from django.contrib.flatpages.admin import FlatpageForm
     5
     6urltest = FlatpageForm.base_fields['url'].clean
     7
     8class FlatpageTests(TestCase):
     9
     10    def testURLValidation(self):
     11        PASS = ('/some/page/', '/about/',
     12                '/cheese/shoppe/comments/')
     13        FAIL = ('white space', 'bad&char', '/trailing/slash',
     14                'leading/slash/', 'noslashes')
     15        for url in PASS:
     16            self.assertEquals(urltest(url), url)
     17        for url in FAIL:
     18            self.assertRaises(ValidationError, urltest, url)
     19
Back to Top