Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #834 from mitodl/fix/gs/use_display_name
Browse files Browse the repository at this point in the history
Added parsing for display_name so we can use it if url_name isn't present
  • Loading branch information
George Schneeloch committed Nov 4, 2015
2 parents f40868c + 3b1dd30 commit e20c3ad
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion importer/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,16 @@ def import_children(course, element, parent, parent_dpath):
desc_path = MissingTitle.for_desc_path_field
mpath = etree.ElementTree(element).getpath(element)
dpath = join_description_paths(parent_dpath, desc_path)
url_name = element.attrib.get(
"url_name",
element.attrib.get("display_name", None)
)
resource = create_resource(
course=course, parent=parent, resource_type=element.tag,
title=title,
content_xml=etree.tostring(element),
mpath=mpath,
url_name=element.attrib.get("url_name", None),
url_name=url_name,
dpath=dpath,
)
# temp variable to store static assets for bulk insert
Expand Down
22 changes: 22 additions & 0 deletions importer/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,25 @@ def get_counts():
"assets/edX/toy/TT_2012_Fall/webGLDemo.css",
])
)

def test_display_name_as_url_name(self):
"""
Test that we use display_name if url_name does not exist.
"""

path = os.path.join(
os.path.abspath(
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
"learningresources", "tests",
"testdata", "courses", "nested_problem"
)
zip_path = self._make_archive(path, True)

import_course_from_file(zip_path, self.repo.id, self.user.id)
self.assertEqual(
sorted([resource.url_name for resource in
LearningResource.objects.filter(
learning_resource_type__name="problem"
).all()]),
sorted(["problem_1", "problem_2", "inner_problem"])
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello overview
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<chapter display_name="Intro">
<sequential url_name="a sequential" />
<!-- a comment -->
</chapter>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<course url_name="2013_Spring" org="MITx" course="mitx.01"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<course semester="2013_Spring" course="mitx.01" org="MITx">
<chapter url_name="Intro_chapter"/>
</course>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html display_name="Overview text">
hello world
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
y:2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x:1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<problem>
<p>Problem #2</p>
</problem>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<sequential>
<vertical url_name="vertical_1" />
<vertical url_name="vertical_2" />
</sequential>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<vertical />
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<vertical>
<problem display_name="problem_1">
<problem display_name="inner_problem">
<p>Problem #1</p>
</problem>
</problem>
<problem url_name="problem_2"/>
</vertical>

0 comments on commit e20c3ad

Please sign in to comment.