Commit dd22bf49 by cahrens

Update tests and minor cleanup.

parent 3bb4be7d
...@@ -195,6 +195,11 @@ def course_image_url(course): ...@@ -195,6 +195,11 @@ def course_image_url(course):
class PublishState(object): class PublishState(object):
"""
The publish state for a given xblock-- either 'draft', 'private', or 'public'.
Currently in CMS, an xblock can only be in 'draft' or 'private' if it is at or below the Unit level.
"""
draft = 'draft' draft = 'draft'
private = 'private' private = 'private'
public = 'public' public = 'public'
......
...@@ -107,8 +107,8 @@ def subsection_handler(request, tag=None, package_id=None, branch=None, version_ ...@@ -107,8 +107,8 @@ def subsection_handler(request, tag=None, package_id=None, branch=None, version_
can_view_live = False can_view_live = False
subsection_units = item.get_children() subsection_units = item.get_children()
for unit in subsection_units: for unit in subsection_units:
state = compute_unit_state(unit) state = compute_publish_state(unit)
if state == UnitState.public or state == UnitState.draft: if state == PublishState.public or state == PublishState.draft:
can_view_live = True can_view_live = True
break break
...@@ -312,10 +312,8 @@ def container_handler(request, tag=None, package_id=None, branch=None, version_g ...@@ -312,10 +312,8 @@ def container_handler(request, tag=None, package_id=None, branch=None, version_g
ancestor_xblocks = [] ancestor_xblocks = []
parent = get_parent_xblock(xblock) parent = get_parent_xblock(xblock)
unit = None
while parent and parent.category != 'sequential': while parent and parent.category != 'sequential':
ancestor_xblocks.append(parent) ancestor_xblocks.append(parent)
unit = parent
parent = get_parent_xblock(parent) parent = get_parent_xblock(parent)
ancestor_xblocks.reverse() ancestor_xblocks.reverse()
...@@ -324,7 +322,7 @@ def container_handler(request, tag=None, package_id=None, branch=None, version_g ...@@ -324,7 +322,7 @@ def container_handler(request, tag=None, package_id=None, branch=None, version_g
'context_course': course, 'context_course': course,
'xblock': xblock, 'xblock': xblock,
'xblock_locator': locator, 'xblock_locator': locator,
'unit': unit, 'unit': None if not ancestor_xblocks else ancestor_xblocks[0],
'ancestor_xblocks': ancestor_xblocks, 'ancestor_xblocks': ancestor_xblocks,
}) })
else: else:
......
...@@ -28,9 +28,9 @@ class ContainerViewTestCase(CourseTestCase): ...@@ -28,9 +28,9 @@ class ContainerViewTestCase(CourseTestCase):
def test_container_html(self): def test_container_html(self):
self._test_html_content( self._test_html_content(
self.child_vertical, self.child_vertical,
expected_section_tag='<section class="wrapper-xblock level-page" data-locator="MITx.999.Robot_Super_Course/branch/published/block/Child_Vertical"/>', expected_section_tag='<section class="wrapper-xblock level-page" data-locator="MITx.999.Robot_Super_Course/branch/draft/block/Child_Vertical"/>',
expected_breadcrumbs=( expected_breadcrumbs=(
r'<a href="/unit/MITx.999.Robot_Super_Course/branch/published/block/Unit"\s*' r'<a href="/unit/MITx.999.Robot_Super_Course/branch/draft/block/Unit"\s*'
r'class="navigation-link navigation-parent">Unit</a>\s*' r'class="navigation-link navigation-parent">Unit</a>\s*'
r'<a href="#" class="navigation-link navigation-current">Child Vertical</a>'), r'<a href="#" class="navigation-link navigation-current">Child Vertical</a>'),
) )
...@@ -46,11 +46,11 @@ class ContainerViewTestCase(CourseTestCase): ...@@ -46,11 +46,11 @@ class ContainerViewTestCase(CourseTestCase):
category="html", display_name="Child HTML") category="html", display_name="Child HTML")
self._test_html_content( self._test_html_content(
xblock_with_child, xblock_with_child,
expected_section_tag='<section class="wrapper-xblock level-page" data-locator="MITx.999.Robot_Super_Course/branch/published/block/Wrapper"/>', expected_section_tag='<section class="wrapper-xblock level-page" data-locator="MITx.999.Robot_Super_Course/branch/draft/block/Wrapper"/>',
expected_breadcrumbs=( expected_breadcrumbs=(
r'<a href="/unit/MITx.999.Robot_Super_Course/branch/published/block/Unit"\s*' r'<a href="/unit/MITx.999.Robot_Super_Course/branch/draft/block/Unit"\s*'
r'class="navigation-link navigation-parent">Unit</a>\s*' r'class="navigation-link navigation-parent">Unit</a>\s*'
r'<a href="/container/MITx.999.Robot_Super_Course/branch/published/block/Child_Vertical"\s*' r'<a href="/container/MITx.999.Robot_Super_Course/branch/draft/block/Child_Vertical"\s*'
r'class="navigation-link navigation-parent">Child Vertical</a>\s*' r'class="navigation-link navigation-parent">Child Vertical</a>\s*'
r'<a href="#" class="navigation-link navigation-current">Wrapper</a>'), r'<a href="#" class="navigation-link navigation-current">Wrapper</a>'),
) )
...@@ -67,3 +67,6 @@ class ContainerViewTestCase(CourseTestCase): ...@@ -67,3 +67,6 @@ class ContainerViewTestCase(CourseTestCase):
self.assertIn(expected_section_tag, html) self.assertIn(expected_section_tag, html)
# Verify the navigation link at the top of the page is correct. # Verify the navigation link at the top of the page is correct.
self.assertRegexpMatches(html, expected_breadcrumbs) self.assertRegexpMatches(html, expected_breadcrumbs)
# Verify the link that allows users to change publish status.
expected_unit_link = 'This container will publish as part of the unit <a href="/unit/MITx.999.Robot_Super_Course/branch/draft/block/Unit">Unit</a>.'
self.assertIn(expected_unit_link, html)
...@@ -16,7 +16,7 @@ class HelpersTestCase(CourseTestCase): ...@@ -16,7 +16,7 @@ class HelpersTestCase(CourseTestCase):
# Verify course URL # Verify course URL
self.assertEqual(xblock_studio_url(course), self.assertEqual(xblock_studio_url(course),
u'/course/MITx.999.Robot_Super_Course/branch/published/block/Robot_Super_Course') u'/course/MITx.999.Robot_Super_Course/branch/draft/block/Robot_Super_Course')
# Verify chapter URL # Verify chapter URL
chapter = ItemFactory.create(parent_location=self.course.location, category='chapter', chapter = ItemFactory.create(parent_location=self.course.location, category='chapter',
...@@ -34,17 +34,17 @@ class HelpersTestCase(CourseTestCase): ...@@ -34,17 +34,17 @@ class HelpersTestCase(CourseTestCase):
vertical = ItemFactory.create(parent_location=sequential.location, category='vertical', vertical = ItemFactory.create(parent_location=sequential.location, category='vertical',
display_name='Unit') display_name='Unit')
self.assertEqual(xblock_studio_url(vertical), self.assertEqual(xblock_studio_url(vertical),
u'/unit/MITx.999.Robot_Super_Course/branch/published/block/Unit') u'/unit/MITx.999.Robot_Super_Course/branch/draft/block/Unit')
self.assertEqual(xblock_studio_url(vertical, course), self.assertEqual(xblock_studio_url(vertical, course),
u'/unit/MITx.999.Robot_Super_Course/branch/published/block/Unit') u'/unit/MITx.999.Robot_Super_Course/branch/draft/block/Unit')
# Verify child vertical URL # Verify child vertical URL
child_vertical = ItemFactory.create(parent_location=vertical.location, category='vertical', child_vertical = ItemFactory.create(parent_location=vertical.location, category='vertical',
display_name='Child Vertical') display_name='Child Vertical')
self.assertEqual(xblock_studio_url(child_vertical), self.assertEqual(xblock_studio_url(child_vertical),
u'/container/MITx.999.Robot_Super_Course/branch/published/block/Child_Vertical') u'/container/MITx.999.Robot_Super_Course/branch/draft/block/Child_Vertical')
self.assertEqual(xblock_studio_url(child_vertical, course), self.assertEqual(xblock_studio_url(child_vertical, course),
u'/container/MITx.999.Robot_Super_Course/branch/published/block/Child_Vertical') u'/container/MITx.999.Robot_Super_Course/branch/draft/block/Child_Vertical')
# Verify video URL # Verify video URL
video = ItemFactory.create(parent_location=child_vertical.location, category="video", video = ItemFactory.create(parent_location=child_vertical.location, category="video",
......
...@@ -154,7 +154,7 @@ class GetItem(ItemTest): ...@@ -154,7 +154,7 @@ class GetItem(ItemTest):
html, html,
# The instance of the wrapper class will have an auto-generated ID (wrapperxxx). Allow anything # The instance of the wrapper class will have an auto-generated ID (wrapperxxx). Allow anything
# for the 3 characters after wrapper. # for the 3 characters after wrapper.
(r'"/container/MITx.999.Robot_Super_Course/branch/published/block/wrapper.{3}" class="action-button">\s*' (r'"/container/MITx.999.Robot_Super_Course/branch/draft/block/wrapper.{3}" class="action-button">\s*'
'<span class="action-button-text">View</span>') '<span class="action-button-text">View</span>')
) )
...@@ -657,7 +657,6 @@ class TestEditItem(ItemTest): ...@@ -657,7 +657,6 @@ class TestEditItem(ItemTest):
draft = self.get_item_from_modulestore(self.problem_locator, True) draft = self.get_item_from_modulestore(self.problem_locator, True)
self.assertNotEqual(draft.data, published.data) self.assertNotEqual(draft.data, published.data)
def test_publish_states_of_nested_xblocks(self): def test_publish_states_of_nested_xblocks(self):
""" Test publishing of a unit page containing a nested xblock """ """ Test publishing of a unit page containing a nested xblock """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment