From 9bc650245944760a55b3d78341d527cdfce78244 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 23 Aug 2016 12:45:04 +0100 Subject: [PATCH] Moved test into wagtailadmin --- .../wagtailadmin/tests/test_pages_views.py | 33 ++++++++++++++++--- wagtail/wagtailcore/tests/test_page_model.py | 31 ----------------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 5a2d1f060..adab11f35 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -19,10 +19,9 @@ from django.utils import formats, timezone from django.utils.dateparse import parse_date from wagtail.tests.testapp.models import ( - EVENT_AUDIENCE_CHOICES, - Advert, AdvertPlacement, BusinessChild, BusinessIndex, BusinessSubIndex, EventPage, - EventPageCarouselItem, FilePage, SimplePage, SingleEventPage, StandardChild, StandardIndex, - TaggedPage) + EVENT_AUDIENCE_CHOICES, Advert, AdvertPlacement, BusinessChild, BusinessIndex, BusinessSubIndex, + EventPage, EventPageCarouselItem, FilePage, SimplePage, SingleEventPage, SingletonPage, + StandardChild, StandardIndex, TaggedPage) from wagtail.tests.utils import WagtailTestUtils from wagtail.wagtailcore.models import GroupPagePermission, Page, PageRevision, Site from wagtail.wagtailcore.signals import page_published, page_unpublished @@ -462,6 +461,32 @@ class TestPageCreation(TestCase, WagtailTestUtils): ) self.assertEqual(response.status_code, 403) + def test_cannot_create_page_when_can_create_at_returns_false(self): + # issue #2892 + + # Check that creating a second SingletonPage results in a permission + # denied error. + + # SingletonPage overrides the can_create_at method to make it return + # False if another SingletonPage already exists. + + add_url = reverse('wagtailadmin_pages:add', args=[ + SingletonPage._meta.app_label, SingletonPage._meta.model_name, self.root_page.pk]) + + # A single singleton page should be creatable + self.assertTrue(SingletonPage.can_create_at(self.root_page)) + response = self.client.get(add_url) + self.assertEqual(response.status_code, 200) + + # Create a singleton page + self.root_page.add_child(instance=SingletonPage( + title='singleton', slug='singleton')) + + # A second singleton page should not be creatable + self.assertFalse(SingletonPage.can_create_at(self.root_page)) + response = self.client.get(add_url) + self.assertEqual(response.status_code, 403) + def test_cannot_create_page_with_wrong_parent_page_types(self): # tests.BusinessChild has limited parent_page_types, so attempting to add # a new one at the root level should fail with permission denied diff --git a/wagtail/wagtailcore/tests/test_page_model.py b/wagtail/wagtailcore/tests/test_page_model.py index 723a15813..5381595fc 100644 --- a/wagtail/wagtailcore/tests/test_page_model.py +++ b/wagtail/wagtailcore/tests/test_page_model.py @@ -8,7 +8,6 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse from django.http import Http404, HttpRequest from django.test import Client, TestCase from django.test.client import RequestFactory @@ -1057,36 +1056,6 @@ class TestIssue1216(TestCase): self.assertEqual(new_christmas_event.url_path, expected_url_path) -class TestIssue2892(TestCase, WagtailTestUtils): - """ - Issue 756 reports that page can be created using a direct url, - even if can_create_at returns False. - """ - - fixtures = ['test.json'] - - def test_singleton_page_creation(self): - self.login() - - root_page = Page.objects.get(url_path='/home/') - add_url = reverse('wagtailadmin_pages:add', args=[ - SingletonPage._meta.app_label, SingletonPage._meta.model_name, root_page.pk]) - - # A single singleton page should be creatable - self.assertTrue(SingletonPage.can_create_at(root_page)) - response = self.client.get(add_url) - self.assertEqual(response.status_code, 200) - - # Create a singleton page - root_page.add_child(instance=SingletonPage( - title='singleton', slug='singleton')) - - # A second singleton page should not be creatable - self.assertFalse(SingletonPage.can_create_at(root_page)) - response = self.client.get(add_url) - self.assertEqual(response.status_code, 403) - - class TestIsCreatable(TestCase): def test_is_creatable_default(self): """By default, pages should be creatable"""