From c17cb38cd9fda2da93fab930fb2a31763929d79e Mon Sep 17 00:00:00 2001 From: zubiar-arbi Date: Tue, 4 Mar 2014 17:41:37 +0500 Subject: [PATCH] add location of handouts in loc_mapper STUD-1248 --- cms/djangoapps/contentstore/views/item.py | 6 ++++++ .../views/tests/test_course_updates.py | 19 ++++++++++++++++++- common/test/acceptance/fixtures/course.py | 17 ----------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py index a56ea58447..5696e213ad 100644 --- a/cms/djangoapps/contentstore/views/item.py +++ b/cms/djangoapps/contentstore/views/item.py @@ -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, diff --git a/cms/djangoapps/contentstore/views/tests/test_course_updates.py b/cms/djangoapps/contentstore/views/tests/test_course_updates.py index 7c505f0deb..1c56a0eb11 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_updates.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_updates.py @@ -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) diff --git a/common/test/acceptance/fixtures/course.py b/common/test/acceptance/fixtures/course.py index e8adbf4e4b..5d54f66112 100644 --- a/common/test/acceptance/fixtures/course.py +++ b/common/test/acceptance/fixtures/course.py @@ -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.