Add failing test for abstract page managers

Custom page managers set on abstract pages would cause an error on start
up, as accessing the manager of an abstract page is invalid.
pull/2069/head
Tim Heap 2015-12-24 09:50:59 +11:00
rodzic 4dfca33c9b
commit c1c32b5599
3 zmienionych plików z 50 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2015-12-23 22:49
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0023_alter_page_revision_on_delete_behaviour'),
('tests', '0022_uploaded_by_user_on_delete_set_null'),
]
operations = [
migrations.CreateModel(
name='MyCustomPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]

Wyświetl plik

@ -588,3 +588,17 @@ class CustomManager(PageManager):
class CustomManagerPage(Page):
objects = CustomManager()
class MyBasePage(Page):
"""
A base Page model, used to set site-wide defaults and overrides.
"""
objects = CustomManager()
class Meta:
abstract = True
class MyCustomPage(MyBasePage):
pass

Wyświetl plik

@ -17,7 +17,7 @@ from wagtail.tests.testapp.models import (
MTIBasePage, MTIChildPage, AbstractPage, TaggedPage,
BlogCategory, BlogCategoryBlogPage, Advert, ManyToManyBlogPage,
GenericSnippetPage, BusinessNowherePage, SingletonPage,
CustomManager, CustomManagerPage)
CustomManager, CustomManagerPage, MyCustomPage)
from wagtail.tests.utils import WagtailTestUtils
@ -1028,3 +1028,11 @@ class TestPageManager(TestCase):
custom Manager inherits from PageManager.
"""
self.assertIs(type(CustomManagerPage.objects), CustomManager)
def test_abstract_base_page_manager(self):
"""
Abstract base classes should be able to override their default Manager,
and Wagtail should respect this. It is up to the developer to ensure
their custom Manager inherits from PageManager.
"""
self.assertIs(type(MyCustomPage.objects), CustomManager)