mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-19 20:41:56 +00:00
Moved test into wagtailadmin
This commit is contained in:
parent
07b7dd2940
commit
9bc6502459
2 changed files with 29 additions and 35 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue