Update tests and minor cleanup.
This commit is contained in:
@@ -195,6 +195,11 @@ def course_image_url(course):
|
||||
|
||||
|
||||
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'
|
||||
private = 'private'
|
||||
public = 'public'
|
||||
|
||||
@@ -107,8 +107,8 @@ def subsection_handler(request, tag=None, package_id=None, branch=None, version_
|
||||
can_view_live = False
|
||||
subsection_units = item.get_children()
|
||||
for unit in subsection_units:
|
||||
state = compute_unit_state(unit)
|
||||
if state == UnitState.public or state == UnitState.draft:
|
||||
state = compute_publish_state(unit)
|
||||
if state == PublishState.public or state == PublishState.draft:
|
||||
can_view_live = True
|
||||
break
|
||||
|
||||
@@ -312,10 +312,8 @@ def container_handler(request, tag=None, package_id=None, branch=None, version_g
|
||||
|
||||
ancestor_xblocks = []
|
||||
parent = get_parent_xblock(xblock)
|
||||
unit = None
|
||||
while parent and parent.category != 'sequential':
|
||||
ancestor_xblocks.append(parent)
|
||||
unit = parent
|
||||
parent = get_parent_xblock(parent)
|
||||
|
||||
ancestor_xblocks.reverse()
|
||||
@@ -324,7 +322,7 @@ def container_handler(request, tag=None, package_id=None, branch=None, version_g
|
||||
'context_course': course,
|
||||
'xblock': xblock,
|
||||
'xblock_locator': locator,
|
||||
'unit': unit,
|
||||
'unit': None if not ancestor_xblocks else ancestor_xblocks[0],
|
||||
'ancestor_xblocks': ancestor_xblocks,
|
||||
})
|
||||
else:
|
||||
|
||||
@@ -28,9 +28,9 @@ class ContainerViewTestCase(CourseTestCase):
|
||||
def test_container_html(self):
|
||||
self._test_html_content(
|
||||
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=(
|
||||
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'<a href="#" class="navigation-link navigation-current">Child Vertical</a>'),
|
||||
)
|
||||
@@ -46,11 +46,11 @@ class ContainerViewTestCase(CourseTestCase):
|
||||
category="html", display_name="Child HTML")
|
||||
self._test_html_content(
|
||||
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=(
|
||||
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'<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'<a href="#" class="navigation-link navigation-current">Wrapper</a>'),
|
||||
)
|
||||
@@ -67,3 +67,6 @@ class ContainerViewTestCase(CourseTestCase):
|
||||
self.assertIn(expected_section_tag, html)
|
||||
# Verify the navigation link at the top of the page is correct.
|
||||
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):
|
||||
|
||||
# Verify course URL
|
||||
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
|
||||
chapter = ItemFactory.create(parent_location=self.course.location, category='chapter',
|
||||
@@ -34,17 +34,17 @@ class HelpersTestCase(CourseTestCase):
|
||||
vertical = ItemFactory.create(parent_location=sequential.location, category='vertical',
|
||||
display_name='Unit')
|
||||
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),
|
||||
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
|
||||
child_vertical = ItemFactory.create(parent_location=vertical.location, category='vertical',
|
||||
display_name='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),
|
||||
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
|
||||
video = ItemFactory.create(parent_location=child_vertical.location, category="video",
|
||||
|
||||
@@ -154,7 +154,7 @@ class GetItem(ItemTest):
|
||||
html,
|
||||
# The instance of the wrapper class will have an auto-generated ID (wrapperxxx). Allow anything
|
||||
# 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>')
|
||||
)
|
||||
|
||||
@@ -657,7 +657,6 @@ class TestEditItem(ItemTest):
|
||||
draft = self.get_item_from_modulestore(self.problem_locator, True)
|
||||
self.assertNotEqual(draft.data, published.data)
|
||||
|
||||
|
||||
def test_publish_states_of_nested_xblocks(self):
|
||||
""" Test publishing of a unit page containing a nested xblock """
|
||||
|
||||
|
||||
Reference in New Issue
Block a user