Validate the slug field in CopyForm against invalid characters

pull/380/head
Matt Westcott 2014-08-01 15:05:47 +01:00
rodzic e1d1fc917f
commit 0f8e3cbe57
2 zmienionych plików z 16 dodań i 1 usunięć

Wyświetl plik

@ -85,7 +85,7 @@ class CopyForm(forms.Form):
super(CopyForm, self).__init__(*args, **kwargs)
self.fields['new_title'] = forms.CharField(initial=self.page.title)
self.fields['new_slug'] = forms.CharField(initial=self.page.slug)
self.fields['new_slug'] = forms.SlugField(initial=self.page.slug)
copy_subpages = forms.BooleanField(required=False, initial=True)
publish_copies = forms.BooleanField(required=False, initial=True)

Wyświetl plik

@ -1127,6 +1127,21 @@ class TestPageCopy(TestCase, WagtailTestUtils):
# Check that a form error was raised
self.assertFormError(response, 'form', 'new_slug', "This slug is already in use")
def test_page_copy_post_invalid_slug(self):
# Attempt to copy the page but set an invalid slug string
post_data = {
'new_title': "Hello world 2",
'new_slug': 'hello world!',
'copy_subpages': False,
}
response = self.client.post(reverse('wagtailadmin_pages_copy', args=(self.test_page.id, )), post_data)
# Should not be redirected (as the save should fail)
self.assertEqual(response.status_code, 200)
# Check that a form error was raised
self.assertFormError(response, 'form', 'new_slug', "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.")
def test_page_copy_no_publish_permission(self):
# Turn user into an editor who can add pages but not publish them
self.user.is_superuser = False