From 1b71ace4b07eadcfe8a4ed9bdd6719ea525aec75 Mon Sep 17 00:00:00 2001 From: Mat Peterson Date: Wed, 2 Jul 2014 20:30:08 +0000 Subject: [PATCH] studio new style assumption corrections --- .../contentstore/tests/test_contentstore.py | 13 ++-- .../views/tests/test_checklists.py | 6 +- .../views/tests/test_course_index.py | 4 +- .../views/tests/test_course_updates.py | 5 +- .../contentstore/views/tests/test_helpers.py | 6 +- .../views/tests/test_import_export.py | 4 +- .../contentstore/views/tests/test_item.py | 2 +- .../contentstore/views/tests/test_preview.py | 2 +- .../modulestore/tests/test_modulestore.py | 59 ++++++++++--------- 9 files changed, 51 insertions(+), 50 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 5f396467ca..f97a180333 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -311,7 +311,6 @@ class ContentStoreToyCourseTest(ContentStoreTestCase): direct_store = self.store _, course_items = import_from_xml(direct_store, self.user.id, 'common/test/data/', ['toy']) usage_key = course_items[0].id.make_usage_key('vertical', 'vertical_test') - # also try a custom response which will trigger the 'is this course in whitelist' logic resp = self.client.get_json( get_url('xblock_view_handler', usage_key, kwargs={'view_name': 'container_preview'}) @@ -319,10 +318,10 @@ class ContentStoreToyCourseTest(ContentStoreTestCase): self.assertEqual(resp.status_code, 200) # These are the data-ids of the xblocks contained in the vertical. - self.assertContains(resp, 'edX+toy+2012_Fall+video+sample_video') - self.assertContains(resp, 'edX+toy+2012_Fall+video+separate_file_video') - self.assertContains(resp, 'edX+toy+2012_Fall+video+video_with_end_time') - self.assertContains(resp, 'edX+toy+2012_Fall+poll_question+T1_changemind_poll_foo_2') + self.assertContains(resp, 'edX/toy/video/sample_video') + self.assertContains(resp, 'edX/toy/video/separate_file_video') + self.assertContains(resp, 'edX/toy/video/video_with_end_time') + self.assertContains(resp, 'edX/toy/poll_question/T1_changemind_poll_foo_2') def test_delete(self): store = self.store @@ -1217,7 +1216,7 @@ class ContentStoreTest(ContentStoreTestCase): resp = self._show_course_overview(course.id) self.assertContains( resp, - '
', + '
', status_code=200, html=True ) @@ -1238,7 +1237,7 @@ class ContentStoreTest(ContentStoreTestCase): data = parse_json(resp) self.assertRegexpMatches( data['locator'], - r"location:MITx\+999\+Robot_Super_Course\+chapter\+([0-9]|[a-f]){3,}$" + r"MITx/999/chapter/([0-9]|[a-f]){3,}$" ) def test_capa_module(self): diff --git a/cms/djangoapps/contentstore/views/tests/test_checklists.py b/cms/djangoapps/contentstore/views/tests/test_checklists.py index b8729151cf..b86a78ce9c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_checklists.py +++ b/cms/djangoapps/contentstore/views/tests/test_checklists.py @@ -43,7 +43,7 @@ class ChecklistTestCase(CourseTestCase): response = self.client.get(self.checklists_url) self.assertContains(response, "Getting Started With Studio") # Verify expansion of action URL happened. - self.assertContains(response, 'course_team/slashes:mitX+333+Checklists_Course') + self.assertContains(response, 'course_team/mitX/333/Checklists_Course') # Verify persisted checklist does NOT have expanded URL. checklist_0 = self.get_persisted_checklists()[0] self.assertEqual('ManageUsers', get_action_url(checklist_0, 0)) @@ -136,8 +136,8 @@ class ChecklistTestCase(CourseTestCase): # Verify no side effect in the original list. self.assertEqual(get_action_url(checklist, index), stored) - test_expansion(self.course.checklists[0], 0, 'ManageUsers', '/course_team/slashes:mitX+333+Checklists_Course/') - test_expansion(self.course.checklists[1], 1, 'CourseOutline', '/course/slashes:mitX+333+Checklists_Course') + test_expansion(self.course.checklists[0], 0, 'ManageUsers', '/course_team/mitX/333/Checklists_Course/') + test_expansion(self.course.checklists[1], 1, 'CourseOutline', '/course/mitX/333/Checklists_Course') test_expansion(self.course.checklists[2], 0, 'http://help.edge.edx.org/', 'http://help.edge.edx.org/') diff --git a/cms/djangoapps/contentstore/views/tests/test_course_index.py b/cms/djangoapps/contentstore/views/tests/test_course_index.py index ed08d42387..ea31cb4f1d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_index.py @@ -96,7 +96,7 @@ class TestCourseIndex(CourseTestCase): # First spot check some values in the root response self.assertEqual(json_response['category'], 'course') - self.assertEqual(json_response['id'], 'location:MITx+999+Robot_Super_Course+course+Robot_Super_Course') + self.assertEqual(json_response['id'], 'i4x://MITx/999/course/Robot_Super_Course') self.assertEqual(json_response['display_name'], 'Robot Super Course') self.assertTrue(json_response['is_container']) self.assertFalse(json_response['is_draft']) @@ -106,7 +106,7 @@ class TestCourseIndex(CourseTestCase): self.assertTrue(len(children) > 0) first_child_response = children[0] self.assertEqual(first_child_response['category'], 'chapter') - self.assertEqual(first_child_response['id'], 'location:MITx+999+Robot_Super_Course+chapter+Week_1') + self.assertEqual(first_child_response['id'], 'i4x://MITx/999/chapter/Week_1') self.assertEqual(first_child_response['display_name'], 'Week 1') self.assertTrue(first_child_response['is_container']) self.assertFalse(first_child_response['is_draft']) diff --git a/cms/djangoapps/contentstore/views/tests/test_course_updates.py b/cms/djangoapps/contentstore/views/tests/test_course_updates.py index d1b33565b1..dd345426f4 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_updates.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_updates.py @@ -5,7 +5,8 @@ import json from contentstore.tests.test_course_settings import CourseTestCase from contentstore.utils import reverse_course_url, reverse_usage_url -from opaque_keys.edx.locations import Location, SlashSeparatedCourseKey +from opaque_keys.edx.locations import SlashSeparatedCourseKey +from opaque_keys.edx.keys import UsageKey from xmodule.modulestore.django import modulestore @@ -246,7 +247,7 @@ class CourseUpdateTest(CourseTestCase): self.assertHTMLEqual(payload['content'], content) updates_location = self.course.id.make_usage_key('course_info', 'updates') - self.assertTrue(isinstance(updates_location, Location)) + self.assertTrue(isinstance(updates_location, UsageKey)) self.assertEqual(updates_location.name, block) # check posting on handouts diff --git a/cms/djangoapps/contentstore/views/tests/test_helpers.py b/cms/djangoapps/contentstore/views/tests/test_helpers.py index 82c25c2b6e..6acc04ed7b 100644 --- a/cms/djangoapps/contentstore/views/tests/test_helpers.py +++ b/cms/djangoapps/contentstore/views/tests/test_helpers.py @@ -15,7 +15,7 @@ class HelpersTestCase(CourseTestCase): # Verify course URL self.assertEqual(xblock_studio_url(self.course), - u'/course/slashes:MITx+999+Robot_Super_Course') + u'/course/MITx/999/Robot_Super_Course') # Verify chapter URL chapter = ItemFactory.create(parent_location=self.course.location, category='chapter', @@ -31,13 +31,13 @@ class HelpersTestCase(CourseTestCase): vertical = ItemFactory.create(parent_location=sequential.location, category='vertical', display_name='Unit') self.assertEqual(xblock_studio_url(vertical), - u'/unit/location:MITx+999+Robot_Super_Course+vertical+Unit') + u'/unit/i4x://MITx/999/vertical/Unit') # Verify child vertical URL child_vertical = ItemFactory.create(parent_location=vertical.location, category='vertical', display_name='Child Vertical') self.assertEqual(xblock_studio_url(child_vertical), - u'/container/location:MITx+999+Robot_Super_Course+vertical+Child_Vertical') + u'/container/i4x://MITx/999/vertical/Child_Vertical') # Verify video URL video = ItemFactory.create(parent_location=child_vertical.location, category="video", diff --git a/cms/djangoapps/contentstore/views/tests/test_import_export.py b/cms/djangoapps/contentstore/views/tests/test_import_export.py index 878442f21d..767e5f9bd6 100644 --- a/cms/djangoapps/contentstore/views/tests/test_import_export.py +++ b/cms/djangoapps/contentstore/views/tests/test_import_export.py @@ -296,7 +296,7 @@ class ExportTestCase(CourseTestCase): """ fake_xblock = ItemFactory.create(parent_location=self.course.location, category='aawefawef') self.store.publish(fake_xblock.location, self.user.id) - self._verify_export_failure(u'/unit/location:MITx+999+Robot_Super_Course+course+Robot_Super_Course') + self._verify_export_failure(u'/unit/i4x://MITx/999/course/Robot_Super_Course') def test_export_failure_subsection_level(self): """ @@ -308,7 +308,7 @@ class ExportTestCase(CourseTestCase): category='aawefawef' ) - self._verify_export_failure(u'/unit/location:MITx+999+Robot_Super_Course+vertical+foo') + self._verify_export_failure(u'/unit/i4x://MITx/999/vertical/foo') def _verify_export_failure(self, expectedText): """ Export failure helper method. """ diff --git a/cms/djangoapps/contentstore/views/tests/test_item.py b/cms/djangoapps/contentstore/views/tests/test_item.py index 5666eeaa85..4ddfc9558d 100644 --- a/cms/djangoapps/contentstore/views/tests/test_item.py +++ b/cms/djangoapps/contentstore/views/tests/test_item.py @@ -158,7 +158,7 @@ class GetItem(ItemTest): html, # The instance of the wrapper class will have an auto-generated ID. Allow any # characters after wrapper. - (r'"/container/location:MITx\+999\+Robot_Super_Course\+wrapper\+\w+" class="action-button">\s*' + (r'"/container/i4x://MITx/999/wrapper/\w+" class="action-button">\s*' 'View') ) diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index 25ddce3458..e1c18711bd 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -43,6 +43,6 @@ class GetPreviewHtmlTestCase(TestCase): # Verify student view html is returned, and the usage ID is as expected. self.assertRegexpMatches( html, - 'data-usage-id="location:MITx\+999\+Robot_Super_Course\+html\+html_[0-9]*"' + 'data-usage-id="i4x://MITx/999/html/html_[0-9]*"' ) self.assertRegexpMatches(html, 'foobar') diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_modulestore.py index d848004eb2..6c359fd2a7 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_modulestore.py @@ -40,33 +40,34 @@ def check_has_course_method(modulestore, locator, locator_key_fields): assert_true(modulestore.has_course(locator, ignore_case)) for key_field in locator_key_fields: - locator_changes_that_should_not_be_found = [ # pylint: disable=invalid-name - # replace value for one of the keys - {key_field: 'fake'}, - # add a character at the end - {key_field: getattr(locator, key_field) + 'X'}, - # add a character in the beginning - {key_field: 'X' + getattr(locator, key_field)}, - ] - for changes in locator_changes_that_should_not_be_found: - search_locator = locator.replace(**changes) - assert_false( - modulestore.has_course(search_locator), - error_message.format(search_locator, ignore_case) - ) + if getattr(locator, key_field): + locator_changes_that_should_not_be_found = [ # pylint: disable=invalid-name + # replace value for one of the keys + {key_field: 'fake'}, + # add a character at the end + {key_field: getattr(locator, key_field) + 'X'}, + # add a character in the beginning + {key_field: 'X' + getattr(locator, key_field)}, + ] + for changes in locator_changes_that_should_not_be_found: + search_locator = locator.replace(**changes) + assert_false( + modulestore.has_course(search_locator), + error_message.format(search_locator, ignore_case) + ) - # test case [in]sensitivity - locator_case_changes = [ - {key_field: getattr(locator, key_field).upper()}, - {key_field: getattr(locator, key_field).capitalize()}, - {key_field: getattr(locator, key_field).capitalize().swapcase()}, - ] - for changes in locator_case_changes: - search_locator = locator.replace(**changes) - # if ignore_case is true, the course would be found with a different-cased course locator. - # if ignore_case is false, the course should NOT found given an incorrectly-cased locator. - assert_equals( - modulestore.has_course(search_locator, ignore_case) is not None, - ignore_case, - error_message.format(search_locator, ignore_case) - ) + # test case [in]sensitivity + locator_case_changes = [ + {key_field: getattr(locator, key_field).upper()}, + {key_field: getattr(locator, key_field).capitalize()}, + {key_field: getattr(locator, key_field).capitalize().swapcase()}, + ] + for changes in locator_case_changes: + search_locator = locator.replace(**changes) + # if ignore_case is true, the course would be found with a different-cased course locator. + # if ignore_case is false, the course should NOT found given an incorrectly-cased locator. + assert_equals( + modulestore.has_course(search_locator, ignore_case) is not None, + ignore_case, + error_message.format(search_locator, ignore_case) + )