Commit c17cb38c by zubiar-arbi

add location of handouts in loc_mapper

STUD-1248
parent b4478081
......@@ -127,6 +127,12 @@ def xblock_handler(request, tag=None, package_id=None, branch=None, version_guid
return _delete_item_at_location(old_location, delete_children, delete_all_versions, request.user)
else: # Since we have a package_id, we are updating an existing xblock.
if block == 'handouts' and old_location is None:
# update handouts location in loc_mapper
course_location = loc_mapper().translate_locator_to_location(locator, get_course=True)
old_location = course_location.replace(category='course_info', name=block)
locator = loc_mapper().translate_location(course_location.course_id, old_location)
return _save_item(
request,
locator,
......
......@@ -230,7 +230,8 @@ class CourseUpdateTest(CourseTestCase):
def test_post_course_update(self):
"""
Test that a user can successfully post on course updates of a course whose location in not in loc_mapper
Test that a user can successfully post on course updates and handouts of a course
whose location in not in loc_mapper
"""
# create a course via the view handler
course_location = Location(['i4x', 'Org_1', 'Course_1', 'course', 'Run_1'])
......@@ -270,3 +271,19 @@ class CourseUpdateTest(CourseTestCase):
updates_locator = loc_mapper().translate_location(course_location.course_id, updates_location)
self.assertTrue(isinstance(updates_locator, BlockUsageLocator))
self.assertEqual(updates_locator.block_id, block)
# check posting on handouts
block = u'handouts'
handouts_locator = BlockUsageLocator(
package_id=updates_locator.package_id, branch=updates_locator.branch, version_guid=version, block_id=block
)
course_handouts_url = handouts_locator.url_reverse('xblock')
content = u"Sample handout"
payload = {"data": content}
resp = self.client.ajax_post(course_handouts_url, payload)
# check that response status is 200 not 500
self.assertEqual(resp.status_code, 200)
payload = json.loads(resp.content)
self.assertHTMLEqual(payload['data'], content)
......@@ -224,9 +224,6 @@ class CourseFixture(StudioApiFixture):
"""
self._create_course()
# Remove once STUD-1248 is resolved
self._update_loc_map()
self._install_course_updates()
self._install_course_handouts()
self._configure_course()
......@@ -362,20 +359,6 @@ class CourseFixture(StudioApiFixture):
"Could not add update to course: {0}. Status was {1}".format(
update, response.status_code))
def _update_loc_map(self):
"""
Force update of the location map.
"""
# We perform a GET request to force Studio to update the course location map.
# This is a (minor) bug in the Studio RESTful API: STUD-1248
url = "{base}/course_info/{course}".format(base=STUDIO_BASE_URL, course=self._course_loc)
response = self.session.get(url, headers={'Accept': 'text/html'})
if not response.ok:
raise CourseFixtureError(
"Could not load Studio dashboard to trigger location map update. Status was {0}".format(
response.status_code))
def _create_xblock_children(self, parent_loc, xblock_descriptions):
"""
Recursively create XBlock children.
......
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