def test_publish_multitable_page_extension(self): page = create_page('Test Multi-Table Page Extension', "nav_playground.html", "en") page_extension = MultiTablePageExtension(extended_object=page, extension_parent_field='page extension 1', multitable_extra='multi-table page extension 1') page_extension.save() page.multitablepageextension = page_extension # publish first time page.publish('en') # print(dir(page)) self.assertEqual(page_extension.extension_parent_field, page.publisher_public.multitablepageextension.extension_parent_field) self.assertEqual(page_extension.multitable_extra, page.publisher_public.multitablepageextension.multitable_extra) self.assertEqual(page.get_publisher_state('en'), 0) # change and publish again page = Page.objects.get(pk=page.pk) page_extension = page.multitablepageextension page_extension.extension_parent_field = 'page extension 1 - changed' page_extension.multitable_extra = 'multi-table page extension 1 - changed' page_extension.save() self.assertEqual(page.get_publisher_state('en', True), PUBLISHER_STATE_DIRTY) page.publish('en') self.assertEqual(page.get_publisher_state('en', True), 0) # delete page_extension.delete() self.assertFalse(MultiTablePageExtension.objects.filter(pk=page_extension.pk).exists()) self.assertEqual(page.get_publisher_state('en', True), PUBLISHER_STATE_DIRTY)
def test_copy_multitable_extensions(self): root = create_page('Root', "nav_playground.html", "en", published=True) page = create_page('Test Multi-Table Page Extension', "nav_playground.html", "en", parent=root.get_draft_object()) subpage = create_page('Test Multi-Table subpage Extension', "nav_playground.html", "en", parent=page) page = Page.objects.get(pk=page.pk) page_extension = MultiTablePageExtension( extended_object=page, extension_parent_field='page extension 1', multitable_extra='multi-table page extension 1') page_extension.save() page.multitablepageextension = page_extension title = page.get_title_obj() title_extension = MultiTableTitleExtension( extended_object=title, extension_title_parent_field='title extension 1', multitable_extra_title='multi-table title extension 1') title_extension.save() page.multitabletitleextension = title_extension subpage_extension = MultiTablePageExtension( extended_object=subpage, extension_parent_field='page extension 2', multitable_extra='multi-table page extension 2') subpage_extension.save() subpage.multitablepageextension = subpage_extension subtitle = subpage.get_title_obj() subtitle_extension = MultiTableTitleExtension( extended_object=subtitle, extension_title_parent_field='title extension 2', multitable_extra_title='multi-table title extension 2') subtitle_extension.save() subpage.multitabletitleextension = subtitle_extension # asserting original extensions self.assertEqual(len(extension_pool.get_page_extensions()), 2) self.assertEqual(len(extension_pool.get_title_extensions()), 2) copied_page = page.copy_with_descendants(target_node=None, position='last-child') # asserting original + copied extensions self.assertEqual(len(extension_pool.get_page_extensions()), 4) self.assertEqual(len(extension_pool.get_title_extensions()), 4) # testing extension content old_page_extensions = [page_extension, subpage_extension] old_title_extension = [title_extension, subtitle_extension] for index, new_page in enumerate( [copied_page] + list(copied_page.get_descendant_pages())): copied_page_extension = extension_pool.get_page_extensions( new_page)[0] copied_title_extension = extension_pool.get_title_extensions( new_page.title_set.get(language='en'))[0] self.assertEqual(copied_page_extension.extension_parent_field, old_page_extensions[index].extension_parent_field) self.assertEqual(copied_page_extension.multitable_extra, old_page_extensions[index].multitable_extra) self.assertEqual( copied_title_extension.extension_title_parent_field, old_title_extension[index].extension_title_parent_field) self.assertEqual(copied_title_extension.multitable_extra_title, old_title_extension[index].multitable_extra_title) # check that objects are actually different self.assertNotEqual( extension_pool.get_page_extensions(new_page)[0].pk, old_page_extensions[index].pk) self.assertNotEqual( extension_pool.get_title_extensions( new_page.title_set.get(language='en'))[0].pk, old_title_extension[index].pk) # Test deleting original page for #3987 page.delete() # asserting original extensions are gone, but copied ones should still exist self.assertEqual(len(extension_pool.get_page_extensions()), 2) self.assertEqual(len(extension_pool.get_title_extensions()), 2)
def test_copy_multitable_extensions(self): root = create_page('Root', "nav_playground.html", "en", published=True) page = create_page('Test Multi-Table Page Extension', "nav_playground.html", "en", parent=root.get_draft_object()) subpage = create_page('Test Multi-Table subpage Extension', "nav_playground.html", "en", parent=page) page = Page.objects.get(pk=page.pk) page_extension = MultiTablePageExtension(extended_object=page, extension_parent_field='page extension 1', multitable_extra='multi-table page extension 1') page_extension.save() page.multitablepageextension = page_extension title = page.get_title_obj() title_extension = MultiTableTitleExtension(extended_object=title, extension_title_parent_field='title extension 1', multitable_extra_title='multi-table title extension 1') title_extension.save() page.multitabletitleextension = title_extension subpage_extension = MultiTablePageExtension(extended_object=subpage, extension_parent_field='page extension 2', multitable_extra='multi-table page extension 2') subpage_extension.save() subpage.multitablepageextension = subpage_extension subtitle = subpage.get_title_obj() subtitle_extension = MultiTableTitleExtension(extended_object=subtitle, extension_title_parent_field='title extension 2', multitable_extra_title='multi-table title extension 2') subtitle_extension.save() subpage.multitabletitleextension = subtitle_extension # asserting original extensions self.assertEqual(len(extension_pool.get_page_extensions()), 2) self.assertEqual(len(extension_pool.get_title_extensions()), 2) copied_page = page.copy_page(None, page.site, position='last-child') # asserting original + copied extensions self.assertEqual(len(extension_pool.get_page_extensions()), 4) self.assertEqual(len(extension_pool.get_title_extensions()), 4) # testing extension content old_page_extensions = [page_extension, subpage_extension] old_title_extension = [title_extension, subtitle_extension] for index, new_page in enumerate([copied_page] + list(copied_page.get_descendants())): copied_page_extension = extension_pool.get_page_extensions(new_page)[0] copied_title_extension = extension_pool.get_title_extensions(new_page.title_set.get(language='en'))[0] self.assertEqual(copied_page_extension.extension_parent_field, old_page_extensions[index].extension_parent_field) self.assertEqual(copied_page_extension.multitable_extra, old_page_extensions[index].multitable_extra) self.assertEqual(copied_title_extension.extension_title_parent_field, old_title_extension[index].extension_title_parent_field) self.assertEqual(copied_title_extension.multitable_extra_title, old_title_extension[index].multitable_extra_title) # check that objects are actually different self.assertNotEqual(extension_pool.get_page_extensions(new_page)[0].pk, old_page_extensions[index].pk) self.assertNotEqual(extension_pool.get_title_extensions(new_page.title_set.get(language='en'))[0].pk, old_title_extension[index].pk) # Test deleting original page for #3987 page.delete() # asserting original extensions are gone, but copied ones should still exist self.assertEqual(len(extension_pool.get_page_extensions()), 2) self.assertEqual(len(extension_pool.get_title_extensions()), 2)