From f27a259246f99f25fc36f6ff46df40f4d2e0b4d1 Mon Sep 17 00:00:00 2001 From: zubiar-arbi Date: Tue, 1 Apr 2014 16:46:21 +0500 Subject: [PATCH] rename url slug(not allowed) of static tabs on course import STUD-1407 --- .../contentstore/tests/test_contentstore.py | 33 +++++++++++++ common/lib/xmodule/xmodule/modulestore/xml.py | 9 ++++ .../data/2014_static_tabs/about/overview.html | 47 +++++++++++++++++++ common/test/data/2014_static_tabs/course.xml | 1 + .../course/2014_static_tabs.xml | 3 ++ .../2014_static_tabs/grading_policy.json | 1 + .../policies/2014_static_tabs/policy.json | 1 + .../2014_static_tabs/policies/assets.json | 1 + .../data/2014_static_tabs/tabs/static.html | 1 + 9 files changed, 97 insertions(+) create mode 100644 common/test/data/2014_static_tabs/about/overview.html create mode 100644 common/test/data/2014_static_tabs/course.xml create mode 100644 common/test/data/2014_static_tabs/course/2014_static_tabs.xml create mode 100644 common/test/data/2014_static_tabs/policies/2014_static_tabs/grading_policy.json create mode 100644 common/test/data/2014_static_tabs/policies/2014_static_tabs/policy.json create mode 100644 common/test/data/2014_static_tabs/policies/assets.json create mode 100644 common/test/data/2014_static_tabs/tabs/static.html diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 0b028cdca068..4baacbc995d8 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -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 @@ -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() diff --git a/common/lib/xmodule/xmodule/modulestore/xml.py b/common/lib/xmodule/xmodule/modulestore/xml.py index 304f5f1c0c88..2ea22c412a6f 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml.py +++ b/common/lib/xmodule/xmodule/modulestore/xml.py @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/common/test/data/2014_static_tabs/about/overview.html b/common/test/data/2014_static_tabs/about/overview.html new file mode 100644 index 000000000000..33911ae1ee73 --- /dev/null +++ b/common/test/data/2014_static_tabs/about/overview.html @@ -0,0 +1,47 @@ +
+

About This Course

+

Include your long course description here. The long course description should contain 150-400 words.

+ +

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

+
+ +
+

Prerequisites

+

Add information about course prerequisites here.

+
+ +
+

Course Staff

+
+
+ Course Staff Image #1 +
+ +

Staff Member #1

+

Biography of instructor/staff member #1

+
+ +
+
+ Course Staff Image #2 +
+ +

Staff Member #2

+

Biography of instructor/staff member #2

+
+
+ +
+
+

Frequently Asked Questions

+
+

Do I need to buy a textbook?

+

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.

+
+ +
+

Question #2

+

Your answer would be displayed here.

+
+
+
diff --git a/common/test/data/2014_static_tabs/course.xml b/common/test/data/2014_static_tabs/course.xml new file mode 100644 index 000000000000..d5ad8d489625 --- /dev/null +++ b/common/test/data/2014_static_tabs/course.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/common/test/data/2014_static_tabs/course/2014_static_tabs.xml b/common/test/data/2014_static_tabs/course/2014_static_tabs.xml new file mode 100644 index 000000000000..0cca234db6ed --- /dev/null +++ b/common/test/data/2014_static_tabs/course/2014_static_tabs.xml @@ -0,0 +1,3 @@ + + + diff --git a/common/test/data/2014_static_tabs/policies/2014_static_tabs/grading_policy.json b/common/test/data/2014_static_tabs/policies/2014_static_tabs/grading_policy.json new file mode 100644 index 000000000000..272cb4fec6f4 --- /dev/null +++ b/common/test/data/2014_static_tabs/policies/2014_static_tabs/grading_policy.json @@ -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}} \ No newline at end of file diff --git a/common/test/data/2014_static_tabs/policies/2014_static_tabs/policy.json b/common/test/data/2014_static_tabs/policies/2014_static_tabs/policy.json new file mode 100644 index 000000000000..e8e93e2e0275 --- /dev/null +++ b/common/test/data/2014_static_tabs/policies/2014_static_tabs/policy.json @@ -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"}}}} diff --git a/common/test/data/2014_static_tabs/policies/assets.json b/common/test/data/2014_static_tabs/policies/assets.json new file mode 100644 index 000000000000..9e26dfeeb6e6 --- /dev/null +++ b/common/test/data/2014_static_tabs/policies/assets.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/common/test/data/2014_static_tabs/tabs/static.html b/common/test/data/2014_static_tabs/tabs/static.html new file mode 100644 index 000000000000..c8e11e26447c --- /dev/null +++ b/common/test/data/2014_static_tabs/tabs/static.html @@ -0,0 +1 @@ +

Sample Page