diff --git a/wagtail/tests/testapp/fixtures/test.json b/wagtail/tests/testapp/fixtures/test.json index 7a51679f7..2c1718d25 100644 --- a/wagtail/tests/testapp/fixtures/test.json +++ b/wagtail/tests/testapp/fixtures/test.json @@ -86,6 +86,41 @@ } }, +{ + "pk": 13, + "model": "wagtailcore.page", + "fields": { + "title": "Saint Patrick", + "numchild": 0, + "show_in_menus": true, + "live": true, + "depth": 4, + "content_type": ["tests", "singleeventpage"], + "path": "0001000100010005", + "url_path": "/home/events/saint-patrick/", + "slug": "saint-patrick", + "owner": 2 + } +}, +{ + "pk": 13, + "model": "tests.eventpage", + "fields": { + "date_from": "2014-12-25", + "audience": "private", + "location": "Wellington", + "body": "

The day when nothing makes sense.

", + "cost": "Semi-free" + } +}, +{ + "pk": 13, + "model": "tests.singleeventpage", + "fields": { + "excerpt": "A little tiny excerpt for Saint Patrick." + } +}, + { "pk": 1, "model": "tests.eventpagespeaker", diff --git a/wagtail/tests/testapp/migrations/0007_singleeventpage.py b/wagtail/tests/testapp/migrations/0007_singleeventpage.py new file mode 100644 index 000000000..adf5eec70 --- /dev/null +++ b/wagtail/tests/testapp/migrations/0007_singleeventpage.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tests', '0006_image_file_size'), + ] + + operations = [ + migrations.CreateModel( + name='SingleEventPage', + fields=[ + ('eventpage_ptr', models.OneToOneField(auto_created=True, to='tests.EventPage', serialize=False, parent_link=True, primary_key=True)), + ('excerpt', models.TextField(help_text='Short text to describe what is this action about', max_length=255, null=True, blank=True)), + ], + bases=('tests.eventpage',), + ), + ] diff --git a/wagtail/tests/testapp/models.py b/wagtail/tests/testapp/models.py index 9b3a9ae82..c6cb98f44 100644 --- a/wagtail/tests/testapp/models.py +++ b/wagtail/tests/testapp/models.py @@ -216,6 +216,13 @@ EventPage.promote_panels = [ ] +# Just to be able to test multi table inheritance +class SingleEventPage(EventPage): + excerpt = models.TextField(max_length=255, blank=True, null=True, help_text="Short text to describe what is this action about") + +SingleEventPage.content_panels = [FieldPanel('excerpt')] + EventPage.content_panels + + # Event index (has a separate AJAX template, and a custom template context) class EventIndex(Page): intro = RichTextField(blank=True) diff --git a/wagtail/wagtailcore/tests/test_management_commands.py b/wagtail/wagtailcore/tests/test_management_commands.py index 7c90f9922..d4b7c6845 100644 --- a/wagtail/wagtailcore/tests/test_management_commands.py +++ b/wagtail/wagtailcore/tests/test_management_commands.py @@ -80,7 +80,7 @@ class TestFixTreeCommand(TestCase): # Check that the issues were detected output_string = output.read() self.assertIn("Incorrect numchild value found for pages: [2]", output_string) - self.assertIn("Orphaned pages found: [4, 5, 6, 9]", output_string) + self.assertIn("Orphaned pages found: [4, 5, 6, 9, 13]", output_string) # Check that christmas_page is still in the tree self.assertTrue(Page.objects.filter(id=christmas_page.id).exists()) @@ -102,7 +102,7 @@ class TestFixTreeCommand(TestCase): # Check that the issues were detected output_string = output.read() self.assertIn("Incorrect numchild value found for pages: [2]", output_string) - self.assertIn("4 orphaned pages deleted.", output_string) + self.assertIn("5 orphaned pages deleted.", output_string) # Check that christmas_page has been deleted self.assertFalse(Page.objects.filter(id=christmas_page.id).exists()) diff --git a/wagtail/wagtailcore/tests/test_page_model.py b/wagtail/wagtailcore/tests/test_page_model.py index b1773ab0c..7af85f878 100644 --- a/wagtail/wagtailcore/tests/test_page_model.py +++ b/wagtail/wagtailcore/tests/test_page_model.py @@ -11,7 +11,7 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser from wagtail.wagtailcore.models import Page, Site -from wagtail.tests.testapp.models import EventPage, EventIndex, SimplePage, BusinessIndex, BusinessSubIndex, BusinessChild, StandardIndex +from wagtail.tests.testapp.models import SingleEventPage, EventPage, EventIndex, SimplePage, BusinessIndex, BusinessSubIndex, BusinessChild, StandardIndex class TestSiteRouting(TestCase): @@ -604,6 +604,28 @@ class TestCopyPage(TestCase): # Check that the user on the last revision is correct self.assertEqual(new_christmas_event.get_latest_revision().user, event_moderator) + def test_copy_multi_table_inheritance(self): + saint_patrick_event = SingleEventPage.objects.get(url_path='/home/events/saint-patrick/') + + # Copy it + new_saint_patrick_event = saint_patrick_event.copy(update_attrs={'slug': 'new-saint-patrick'}) + + # Check that new_saint_patrick_event is correct + self.assertIsInstance(new_saint_patrick_event, SingleEventPage) + self.assertEqual(new_saint_patrick_event.excerpt, saint_patrick_event.excerpt) + + # Check that new_saint_patrick_event is a different page, including parents from both EventPage and Page + self.assertNotEqual(saint_patrick_event.id, new_saint_patrick_event.id) + self.assertNotEqual(saint_patrick_event.eventpage_ptr.id, new_saint_patrick_event.eventpage_ptr.id) + self.assertNotEqual(saint_patrick_event.eventpage_ptr.page_ptr.id, new_saint_patrick_event.eventpage_ptr.page_ptr.id) + + # Check that the url path was updated + self.assertEqual(new_saint_patrick_event.url_path, '/home/events/new-saint-patrick/') + + # Check that both parent instance exists + self.assertIsInstance(EventPage.objects.get(id=new_saint_patrick_event.id), EventPage) + self.assertIsInstance(Page.objects.get(id=new_saint_patrick_event.id), Page) + class TestSubpageTypeBusinessRules(TestCase): def test_allowed_subpage_types(self):