Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
For some reason tests on child_pages decided to start failing due to …
Browse files Browse the repository at this point in the history
…DraftBoobyTrap access just now. This change repairs logic on the plugin to be aware of draft/public status.
  • Loading branch information
Greg Turner committed Nov 22, 2016
1 parent 29a5d1b commit 50392c9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
12 changes: 0 additions & 12 deletions icekit/page_types/layout_page/search_indexes.py

This file was deleted.

13 changes: 10 additions & 3 deletions icekit/plugins/child_pages/abstract_models.py
Expand Up @@ -4,13 +4,20 @@


@python_2_unicode_compatible
class AbstractChildPageItem(ContentItem):
class AbstractChildPagesItem(ContentItem):
class Meta:
abstract = True
verbose_name = _('Child Page')
verbose_name = _('Child Pages')

def __str__(self):
return 'Child Pages'

def get_child_pages(self):
return self.parent.get_children()
# If my parent page is draft, show parent's (draft) children
# if my parent page is published, show published equivalents of parent's children
parent = self.parent

if parent.is_draft:
return [p for p in parent.get_children() if p.publishing_is_draft]
else:
return parent.get_draft().get_children().published()
2 changes: 1 addition & 1 deletion icekit/plugins/child_pages/models.py
@@ -1,5 +1,5 @@
from . import abstract_models


class ChildPageItem(abstract_models.AbstractChildPageItem):
class ChildPageItem(abstract_models.AbstractChildPagesItem):
pass
36 changes: 24 additions & 12 deletions icekit/plugins/child_pages/tests.py
Expand Up @@ -12,7 +12,7 @@
User = get_user_model()


class InstagramEmbedItemTestCase(WebTest):
class ChildPagesTestCase(WebTest):
def setUp(self):
self.layout_1 = G(
Layout,
Expand All @@ -32,23 +32,20 @@ def setUp(self):
parent_site=Site.objects.first(),
layout=self.layout_1,
author=self.staff_1,
status='p', # Publish the page
)
self.page_2 = LayoutPage.objects.create(
title='Test Page 2',
slug='test-page-2',
parent_site=Site.objects.first(),
layout=self.layout_1,
author=self.staff_1,
status='p', # Publish the page
)
self.page_3 = LayoutPage.objects.create(
title='Test Page 3',
slug='test-page-3',
parent_site=Site.objects.first(),
layout=self.layout_1,
author=self.staff_1,
status='p', # Publish the page
parent=self.page_2,
)
self.page_4 = LayoutPage.objects.create(
Expand All @@ -57,24 +54,39 @@ def setUp(self):
parent_site=Site.objects.first(),
layout=self.layout_1,
author=self.staff_1,
status='p', # Publish the page
parent=self.page_2,
)
self.child_page_1 = fluent_contents.create_content_instance(
self.child_pages_1 = fluent_contents.create_content_instance(
models.ChildPageItem,
self.page_1,
)
self.child_page_2 = fluent_contents.create_content_instance(
self.child_pages_2 = fluent_contents.create_content_instance(
models.ChildPageItem,
self.page_2,
)

self.page_1.publish()
self.page_2.publish()
self.page_3.publish()
# page_4 is not published

def test_str(self):
self.assertEqual(str(self.child_page_1), 'Child Pages')
self.assertEqual(str(self.child_pages_1), 'Child Pages')

def test_get_child_pages(self):
self.assertEqual(self.child_page_1.get_child_pages().count(), 0)
self.assertEqual(self.child_page_2.get_child_pages().count(), 2)
def test_get_child_pages_draft(self):
self.assertEqual(len(self.child_pages_1.get_child_pages()), 0)
self.assertEqual(len(self.child_pages_2.get_child_pages()), 2)
expected_children = [self.page_3, self.page_4]
for child in expected_children:
self.assertIn(child, self.child_page_2.get_child_pages())
self.assertIn(child, self.child_pages_2.get_child_pages())


def test_get_child_pages_published(self):
pcp1 = self.page_1.get_published().contentitem_set.all()[0]
pcp2 = self.page_2.get_published().contentitem_set.all()[0]

self.assertEqual(len(pcp1.get_child_pages()), 0)
self.assertEqual(len(pcp2.get_child_pages()), 1)
expected_children = [self.page_3.get_published()]
for child in expected_children:
self.assertIn(child, pcp2.get_child_pages())

0 comments on commit 50392c9

Please sign in to comment.