Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cms/djangoapps/contentstore/tests/test_contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from xmodule.seq_module import SequenceDescriptor
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.locator import BlockUsageLocator
from xmodule.tabs import CourseTabList

from contentstore.views.component import ADVANCED_COMPONENT_TYPES
from xmodule.exceptions import NotFoundError
Expand Down Expand Up @@ -395,6 +396,38 @@ def test_create_static_tab_and_rename(self):

self.assertEqual(course.tabs, expected_tabs)

def test_invalid_static_tab_on_import(self):
"""
Test that on import, url_slug of static tabs changes to some unique hex string if that tab
has invalid url slug, e.g. 'static'
"""
module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['2014_static_tabs'])

course_location = CourseDescriptor.id_to_location('Edx/StaticTabs/2014_static_tabs')
course = module_store.get_item(course_location)

self.assertIsNotNone(course)

# test that static tab is properly imported and its url_slug is not 'static'
static_tab = None
for tab in course.tabs:
if tab.type == u'static_tab' and tab.name == u'Sample Static Page':
static_tab = tab

self.assertIsNotNone(static_tab)
self.assertNotEqual(static_tab.url_slug, u'static')

expected_tabs = []
expected_tabs.append({u'type': u'courseware'})
expected_tabs.append({u'type': u'course_info', u'name': u'Course Info'})
expected_tabs.append({u'type': u'textbooks'})
expected_tabs.append({u'type': u'discussion', u'name': u'Discussion'})
expected_tabs.append({u'type': u'wiki', u'name': u'Wiki'})
expected_tabs.append({u'type': u'progress', u'name': u'Progress'})
expected_tabs.append({u'type': u'static_tab', u'name': u'Sample Static Page', u"url_slug": static_tab.url_slug})
self.assertEqual(course.tabs, expected_tabs)

def test_static_tab_reordering(self):
module_store, course_location, new_location = self._create_static_tabs()

Expand Down
9 changes: 9 additions & 0 deletions common/lib/xmodule/xmodule/modulestore/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from importlib import import_module
from lxml import etree
from path import path
from uuid import uuid4

from xmodule.error_module import ErrorDescriptor
from xmodule.errortracker import make_error_tracker, exc_info_to_str
Expand All @@ -38,6 +39,7 @@

log = logging.getLogger(__name__)

INVALID_STATIC_TAB_SLUGS = ['static']

# VS[compat]
# TODO (cpennington): Remove this once all fall 2012 courses have been imported
Expand Down Expand Up @@ -651,6 +653,9 @@ def _load_extra_content(self, system, course_descriptor, category, content_path,
data_content = {'data': html, 'location': loc, 'category': category}

if module is None:
if category == 'static_tab' and slug in INVALID_STATIC_TAB_SLUGS:
loc = loc.replace(name = uuid4().hex)

module = system.construct_xblock(
category,
# We're loading a descriptor, so student_id is meaningless
Expand All @@ -665,6 +670,10 @@ def _load_extra_content(self, system, course_descriptor, category, content_path,
if category == "static_tab":
tab = CourseTabList.get_tab_by_slug(tab_list=course_descriptor.tabs, url_slug=slug)
if tab:
if slug in INVALID_STATIC_TAB_SLUGS:
# Modify url_slug according to location
setattr(tab, 'url_slug', loc.name)

module.display_name = tab.name
module.data_dir = course_dir
module.save()
Expand Down
47 changes: 47 additions & 0 deletions common/test/data/2014_static_tabs/about/overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<section class="about">
<h2>About This Course</h2>
<p>Include your long course description here. The long course description should contain 150-400 words.</p>

<p>This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.</p>
</section>

<section class="prerequisites">
<h2>Prerequisites</h2>
<p>Add information about course prerequisites here.</p>
</section>

<section class="course-staff">
<h2>Course Staff</h2>
<article class="teacher">
<div class="teacher-image">
<img src="/static/images/pl-faculty.png" align="left" style="margin:0 20 px 0" alt="Course Staff Image #1">
</div>

<h3>Staff Member #1</h3>
<p>Biography of instructor/staff member #1</p>
</article>

<article class="teacher">
<div class="teacher-image">
<img src="/static/images/pl-faculty.png" align="left" style="margin:0 20 px 0" alt="Course Staff Image #2">
</div>

<h3>Staff Member #2</h3>
<p>Biography of instructor/staff member #2</p>
</article>
</section>

<section class="faq">
<section class="responses">
<h2>Frequently Asked Questions</h2>
<article class="response">
<h3>Do I need to buy a textbook?</h3>
<p>No, a free online version of Chemistry: Principles, Patterns, and Applications, First Edition by Bruce Averill and Patricia Eldredge will be available, though you can purchase a printed version (published by FlatWorld Knowledge) if you’d like.</p>
</article>

<article class="response">
<h3>Question #2</h3>
<p>Your answer would be displayed here.</p>
</article>
</section>
</section>
1 change: 1 addition & 0 deletions common/test/data/2014_static_tabs/course.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<course url_name="2014_static_tabs" org="Edx" course="StaticTabs"/>
3 changes: 3 additions & 0 deletions common/test/data/2014_static_tabs/course/2014_static_tabs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<course display_name="Static Tabs Testing">
<wiki slug="Edx.StaticTabs.2014_static_tabs"/>
</course>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"GRADER": [{"short_label": "HW", "min_count": 12, "type": "Homework", "drop_count": 2, "weight": 0.15}, {"min_count": 12, "type": "Lab", "drop_count": 2, "weight": 0.15}, {"short_label": "Midterm", "min_count": 1, "type": "Midterm Exam", "drop_count": 0, "weight": 0.3}, {"short_label": "Final", "min_count": 1, "type": "Final Exam", "drop_count": 0, "weight": 0.4}], "GRADE_CUTOFFS": {"Pass": 0.5}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"course/2014_static_tabs": {"tabs": [{"type": "courseware", "name": "Courseware"}, {"type": "course_info", "name": "Course Info"}, {"type": "textbooks", "name": "Textbooks"}, {"type": "discussion", "name": "Discussion"}, {"type": "wiki", "name": "Wiki"}, {"type": "progress", "name": "Progress"}, {"type": "static_tab", "name": "Sample Static Page", "url_slug": "static"}], "display_name": "Static Tabs Testing", "discussion_topics": {"General": {"id": "i4x-Edx-StaticTabs-course-2014_static_tabs"}}}}
1 change: 1 addition & 0 deletions common/test/data/2014_static_tabs/policies/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions common/test/data/2014_static_tabs/tabs/static.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Sample Page</h1>