diff --git a/cms/djangoapps/contentstore/api/tests/base.py b/cms/djangoapps/contentstore/api/tests/base.py index dd460734645c..150f299538ec 100644 --- a/cms/djangoapps/contentstore/api/tests/base.py +++ b/cms/djangoapps/contentstore/api/tests/base.py @@ -43,44 +43,44 @@ def initialize_course(cls, course): cls.store.update_item(course, cls.staff.id) cls.section = BlockFactory.create( - parent_location=course.location, + parent_location=course.usage_key, category="chapter", ) cls.subsection1 = BlockFactory.create( - parent_location=cls.section.location, + parent_location=cls.section.usage_key, category="sequential", ) unit1 = BlockFactory.create( - parent_location=cls.subsection1.location, + parent_location=cls.subsection1.usage_key, category="vertical", ) BlockFactory.create( - parent_location=unit1.location, + parent_location=unit1.usage_key, category="video", ) BlockFactory.create( - parent_location=unit1.location, + parent_location=unit1.usage_key, category="problem", ) cls.subsection2 = BlockFactory.create( - parent_location=cls.section.location, + parent_location=cls.section.usage_key, category="sequential", ) unit2 = BlockFactory.create( - parent_location=cls.subsection2.location, + parent_location=cls.subsection2.usage_key, category="vertical", ) unit3 = BlockFactory.create( - parent_location=cls.subsection2.location, + parent_location=cls.subsection2.usage_key, category="vertical", ) BlockFactory.create( - parent_location=unit3.location, + parent_location=unit3.usage_key, category="video", ) BlockFactory.create( - parent_location=unit3.location, + parent_location=unit3.usage_key, category="video", ) diff --git a/cms/djangoapps/contentstore/api/tests/test_validation.py b/cms/djangoapps/contentstore/api/tests/test_validation.py index a091eedcc577..c679cf89fa26 100644 --- a/cms/djangoapps/contentstore/api/tests/test_validation.py +++ b/cms/djangoapps/contentstore/api/tests/test_validation.py @@ -76,11 +76,11 @@ def initialize_course(cls, course): ) section = BlockFactory.create( - parent_location=course.location, + parent_location=course.usage_key, category="chapter", ) BlockFactory.create( - parent_location=section.location, + parent_location=section.usage_key, category="sequential", ) @@ -183,23 +183,23 @@ def initialize_course(cls, course): Sets up test course structure. """ section = BlockFactory.create( - parent_location=course.location, + parent_location=course.usage_key, category="chapter", ) subsection = BlockFactory.create( - parent_location=section.location, + parent_location=section.usage_key, category="sequential", ) unit = BlockFactory.create( - parent_location=subsection.location, + parent_location=subsection.usage_key, category="vertical", ) cls.block1 = BlockFactory.create( - parent_location=unit.location, + parent_location=unit.usage_key, category="library_content", ) cls.block2 = BlockFactory.create( - parent_location=unit.location, + parent_location=unit.usage_key, category="library_content", ) @@ -273,8 +273,8 @@ def test_list_ready_to_update_reference_success(self, mock_block, mock_auth): data = response.json() self.assertListEqual(data, [ - {'usage_key': str(self.block1.location)}, - {'usage_key': str(self.block2.location)}, + {'usage_key': str(self.block1.usage_key)}, + {'usage_key': str(self.block2.usage_key)}, ]) mock_auth.assert_called_once() diff --git a/cms/djangoapps/contentstore/api/views/course_quality.py b/cms/djangoapps/contentstore/api/views/course_quality.py index 6ff2c02e2f6c..505f58924a47 100644 --- a/cms/djangoapps/contentstore/api/views/course_quality.py +++ b/cms/djangoapps/contentstore/api/views/course_quality.py @@ -218,12 +218,12 @@ def _get_subsections_and_units(cls, course, request): for unit in visible_units: leaf_blocks = cls._get_leaf_blocks(unit) - unit_dict[unit.location] = dict( + unit_dict[unit.usage_key] = dict( num_leaf_blocks=len(leaf_blocks), - leaf_block_types={block.location.block_type for block in leaf_blocks}, + leaf_block_types={block.usage_key.block_type for block in leaf_blocks}, ) - subsection_dict[subsection.location] = unit_dict + subsection_dict[subsection.usage_key] = unit_dict return subsection_dict @classmethod @@ -257,7 +257,7 @@ def _get_children(cls, parent): # lint-amnesty, pylint: disable=missing-functio def _get_leaf_blocks(cls, unit): # lint-amnesty, pylint: disable=missing-function-docstring def leaf_filter(block): return ( - block.location.block_type not in ('chapter', 'sequential', 'vertical') and + block.usage_key.block_type not in ('chapter', 'sequential', 'vertical') and len(cls._get_children(block)) == 0 ) diff --git a/cms/djangoapps/contentstore/api/views/course_validation.py b/cms/djangoapps/contentstore/api/views/course_validation.py index fd3e447b2746..1553ba1c37d8 100644 --- a/cms/djangoapps/contentstore/api/views/course_validation.py +++ b/cms/djangoapps/contentstore/api/views/course_validation.py @@ -143,7 +143,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis ] assignments_with_dates_before_start = ( [ - {'id': str(a.location), 'display_name': a.display_name} + {'id': str(a.usage_key), 'display_name': a.display_name} for a in assignments_with_dates if a.due < course.start ] @@ -153,7 +153,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis assignments_with_dates_after_end = ( [ - {'id': str(a.location), 'display_name': a.display_name} + {'id': str(a.usage_key), 'display_name': a.display_name} for a in assignments_with_dates if a.due > course.end ] @@ -169,7 +169,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis ] assignments_with_dates_before_start = ( [ - {'id': str(a.location), 'display_name': a.display_name} + {'id': str(a.usage_key), 'display_name': a.display_name} for a in assignments_with_dates if a.due < course.start ] @@ -179,7 +179,7 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis assignments_with_dates_after_end = ( [ - {'id': str(a.location), 'display_name': a.display_name} + {'id': str(a.usage_key), 'display_name': a.display_name} for a in assignments_with_dates if a.due > course.end ] @@ -200,14 +200,14 @@ def _assignments_validation(self, course, request): # lint-amnesty, pylint: dis parent_unit = modulestore().get_item(ora.parent) parent_assignment = modulestore().get_item(parent_unit.parent) assignments_with_ora_dates_before_start.append({ - 'id': str(parent_assignment.location), + 'id': str(parent_assignment.usage_key), 'display_name': parent_assignment.display_name }) if course.end and self._has_date_after_end(ora, course.end): parent_unit = modulestore().get_item(ora.parent) parent_assignment = modulestore().get_item(parent_unit.parent) assignments_with_ora_dates_after_end.append({ - 'id': str(parent_assignment.location), + 'id': str(parent_assignment.usage_key), 'display_name': parent_assignment.display_name }) diff --git a/cms/djangoapps/contentstore/asset_storage_handlers.py b/cms/djangoapps/contentstore/asset_storage_handlers.py index bbb1deaad21a..d03b2a90a6cb 100644 --- a/cms/djangoapps/contentstore/asset_storage_handlers.py +++ b/cms/djangoapps/contentstore/asset_storage_handlers.py @@ -188,7 +188,7 @@ def _get_asset_usage_path(course_key, assets): if handout and asset_key_string in handout: usage_dict = {'display_location': '', 'url': ''} xblock_display_name = getattr(block, 'display_name', '') - xblock_location = str(block.location) + xblock_location = str(block.usage_key) unit = block.get_parent() unit_location = str(block.parent) unit_display_name = getattr(unit, 'display_name', '') @@ -204,7 +204,7 @@ def _get_asset_usage_path(course_key, assets): if static_path in data or asset_key_string in data: usage_dict = {'display_location': '', 'url': ''} xblock_display_name = getattr(block, 'display_name', '') - xblock_location = str(block.location) + xblock_location = str(block.usage_key) unit = block.get_parent() unit_location = str(block.parent) unit_display_name = getattr(unit, 'display_name', '') diff --git a/cms/djangoapps/contentstore/core/course_optimizer_provider.py b/cms/djangoapps/contentstore/core/course_optimizer_provider.py index 134329992cfe..a83a06acbeb5 100644 --- a/cms/djangoapps/contentstore/core/course_optimizer_provider.py +++ b/cms/djangoapps/contentstore/core/course_optimizer_provider.py @@ -244,7 +244,7 @@ def _update_node_tree_and_dictionary(block, link, link_state, node_tree, diction # Traverse the path and build the tree structure for xblock in path: - xblock_id = xblock.location + xblock_id = xblock.usage_key updated_dictionary.setdefault( xblock_id, { @@ -258,7 +258,7 @@ def _update_node_tree_and_dictionary(block, link, link_state, node_tree, diction # Add block-level details for the last xblock in the path (URL and broken/locked links) updated_dictionary[xblock_id].setdefault( 'url', - f'/course/{block.course_id}/editor/{block.category}/{block.location}' + f'/course/{block.course_id}/editor/{block.category}/{block.usage_key}' ) # The link_state == True condition is maintained for backward compatibility. @@ -358,7 +358,7 @@ def sort_course_sections(course_key, data): if not course_blocks or 'LinkCheckOutput' not in data or 'sections' not in data['LinkCheckOutput']: return data - sorted_section_ids = [section.location for section in course_blocks[0].get_children()] + sorted_section_ids = [section.usage_key for section in course_blocks[0].get_children()] sections_map = {section['id']: section for section in data['LinkCheckOutput']['sections']} data['LinkCheckOutput']['sections'] = [ sections_map[section_id] diff --git a/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py b/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py index 0780848dfda9..5a5dcb402554 100644 --- a/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py +++ b/cms/djangoapps/contentstore/core/tests/test_course_optimizer_provider.py @@ -61,10 +61,10 @@ def test_update_node_tree_and_dictionary_returns_node_tree(self): when passed a block level xblock. """ expected_tree = { - self.mock_section.location: { - self.mock_subsection.location: { - self.mock_unit.location: { - self.mock_block.location: {} + self.mock_section.usage_key: { + self.mock_subsection.usage_key: { + self.mock_unit.usage_key: { + self.mock_block.usage_key: {} } } } @@ -81,22 +81,22 @@ def test_update_node_tree_and_dictionary_returns_dictionary(self): when passed a block level xblock. """ expected_dictionary = { - self.mock_section.location: { + self.mock_section.usage_key: { 'display_name': 'Section Name', 'category': 'chapter' }, - self.mock_subsection.location: { + self.mock_subsection.usage_key: { 'display_name': 'Subsection Name', 'category': 'sequential' }, - self.mock_unit.location: { + self.mock_unit.usage_key: { 'display_name': 'Unit Name', 'category': 'vertical' }, - self.mock_block.location: { + self.mock_block.usage_key: { 'display_name': 'Block Name', 'category': 'html', - 'url': f'/course/{self.course.id}/editor/html/{self.mock_block.location}', + 'url': f'/course/{self.course.id}/editor/html/{self.mock_block.usage_key}', 'locked_links': ['example_link'] } } @@ -375,12 +375,12 @@ def test_course_updates_and_custom_pages_structure(self): # Test data that represents the broken links JSON structure json_content = [ [ - str(self.mock_block.location), + str(self.mock_block.usage_key), "http://content-link.com", LinkState.BROKEN, ], [ - str(self.mock_unit.location), + str(self.mock_unit.usage_key), "http://unit-link.com", LinkState.LOCKED, ], diff --git a/cms/djangoapps/contentstore/course_group_config.py b/cms/djangoapps/contentstore/course_group_config.py index a6babd0a0c2f..87bf18d91803 100644 --- a/cms/djangoapps/contentstore/course_group_config.py +++ b/cms/djangoapps/contentstore/course_group_config.py @@ -139,7 +139,7 @@ def _get_usage_dict(course, unit, block, scheme_name=None): unit_url = reverse_usage_url( 'container_handler', - course.location.course_key.make_usage_key(unit_for_url.location.block_type, unit_for_url.location.block_id) + course.usage_key.course_key.make_usage_key(unit_for_url.usage_key.block_type, unit_for_url.usage_key.block_id) ) usage_dict = {'label': f"{unit.display_name} / {block.display_name}", 'url': unit_url} @@ -194,7 +194,7 @@ def _get_content_experiment_usage_info(store, course, split_tests): # pylint: d for split_test in split_tests: unit = split_test.get_parent() if not unit: - log.warning("Unable to find parent for split_test %s", split_test.location) + log.warning("Unable to find parent for split_test %s", split_test.usage_key) # Make sure that this user_partition appears in the output even though it has no content usage_info[split_test.user_partition_id] = [] continue @@ -234,7 +234,7 @@ def get_partitions_usage_info(store, course): for block, partition_id, group_id in GroupConfiguration._iterate_items_and_group_ids(course, items): unit = block.get_parent() if not unit: - log.warning("Unable to find parent for component %s", block.location) + log.warning("Unable to find parent for component %s", block.usage_key) continue usage_info[partition_id][group_id].append(GroupConfiguration._get_usage_dict( diff --git a/cms/djangoapps/contentstore/courseware_index.py b/cms/djangoapps/contentstore/courseware_index.py index b7b74992035a..d6e4ffb2a5b6 100644 --- a/cms/djangoapps/contentstore/courseware_index.py +++ b/cms/djangoapps/contentstore/courseware_index.py @@ -161,7 +161,7 @@ def get_item_location(item): """ Gets the version agnostic item location """ - return item.location.version_agnostic().replace(branch=None) + return item.usage_key.version_agnostic().replace(branch=None) def prepare_item_index(item, skip_index=False, groups_usage_info=None): """ @@ -192,7 +192,7 @@ def prepare_item_index(item, skip_index=False, groups_usage_info=None): for group in split_partition.groups: group_id = str(group.id) child_location = item.group_id_to_child.get(group_id, None) - if child_location == split_test_child.location: + if child_location == split_test_child.usage_key: groups_usage_info.update({ str(get_item_location(split_test_child)): [group_id], }) @@ -242,8 +242,8 @@ def prepare_item_index(item, skip_index=False, groups_usage_info=None): return item_content_groups except Exception as err: # pylint: disable=broad-except # broad exception so that index operation does not fail on one item of many - log.warning('Could not index item: %s - %r', item.location, err) - error_list.append(_('Could not index item: {}').format(item.location)) + log.warning('Could not index item: %s - %r', item.usage_key, err) + error_list.append(_('Could not index item: {}').format(item.usage_key)) try: with modulestore.branch_setting(ModuleStoreEnum.RevisionOption.published_only): @@ -617,7 +617,7 @@ def index_about_information(cls, modulestore, course): # load data for all of the 'about' blocks for this course into a dictionary about_dictionary = { - item.location.block_id: item.data + item.usage_key.block_id: item.data for item in modulestore.get_items(course.id, qualifiers={"category": "about"}) } diff --git a/cms/djangoapps/contentstore/exams.py b/cms/djangoapps/contentstore/exams.py index 8a4ddc09425e..798a1112e53d 100644 --- a/cms/djangoapps/contentstore/exams.py +++ b/cms/djangoapps/contentstore/exams.py @@ -56,7 +56,7 @@ def register_exams(course_key): exams_list = [] locations = [] for timed_exam in timed_exams: - location = str(timed_exam.location) + location = str(timed_exam.usage_key) msg = ( 'Found {location} as an exam in course structure.'.format( location=location @@ -84,7 +84,7 @@ def register_exams(course_key): exams_list.append({ 'course_id': str(course_key), - 'content_id': str(timed_exam.location), + 'content_id': str(timed_exam.usage_key), 'exam_name': timed_exam.display_name, 'time_limit_mins': timed_exam.default_time_limit_minutes, # If the subsection has no due date, then infer a due date from the course end date. This behavior is a diff --git a/cms/djangoapps/contentstore/helpers.py b/cms/djangoapps/contentstore/helpers.py index 9bfab1f1f385..df2e60e8ea12 100644 --- a/cms/djangoapps/contentstore/helpers.py +++ b/cms/djangoapps/contentstore/helpers.py @@ -69,7 +69,7 @@ def get_parent_xblock(xblock): """ Returns the xblock that is the parent of the specified xblock, or None if it has no parent. """ - locator = xblock.location + locator = xblock.usage_key parent_location = modulestore().get_parent_location(locator) if parent_location is None: @@ -153,17 +153,17 @@ def xblock_studio_url(xblock, parent_xblock=None, find_parent=False): return None category = xblock.category if category == 'course': - return reverse_course_url('course_handler', xblock.location.course_key) + return reverse_course_url('course_handler', xblock.usage_key.course_key) elif category in ('chapter', 'sequential'): return '{url}?show={usage_key}'.format( - url=reverse_course_url('course_handler', xblock.location.course_key), - usage_key=urllib.parse.quote(str(xblock.location)) + url=reverse_course_url('course_handler', xblock.usage_key.course_key), + usage_key=urllib.parse.quote(str(xblock.usage_key)) ) elif category == 'library': - library_key = xblock.location.course_key + library_key = xblock.usage_key.course_key return reverse_library_url('library_handler', library_key) else: - return reverse_usage_url('container_handler', xblock.location) + return reverse_usage_url('container_handler', xblock.usage_key) def xblock_lms_url(xblock) -> str: @@ -177,7 +177,7 @@ def xblock_lms_url(xblock) -> str: str: The LMS URL for the specified xblock. """ lms_root_url = configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL) - return f"{lms_root_url}/courses/{xblock.location.course_key}/jump_to/{xblock.location}" + return f"{lms_root_url}/courses/{xblock.usage_key.course_key}/jump_to/{xblock.usage_key}" def xblock_embed_lms_url(xblock) -> str: @@ -191,7 +191,7 @@ def xblock_embed_lms_url(xblock) -> str: str: The LMS URL for the specified xblock in embed mode. """ lms_root_url = configuration_helpers.get_value('LMS_ROOT_URL', settings.LMS_ROOT_URL) - return f"{lms_root_url}/xblock/{xblock.location}" + return f"{lms_root_url}/xblock/{xblock.usage_key}" def xblock_type_display_name(xblock, default_display_name=None): @@ -597,7 +597,7 @@ def _import_xml_node_to_parent( # Save the XBlock into modulestore. We need to save the block and its parent for this to work: new_xblock = store.update_item(temp_xblock, user.id, allow_not_found=True) new_xblock.parent = parent_key - parent_xblock.children.append(new_xblock.location) + parent_xblock.children.append(new_xblock.usage_key) store.update_item(parent_xblock, user.id) children_handled = False @@ -622,13 +622,13 @@ def _import_xml_node_to_parent( # copy the tags from the upstream as ready-only content_tagging_api.copy_tags_as_read_only( new_xblock.upstream, - new_xblock.location, + new_xblock.usage_key, ) elif tags and node_copied_from: object_tags = tags.get(node_copied_from) if object_tags: content_tagging_api.set_all_object_tags( - content_key=new_xblock.location, + content_key=new_xblock.usage_key, object_tags=object_tags, ) @@ -812,7 +812,7 @@ def is_item_in_course_tree(item): if its parent has been deleted and is now an orphan. """ ancestor = item.get_parent() - while ancestor is not None and ancestor.location.block_type != "course": + while ancestor is not None and ancestor.usage_key.block_type != "course": ancestor = ancestor.get_parent() return ancestor is not None diff --git a/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py b/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py index b9a4368f6d6b..34a030dd1e94 100644 --- a/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py +++ b/cms/djangoapps/contentstore/management/commands/delete_v1_libraries.py @@ -75,7 +75,7 @@ def handle(self, *args, **options): # lint-amnesty, pylint: disable=unused-argu store = modulestore() if query_yes_no(self.CONFIRMATION_PROMPT, default="no"): v1_library_keys = [ - library.location.library_key.replace(branch=None) for library in store.get_libraries() + library.usage_key.library_key.replace(branch=None) for library in store.get_libraries() ] else: return diff --git a/cms/djangoapps/contentstore/management/commands/export_content_library.py b/cms/djangoapps/contentstore/management/commands/export_content_library.py index b56c172e374e..e51841f533cb 100644 --- a/cms/djangoapps/contentstore/management/commands/export_content_library.py +++ b/cms/djangoapps/contentstore/management/commands/export_content_library.py @@ -62,4 +62,4 @@ def handle(self, *args, **options): tarball.file.seek(0) with open(target, 'wb') as f: shutil.copyfileobj(tarball.file, f) - print(f'Library "{library.location.library_key}" exported to "{target}"') + print(f'Library "{library.usage_key.library_key}" exported to "{target}"') diff --git a/cms/djangoapps/contentstore/management/commands/import_content_library.py b/cms/djangoapps/contentstore/management/commands/import_content_library.py index 7d2a64825a31..9584c85d3ea8 100644 --- a/cms/djangoapps/contentstore/management/commands/import_content_library.py +++ b/cms/djangoapps/contentstore/management/commands/import_content_library.py @@ -111,8 +111,8 @@ def _get_or_create_library(org, number, display_name, user): "display_name": display_name }, ) - add_instructor(library.location.library_key, user, user) - return library.location.library_key, True + add_instructor(library.usage_key.library_key, user, user) + return library.usage_key.library_key, True except DuplicateCourseError: # Course exists, return its key return LibraryLocator(org=org, library=number), False diff --git a/cms/djangoapps/contentstore/management/commands/reindex_library.py b/cms/djangoapps/contentstore/management/commands/reindex_library.py index cf352576f6be..594b56c6d8a1 100644 --- a/cms/djangoapps/contentstore/management/commands/reindex_library.py +++ b/cms/djangoapps/contentstore/management/commands/reindex_library.py @@ -55,7 +55,7 @@ def handle(self, *args, **options): if options['all']: if query_yes_no(self.CONFIRMATION_PROMPT, default="no"): - library_keys = [library.location.library_key.replace(branch=None) for library in store.get_libraries()] + library_keys = [library.usage_key.library_key.replace(branch=None) for library in store.get_libraries()] else: return else: diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py b/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py index 75650d41dcb2..a4349faa7927 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py @@ -90,7 +90,7 @@ def create_split_course_with_published_orphan(self): orphan = self.store.create_item( self.user.id, course.id, 'html', "PublishedOnlyOrphan" ) - self.store.publish(orphan.location, self.user.id) + self.store.publish(orphan.usage_key, self.user.id) # grab the published branch of the course published_branch = course.id.for_branch( @@ -104,13 +104,13 @@ def create_split_course_with_published_orphan(self): # delete this orphan from the draft branch without # auto-publishing this change to the published branch self.store.delete_item( - orphan.location, self.user.id, skip_auto_publish=True + orphan.usage_key, self.user.id, skip_auto_publish=True ) # now there should be no orphans in the draft branch, but # there should be one in published self.assertOrphanCount(course.id, 0) self.assertOrphanCount(published_branch, 1) - self.assertIn(orphan.location, [x.location for x in self.store.get_items(published_branch)]) + self.assertIn(orphan.usage_key, [x.usage_key for x in self.store.get_items(published_branch)]) return course, orphan diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py b/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py index b9372d15204b..1c5b7bd7c832 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_fix_not_found.py @@ -25,7 +25,7 @@ def test_no_args(self): def test_fix_not_found(self): course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split) - BlockFactory.create(category='chapter', parent_location=course.location) + BlockFactory.create(category='chapter', parent_location=course.usage_key) # get course again in order to update its children list course = self.store.get_course(course.id) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py b/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py index ea16707d7eb8..e7493c36aaff 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py @@ -76,16 +76,16 @@ def test_force_publish(self): Test 'force_publish' command """ # Add some changes to course - chapter = BlockFactory.create(category='chapter', parent_location=self.course.location) + chapter = BlockFactory.create(category='chapter', parent_location=self.course.usage_key) self.store.create_child( self.test_user_id, - chapter.location, + chapter.usage_key, 'html', block_id='html_component' ) # verify that course has changes. - self.assertTrue(self.store.has_changes(self.store.get_item(self.course.location))) + self.assertTrue(self.store.has_changes(self.store.get_item(self.course.usage_key))) # get draft and publish branch versions versions = get_course_versions(str(self.course.id)) @@ -102,7 +102,7 @@ def test_force_publish(self): call_command('force_publish', str(self.course.id), '--commit') # verify that course has no changes - self.assertFalse(self.store.has_changes(self.store.get_item(self.course.location))) + self.assertFalse(self.store.has_changes(self.store.get_item(self.course.usage_key))) # get new draft and publish branch versions versions = get_course_versions(str(self.course.id)) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py index 6d14b4a339f2..9a85f404acdf 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py @@ -52,7 +52,7 @@ def setUp(self): def _get_lib_key(self, library): """ Get's library key as it is passed to indexer """ - return library.location.library_key + return library.usage_key.library_key def _build_calls(self, *courses): """ Builds a list of mock.call instances representing calls to reindexing method """ diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py index d5013cf69462..98a80d600cf3 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py @@ -44,7 +44,7 @@ def setUp(self): def _get_lib_key(self, library): """ Get's library key as it is passed to indexer """ - return library.location.library_key + return library.usage_key.library_key def _build_calls(self, *libraries): """ BUilds a list of mock.call instances representing calls to reindexing method """ diff --git a/cms/djangoapps/contentstore/outlines.py b/cms/djangoapps/contentstore/outlines.py index 72d5c4f257f0..4bc49adc2bfe 100644 --- a/cms/djangoapps/contentstore/outlines.py +++ b/cms/djangoapps/contentstore/outlines.py @@ -51,12 +51,12 @@ def _error_for_not_section(not_section): """ return ContentErrorData( message=( - f' contains a <{not_section.location.block_type}> tag with ' - f'url_name="{not_section.location.block_id}" and ' + f' contains a <{not_section.usage_key.block_type}> tag with ' + f'url_name="{not_section.usage_key.block_id}" and ' f'display_name="{getattr(not_section, "display_name", "")}". ' f'Expected tag instead.' ), - usage_key=_remove_version_info(not_section.location), + usage_key=_remove_version_info(not_section.usage_key), ) @@ -68,14 +68,14 @@ def _error_for_not_sequence(section, not_sequence): """ return ContentErrorData( message=( - f' with url_name="{section.location.block_id}" and ' + f' with url_name="{section.usage_key.block_id}" and ' f'display_name="{section.display_name}" contains a ' - f'<{not_sequence.location.block_type}> tag with ' - f'url_name="{not_sequence.location.block_id}" and ' + f'<{not_sequence.usage_key.block_type}> tag with ' + f'url_name="{not_sequence.usage_key.block_id}" and ' f'display_name="{getattr(not_sequence, "display_name", "")}". ' f'Expected a tag.' ), - usage_key=_remove_version_info(not_sequence.location), + usage_key=_remove_version_info(not_sequence.usage_key), ) @@ -88,18 +88,18 @@ def _error_for_duplicate_child(section, duplicate_child, original_section): """ return ContentErrorData( message=( - f' with url_name="{section.location.block_id}" and ' + f' with url_name="{section.usage_key.block_id}" and ' f'display_name="{section.display_name}" contains a ' - f'<{duplicate_child.location.block_type}> tag with ' - f'url_name="{duplicate_child.location.block_id}" and ' + f'<{duplicate_child.usage_key.block_type}> tag with ' + f'url_name="{duplicate_child.usage_key.block_id}" and ' f'display_name="{getattr(duplicate_child, "display_name", "")}" ' f'that is defined in another section with ' - f'url_name="{original_section.location.block_id}" and ' + f'url_name="{original_section.usage_key.block_id}" and ' f'display_name="{original_section.display_name}". Expected a ' f'unique tag instead.' ), - usage_key=_remove_version_info(duplicate_child.location), + usage_key=_remove_version_info(duplicate_child.usage_key), ) @@ -234,12 +234,12 @@ def _make_section_data(section, unique_sequences): section_errors = [] # First check if it's not a section at all, and short circuit if it isn't. - if section.location.block_type != 'chapter': + if section.usage_key.block_type != 'chapter': section_errors.append(_error_for_not_section(section)) return (None, section_errors, unique_sequences) section_user_partition_groups, error = _make_user_partition_groups( - section.location, section.group_access + section.usage_key, section.group_access ) # Invalid user partition errors aren't fatal. Just log and continue on. if error: @@ -249,21 +249,21 @@ def _make_section_data(section, unique_sequences): sequences_data = [] for sequence in section.get_children(): - if sequence.location.block_type not in valid_sequence_tags: + if sequence.usage_key.block_type not in valid_sequence_tags: section_errors.append(_error_for_not_sequence(section, sequence)) continue # We need to check if there are duplicate sequences. If there are # duplicate sequences the course outline generation will fail. We ignore # the duplicated sequences, so they will not be sent to # learning_sequences. - if sequence.location in unique_sequences: - original_section = unique_sequences[sequence.location] + if sequence.usage_key in unique_sequences: + original_section = unique_sequences[sequence.usage_key] section_errors.append(_error_for_duplicate_child(section, sequence, original_section)) continue else: - unique_sequences[sequence.location] = section + unique_sequences[sequence.usage_key] = section seq_user_partition_groups, error = _make_user_partition_groups( - sequence.location, sequence.group_access + sequence.usage_key, sequence.group_access ) if error: section_errors.append(error) @@ -279,19 +279,19 @@ def _make_section_data(section, unique_sequences): # no conflicting value set at the Sequence level. if user_partition_id not in seq_user_partition_groups: section_errors.append( - _make_bubbled_up_error(sequence.location, user_partition_id, group_ids) + _make_bubbled_up_error(sequence.usage_key, user_partition_id, group_ids) ) seq_user_partition_groups[user_partition_id] = group_ids else: section_errors.append( _make_not_bubbled_up_error( - sequence.location, sequence.group_access, user_partition_id, group_ids + sequence.usage_key, sequence.group_access, user_partition_id, group_ids ) ) sequences_data.append( CourseLearningSequenceData( - usage_key=_remove_version_info(sequence.location), + usage_key=_remove_version_info(sequence.usage_key), title=sequence.display_name_with_default, inaccessible_after_due=sequence.hide_after_due, exam=ExamData( @@ -308,7 +308,7 @@ def _make_section_data(section, unique_sequences): ) section_data = CourseSectionData( - usage_key=_remove_version_info(section.location), + usage_key=_remove_version_info(section.usage_key), title=section.display_name_with_default, sequences=sequences_data, visibility=VisibilityData( diff --git a/cms/djangoapps/contentstore/proctoring.py b/cms/djangoapps/contentstore/proctoring.py index bd33049006c4..93e8c140bd40 100644 --- a/cms/djangoapps/contentstore/proctoring.py +++ b/cms/djangoapps/contentstore/proctoring.py @@ -71,7 +71,7 @@ def register_special_exams(course_key): for timed_exam in timed_exams: msg = ( 'Found {location} as a timed-exam in course structure. Inspecting...'.format( - location=str(timed_exam.location) + location=str(timed_exam.usage_key) ) ) log.info(msg) @@ -89,7 +89,7 @@ def register_special_exams(course_key): } try: - exam = get_exam_by_content_id(str(course_key), str(timed_exam.location)) + exam = get_exam_by_content_id(str(course_key), str(timed_exam.usage_key)) # update case, make sure everything is synced exam_metadata['exam_id'] = exam['id'] @@ -99,7 +99,7 @@ def register_special_exams(course_key): except ProctoredExamNotFoundException: exam_metadata['course_id'] = str(course_key) - exam_metadata['content_id'] = str(timed_exam.location) + exam_metadata['content_id'] = str(timed_exam.usage_key) exam_id = create_exam(**exam_metadata) msg = f'Created new timed exam {exam_id}' log.info(msg) @@ -136,7 +136,7 @@ def register_special_exams(course_key): search = [ timed_exam for timed_exam in timed_exams if - str(timed_exam.location) == exam['content_id'] + str(timed_exam.usage_key) == exam['content_id'] ] if not search: # This means it was turned off in Studio, we need to mark diff --git a/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py b/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py index 5e83c9313617..e6702438afc0 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py +++ b/cms/djangoapps/contentstore/rest_api/v0/tests/test_tabs.py @@ -44,7 +44,7 @@ def setUp(self): # add a static tab to the course, for code coverage self.test_tab = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category="static_tab", display_name="Static_1", ) diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py index 5df4804027cb..ff4409ac4129 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -87,8 +87,8 @@ class ContainerHandlerSerializer(serializers.Serializer): user_clipboard = serializers.DictField() is_fullwidth_content = serializers.BooleanField() assets_url = serializers.SerializerMethodField() - unit_block_id = serializers.CharField(source="unit.location.block_id") - subsection_location = serializers.CharField(source="subsection.location") + unit_block_id = serializers.CharField(source="unit.usage_key.block_id") + subsection_location = serializers.CharField(source="subsection.usage_key") course_sequence_ids = serializers.ListField(child=serializers.CharField()) library_content_picker_url = serializers.CharField() diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py b/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py index 42b5b1e9d78d..739e5f070b6a 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/course_index.py @@ -255,7 +255,7 @@ def get(self, request: Request, usage_key_string: str): with modulestore().bulk_operations(usage_key.course_key): # load course once to reuse it for user_partitions query - course = modulestore().get_course(current_xblock.location.course_key) + course = modulestore().get_course(current_xblock.usage_key.course_key) children = [] if current_xblock.has_children: for child in current_xblock.children: @@ -269,8 +269,8 @@ def get(self, request: Request, usage_key_string: str): children.append({ "xblock": child_info, "name": child_info.display_name_with_default, - "block_id": child_info.location, - "block_type": child_info.location.block_type, + "block_id": child_info.usage_key, + "block_type": child_info.usage_key.block_type, "user_partition_info": user_partition_info, "user_partitions": user_partitions, "upstream_link": ( diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py index 310d0ba80adc..4424fa12a9ab 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_course_index.py @@ -74,7 +74,7 @@ def test_course_index_response(self): "source_edit_url": "" }, "language_code": "en", - "lms_link": get_lms_link_for_item(self.course.location), + "lms_link": get_lms_link_for_item(self.course.usage_key), "mfe_proctored_exam_settings_url": ( f"http://course-authoring-mfe/course/{self.course.id}" "/pages-and-resources/proctoring/settings" @@ -99,7 +99,7 @@ def test_course_index_response(self): @override_waffle_flag(CUSTOM_RELATIVE_DATES, active=False) def test_course_index_response_with_show_locators(self): """Check successful response content with show query param""" - response = self.client.get(self.url, {"show": str(self.unit.location)}) + response = self.client.get(self.url, {"show": str(self.unit.usage_key)}) expected_response = { "course_release_date": "Set Date", "course_structure": _course_outline_json(self.request, self.course), @@ -113,10 +113,10 @@ def test_course_index_response_with_show_locators(self): "is_custom_relative_dates_active": False, "initial_state": { "expanded_locators": [ - str(self.unit.location), - str(self.xblock.location), + str(self.unit.usage_key), + str(self.xblock.usage_key), ], - "locator_to_show": str(self.unit.location), + "locator_to_show": str(self.unit.usage_key), }, "initial_user_clipboard": { "content": None, @@ -125,7 +125,7 @@ def test_course_index_response_with_show_locators(self): "source_edit_url": "" }, "language_code": "en", - "lms_link": get_lms_link_for_item(self.course.location), + "lms_link": get_lms_link_for_item(self.course.usage_key), "mfe_proctored_exam_settings_url": ( f"http://course-authoring-mfe/course/{self.course.id}" "/pages-and-resources/proctoring/settings" diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_home.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_home.py index a155ceb235a4..b22505bf7445 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_home.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_home.py @@ -127,7 +127,7 @@ def test_home_page_response(self): "courses": [{ "course_key": course_id, "display_name": self.course.display_name, - "lms_link": f'{settings.LMS_ROOT_URL}/courses/{course_id}/jump_to/{self.course.location}', + "lms_link": f'{settings.LMS_ROOT_URL}/courses/{course_id}/jump_to/{self.course.usage_key}', "number": self.course.number, "org": self.course.org, "rerun_link": f'/course_rerun/{course_id}', @@ -153,7 +153,7 @@ def test_home_page_response_with_api_v2(self): OrderedDict([ ("course_key", course_id), ("display_name", self.course.display_name), - ("lms_link", f'{settings.LMS_ROOT_URL}/courses/{course_id}/jump_to/{self.course.location}'), + ("lms_link", f'{settings.LMS_ROOT_URL}/courses/{course_id}/jump_to/{self.course.usage_key}'), ("number", self.course.number), ("org", self.course.org), ("rerun_link", f'/course_rerun/{course_id}'), diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py index 6cf08fe101e9..fd8938005c5e 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_proctoring.py @@ -197,7 +197,7 @@ def test_update_exam_settings_200_escalation_email(self): ) # course settings have been updated - updated = modulestore().get_item(self.course.location) + updated = modulestore().get_item(self.course.usage_key) assert updated.enable_proctored_exams is True assert updated.proctoring_provider == "test_proctoring_provider" assert updated.proctoring_escalation_email == "foo@bar.com" @@ -234,7 +234,7 @@ def test_update_exam_settings_200_no_escalation_email(self): ) # course settings have been updated - updated = modulestore().get_item(self.course.location) + updated = modulestore().get_item(self.course.usage_key) assert updated.enable_proctored_exams is True assert updated.proctoring_provider == "test_proctoring_provider" assert updated.proctoring_escalation_email is None @@ -265,7 +265,7 @@ def test_update_exam_settings_excluded_field(self): ) # excluded course settings are not updated - updated = modulestore().get_item(self.course.location) + updated = modulestore().get_item(self.course.usage_key) assert updated.proctoring_escalation_email is None @override_settings( @@ -295,7 +295,7 @@ def test_update_exam_settings_invalid_value(self): ) # course settings have been updated - updated = modulestore().get_item(self.course.location) + updated = modulestore().get_item(self.course.usage_key) assert updated.enable_proctored_exams is False assert updated.proctoring_provider == "null" @@ -361,7 +361,7 @@ def test_nonadmin_with_zendesk_ticket( ) logger_mock.assert_any_call(logger_string) - updated = modulestore().get_item(self.course.location) + updated = modulestore().get_item(self.course.usage_key) assert updated.create_zendesk_tickets is create_zendesk_tickets @override_waffle_flag(EXAMS_IDA, active=True) @@ -393,7 +393,7 @@ def test_200_for_lti_provider(self): ) # course settings have been updated - updated = modulestore().get_item(self.course.location) + updated = modulestore().get_item(self.course.usage_key) assert updated.enable_proctored_exams is True assert updated.proctoring_provider == "lti_external" @@ -422,7 +422,7 @@ def test_400_for_disabled_lti(self): ) # course settings have been updated - updated = modulestore().get_item(self.course.location) + updated = modulestore().get_item(self.course.usage_key) assert updated.enable_proctored_exams is False assert updated.proctoring_provider == "null" diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py index cd1e1a99d074..dfc84720f980 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py @@ -64,19 +64,19 @@ def setup_xblock(self): self._publish_library_block(self.html_block["id"]) self.chapter = self.create_block( - parent=self.course.location, + parent=self.course.usage_key, category="chapter", display_name="Week 1", ) self.sequential = self.create_block( - parent=self.chapter.location, + parent=self.chapter.usage_key, category="sequential", display_name="Lesson 1", ) self.vertical = self.create_block( - self.sequential.location, + self.sequential.usage_key, "vertical", "Unit", upstream=self.unit["id"], @@ -84,13 +84,13 @@ def setup_xblock(self): ) self.html_unit_first = self.create_block( - parent=self.vertical.location, + parent=self.vertical.usage_key, category="html", display_name="Html Content 1", ) self.html_unit_second = self.create_block( - parent=self.vertical.location, + parent=self.vertical.usage_key, category="html", display_name="Html Content 2", upstream=self.html_block["id"], @@ -146,7 +146,7 @@ def test_success_response(self): """ Check that endpoint is valid and success response. """ - url = self.get_reverse_url(self.vertical.location) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) @@ -155,8 +155,8 @@ def test_ancestor_xblocks_response(self): Check if the ancestor_xblocks are returned as expected. """ course_key_str = str(self.course.id) - chapter_usage_key = str(self.chapter.location) - sequential_usage_key = str(self.sequential.location) + chapter_usage_key = str(self.chapter.usage_key) + sequential_usage_key = str(self.sequential.usage_key) # URL encode the usage keys for the URLs chapter_encoded = quote(chapter_usage_key, safe='') @@ -187,7 +187,7 @@ def test_ancestor_xblocks_response(self): } ] - url = self.get_reverse_url(self.vertical.location) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(url) response_ancestor_xblocks = response.json().get("ancestor_xblocks", []) @@ -222,7 +222,7 @@ def test_success_response(self): """ Check that endpoint returns valid response data. """ - url = self.get_reverse_url(self.vertical.location) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() @@ -236,7 +236,7 @@ def test_success_response_with_upstream_info(self): """ Check that endpoint returns valid response data using `get_upstream_info` query param """ - url = self.get_reverse_url(self.vertical.location) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(f"{url}?get_upstream_info=true") self.assertEqual(response.status_code, status.HTTP_200_OK) data = response.json() @@ -256,8 +256,8 @@ def test_xblock_is_published(self): """ Check that published xBlock container returns. """ - self.publish_item(self.store, self.vertical.location) - url = self.get_reverse_url(self.vertical.location) + self.publish_item(self.store, self.vertical.usage_key) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(url) self.assertTrue(response.data["is_published"]) @@ -265,7 +265,7 @@ def test_children_content(self): """ Check that returns valid response with children of vertical container. """ - url = self.get_reverse_url(self.vertical.location) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(url) expected_user_partition_info = { @@ -288,8 +288,8 @@ def test_children_content(self): expected_response = [ { "name": self.html_unit_first.display_name_with_default, - "block_id": str(self.html_unit_first.location), - "block_type": self.html_unit_first.location.block_type, + "block_id": str(self.html_unit_first.usage_key), + "block_type": self.html_unit_first.usage_key.block_type, "upstream_link": None, "user_partition_info": expected_user_partition_info, "user_partitions": expected_user_partitions, @@ -306,8 +306,8 @@ def test_children_content(self): }, { "name": self.html_unit_second.display_name_with_default, - "block_id": str(self.html_unit_second.location), - "block_type": self.html_unit_second.location.block_type, + "block_id": str(self.html_unit_second.usage_key), + "block_type": self.html_unit_second.usage_key.block_type, "actions": { "can_copy": True, "can_duplicate": True, @@ -352,7 +352,7 @@ def test_actions_with_turned_off_taxonomy_flag(self): """ Check that action manage_tags for each child item has the same value as taxonomy flag. """ - url = self.get_reverse_url(self.vertical.location) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(url) for children in response.data["children"]: self.assertFalse(children["actions"]["can_manage_tags"]) @@ -372,8 +372,8 @@ def test_validation_errors(self): self.store.update_item(self.course, self.user.id) user_partition = self.course.user_partitions[0] - vertical = self.store.get_item(self.vertical.location) - html_unit_first = self.store.get_item(self.html_unit_first.location) + vertical = self.store.get_item(self.vertical.usage_key) + html_unit_first = self.store.get_item(self.html_unit_first.usage_key) group_first = user_partition.groups[0] group_second = user_partition.groups[1] @@ -383,10 +383,10 @@ def test_validation_errors(self): self.set_group_access(html_unit_first, {user_partition.id: [group_first.id]}) # update vertical/html - vertical = self.store.get_item(self.vertical.location) - html_unit_first = self.store.get_item(self.html_unit_first.location) + vertical = self.store.get_item(self.vertical.usage_key) + html_unit_first = self.store.get_item(self.html_unit_first.usage_key) - url = self.get_reverse_url(self.vertical.location) + url = self.get_reverse_url(self.vertical.usage_key) response = self.client.get(url) children_response = response.data["children"] diff --git a/cms/djangoapps/contentstore/rest_api/v2/serializers/home.py b/cms/djangoapps/contentstore/rest_api/v2/serializers/home.py index 857291fe838b..186674ee7225 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/serializers/home.py +++ b/cms/djangoapps/contentstore/rest_api/v2/serializers/home.py @@ -38,7 +38,7 @@ class CourseCommonSerializerV2(serializers.Serializer): def get_lms_link(self, obj): """Get LMS link for course.""" - return get_lms_link_for_item(obj.location) + return get_lms_link_for_item(obj.usage_key) def get_cms_link(self, obj): """Get CMS link for course.""" diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py index f82859f74bd3..42a7cb0ff478 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_downstreams.py @@ -518,7 +518,7 @@ def call_api_post(self, library_content_key, category): `library_content_key` as upstream """ data = { - "parent_locator": str(self.course.location), + "parent_locator": str(self.course.usage_key), "display_name": "Test block", "library_content_key": library_content_key, "category": category, diff --git a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_home.py b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_home.py index 93a9941f4f1a..e1c2eeb08282 100644 --- a/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_home.py +++ b/cms/djangoapps/contentstore/rest_api/v2/views/tests/test_home.py @@ -55,7 +55,7 @@ def test_home_page_response(self): OrderedDict([ ("course_key", course_id), ("display_name", self.course.display_name), - ("lms_link", f'{settings.LMS_ROOT_URL}/courses/{course_id}/jump_to/{self.course.location}'), + ("lms_link", f'{settings.LMS_ROOT_URL}/courses/{course_id}/jump_to/{self.course.usage_key}'), ("cms_link", f'//{settings.CMS_BASE}{reverse_course_url("course_handler", self.course.id)}'), ("number", self.course.number), ("org", self.course.org), @@ -69,7 +69,7 @@ def test_home_page_response(self): ("display_name", self.archived_course.display_name), ( "lms_link", - f'{settings.LMS_ROOT_URL}/courses/{archived_course_id}/jump_to/{self.archived_course.location}' + f'{settings.LMS_ROOT_URL}/courses/{archived_course_id}/jump_to/{self.archived_course.usage_key}' ), ( "cms_link", @@ -108,7 +108,7 @@ def test_active_only_query_if_passed(self): self.assertEqual(response.data["results"]["courses"], [OrderedDict([ ("course_key", str(self.course.id)), ("display_name", self.course.display_name), - ("lms_link", f'{settings.LMS_ROOT_URL}/courses/{str(self.course.id)}/jump_to/{self.course.location}'), + ("lms_link", f'{settings.LMS_ROOT_URL}/courses/{str(self.course.id)}/jump_to/{self.course.usage_key}'), ("cms_link", f'//{settings.CMS_BASE}{reverse_course_url("course_handler", self.course.id)}'), ("number", self.course.number), ("org", self.course.org), @@ -136,7 +136,7 @@ def test_archived_only_query_if_passed(self): '{url_root}/courses/{course_id}/jump_to/{location}'.format( url_root=settings.LMS_ROOT_URL, course_id=str(self.archived_course.id), - location=self.archived_course.location + location=self.archived_course.usage_key ), ), ("cms_link", f'//{settings.CMS_BASE}{reverse_course_url("course_handler", self.archived_course.id)}'), @@ -166,7 +166,7 @@ def test_search_query_if_passed(self): '{url_root}/courses/{course_id}/jump_to/{location}'.format( url_root=settings.LMS_ROOT_URL, course_id=str(self.archived_course.id), - location=self.archived_course.location + location=self.archived_course.usage_key ), ), ("cms_link", f'//{settings.CMS_BASE}{reverse_course_url("course_handler", self.archived_course.id)}'), diff --git a/cms/djangoapps/contentstore/signals/handlers.py b/cms/djangoapps/contentstore/signals/handlers.py index e28cbf313acb..0a90c7da1c47 100644 --- a/cms/djangoapps/contentstore/signals/handlers.py +++ b/cms/djangoapps/contentstore/signals/handlers.py @@ -212,13 +212,13 @@ def handle_item_deleted(**kwargs): deleted_block = modulestore().get_item(usage_key) except ItemNotFoundError: return - id_list = {deleted_block.location} + id_list = {deleted_block.usage_key} for block in yield_dynamic_block_descendants(deleted_block, kwargs.get('user_id')): # Remove prerequisite milestone data - gating_api.remove_prerequisite(block.location) + gating_api.remove_prerequisite(block.usage_key) # Remove any 'requires' course content milestone relationships - gating_api.set_required_content(course_key, block.location, None, None, None) - id_list.add(block.location) + gating_api.set_required_content(course_key, block.usage_key, None, None, None) + id_list.add(block.usage_key) ComponentLink.objects.filter(downstream_usage_key__in=id_list).delete() ContainerLink.objects.filter(downstream_usage_key__in=id_list).delete() diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index 983471e1ebef..a1b6f1ea2f77 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -432,8 +432,8 @@ def create_export_tarball(course_block, course_key, context, status=None): LOGGER.exception('There was an error exporting %s', course_key, exc_info=True) parent = None try: - failed_item = modulestore().get_item(exc.location) - parent_loc = modulestore().get_parent_location(failed_item.location) + failed_item = modulestore().get_item(exc.usage_key) + parent_loc = modulestore().get_parent_location(failed_item.usage_key) if parent_loc is not None: parent = modulestore().get_item(parent_loc) @@ -444,7 +444,7 @@ def create_export_tarball(course_block, course_key, context, status=None): context.update({ 'in_err': True, 'raw_err_msg': str(exc), - 'edit_unit_url': reverse_usage_url("container_handler", parent.location) if parent else "", + 'edit_unit_url': reverse_usage_url("container_handler", parent.usage_key) if parent else "", }) if status: status.fail(json.dumps({'raw_error_msg': context['raw_err_msg'], @@ -741,7 +741,7 @@ def read_chunk(): verbose=True, ) - new_location = courselike_items[0].location + new_location = courselike_items[0].usage_key LOGGER.debug('new course at %s', new_location) LOGGER.info(f'{log_prefix}: Course import successful') @@ -765,7 +765,7 @@ def read_chunk(): settings={'is_entrance_exam': True} )[0] - metadata = {'entrance_exam_id': str(entrance_exam_chapter.location)} + metadata = {'entrance_exam_id': str(entrance_exam_chapter.usage_key)} CourseMetadata.update_from_dict(metadata, course, user) from .views.entrance_exam import add_entrance_exam_milestone add_entrance_exam_milestone(course.id, entrance_exam_chapter) @@ -1020,7 +1020,7 @@ def replace_all_library_source_blocks_ids_for_course(course_key_string, v1_to_v2 for branch in [ModuleStoreEnum.BranchName.draft, ModuleStoreEnum.BranchName.published] ] - published_dict = {block.location: block for block in published_blocks} + published_dict = {block.usage_key: block for block in published_blocks} for draft_library_source_block in draft_blocks: try: @@ -1038,19 +1038,19 @@ def replace_all_library_source_blocks_ids_for_course(course_key_string, v1_to_v2 # This way, if authors "discard changes," they won't be reverted back to the V1 lib. # However, we also don't want to publish the draft branch. try: - if published_dict[draft_library_source_block.location] is not None: + if published_dict[draft_library_source_block.usage_key] is not None: #temporarily set the published version to be the draft & publish it. - temp = published_dict[draft_library_source_block.location] + temp = published_dict[draft_library_source_block.usage_key] temp.source_library_id = new_source_id store.update_item(temp, None) - store.publish(temp.location, None) + store.publish(temp.usage_key, None) draft_library_source_block.source_library_id = new_source_id store.update_item(draft_library_source_block, None) except KeyError: #Warn, but just update the draft block if no published block for draft block. LOGGER.warning( 'No matching published block for draft block %s', - str(draft_library_source_block.location) + str(draft_library_source_block.usage_key) ) draft_library_source_block.source_library_id = new_source_id store.update_item(draft_library_source_block, None) @@ -1078,7 +1078,7 @@ def undo_all_library_source_blocks_ids_for_course(course_key_string, v1_to_v2_li for branch in [ModuleStoreEnum.BranchName.draft, ModuleStoreEnum.BranchName.published] ] - published_dict = {block.location: block for block in published_blocks} + published_dict = {block.usage_key: block for block in published_blocks} for draft_library_source_block in draft_blocks: try: @@ -1096,19 +1096,19 @@ def undo_all_library_source_blocks_ids_for_course(course_key_string, v1_to_v2_li # This way, if authors "discard changes," they won't be reverted back to the V1 lib. # However, we also don't want to publish the draft branch. try: - if published_dict[draft_library_source_block.location] is not None: + if published_dict[draft_library_source_block.usage_key] is not None: #temporarily set the published version to be the draft & publish it. - temp = published_dict[draft_library_source_block.location] + temp = published_dict[draft_library_source_block.usage_key] temp.source_library_id = new_source_id store.update_item(temp, None) - store.publish(temp.location, None) + store.publish(temp.usage_key, None) draft_library_source_block.source_library_id = new_source_id store.update_item(draft_library_source_block, None) except KeyError: #Warn, but just update the draft block if no published block for draft block. LOGGER.warning( 'No matching published block for draft block %s', - str(draft_library_source_block.location) + str(draft_library_source_block.usage_key) ) draft_library_source_block.source_library_id = new_source_id store.update_item(draft_library_source_block, None) @@ -1258,7 +1258,7 @@ def _scan_course_for_links(course_key): # and it doesn't contain user-facing links to scan. if block.category == 'drag-and-drop-v2': continue - block_id = str(block.location) + block_id = str(block.usage_key) block_info = get_block_info(block) block_data = block_info['data'] url_list = extract_content_URLs_from_course(block_data) @@ -2105,7 +2105,7 @@ def _update_course_content_link(block_id, old_url, new_url, course_key, user): if hasattr(block, "data") and old_url in block.data: block.data = block.data.replace(old_url, new_url) store.update_item(block, user.id) - store.publish(block.location, user.id) + store.publish(block.usage_key, user.id) LOGGER.info( f"Updated block {block_id} data with new URL: {old_url} -> {new_url}" ) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index 431a155d20a9..ea36e21a9e18 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -313,7 +313,7 @@ def verify_content_existence(self, store, root_dir, course_id, dirname, category for item in items: filesystem = OSFS(root_dir / ('test_export/' + dirname)) - self.assertTrue(filesystem.exists(item.location.block_id + filename_suffix)) + self.assertTrue(filesystem.exists(item.usage_key.block_id + filename_suffix)) def test_export_course_with_metadata_only_video(self): content_store = contentstore() @@ -330,7 +330,7 @@ def test_export_course_with_metadata_only_video(self): parent = verticals[0] - BlockFactory.create(parent_location=parent.location, category="video", display_name="untitled") + BlockFactory.create(parent_location=parent.usage_key, category="video", display_name="untitled") root_dir = path(mkdtemp_clean()) @@ -356,7 +356,7 @@ def test_export_course_with_metadata_only_word_cloud(self): parent = verticals[0] - BlockFactory.create(parent_location=parent.location, category="word_cloud", display_name="untitled") + BlockFactory.create(parent_location=parent.usage_key, category="word_cloud", display_name="untitled") root_dir = path(mkdtemp_clean()) @@ -383,15 +383,15 @@ def test_import_after_renaming_xml_data(self): create_if_not_present=True ) all_items = split_store.get_items(course_after_rename[0].id, qualifiers={'category': 'chapter'}) - renamed_chapter = [item for item in all_items if item.location.block_id == 'renamed_chapter'][0] + renamed_chapter = [item for item in all_items if item.usage_key.block_id == 'renamed_chapter'][0] self.assertIsNotNone(renamed_chapter.published_on) self.assertIsNotNone(renamed_chapter.parent) - self.assertIn(renamed_chapter.location, course_after_rename[0].children) + self.assertIn(renamed_chapter.usage_key, course_after_rename[0].children) original_chapter = [item for item in all_items - if item.location.block_id == 'b9870b9af59841a49e6e02765d0e3bbf'][0] + if item.usage_key.block_id == 'b9870b9af59841a49e6e02765d0e3bbf'][0] self.assertIsNone(original_chapter.published_on) self.assertIsNone(original_chapter.parent) - self.assertNotIn(original_chapter.location, course_after_rename[0].children) + self.assertNotIn(original_chapter.usage_key, course_after_rename[0].children) def test_empty_data_roundtrip(self): """ @@ -411,7 +411,7 @@ def test_empty_data_roundtrip(self): # Create a block, and ensure that its `data` field is empty word_cloud = BlockFactory.create( - parent_location=parent.location, category="word_cloud", display_name="untitled") + parent_location=parent.usage_key, category="word_cloud", display_name="untitled") del word_cloud.data self.assertEqual(word_cloud.data, '') @@ -498,13 +498,13 @@ def test_export_course_no_xml_attributes(self): # create OpenAssessmentBlock: open_assessment = BlockFactory.create( - parent_location=vertical.location, + parent_location=vertical.usage_key, category="openassessment", display_name="untitled", ) # convert it to draft draft_open_assessment = self.store.convert_to_draft( - open_assessment.location, self.user.id + open_assessment.usage_key, self.user.id ) # note that it has no `xml_attributes` attribute @@ -531,12 +531,12 @@ def setUp(self): super().setUp() # save locs not items b/c the items won't have the subsequently created children in them until refetched self.chapter_loc = self.store.create_child( - self.user.id, self.course.location, 'chapter', 'test_chapter' - ).location + self.user.id, self.course.usage_key, 'chapter', 'test_chapter' + ).usage_key self.seq_loc = self.store.create_child( self.user.id, self.chapter_loc, 'sequential', 'test_seq' - ).location - self.vert_loc = self.store.create_child(self.user.id, self.seq_loc, 'vertical', 'test_vert').location + ).usage_key + self.vert_loc = self.store.create_child(self.user.id, self.seq_loc, 'vertical', 'test_vert').usage_key # now create some things quasi like the toy course had self.problem = self.store.create_child( self.user.id, self.vert_loc, 'problem', 'test_problem', fields={ @@ -570,7 +570,7 @@ def setUp(self): "answers": [{"id": "yes", "text": "Yes"}, {"id": "no", "text": "No"}], } ) - self.course = self.store.publish(self.course.location, self.user.id) + self.course = self.store.publish(self.course.usage_key, self.user.id) def check_components_on_page(self, component_types, expected_types): """ @@ -655,7 +655,7 @@ def test_export_with_orphan_vertical(self): information but the draft child xblock has parent information. """ # Make an existing unit a draft - self.problem = self.store.unpublish(self.problem.location, self.user.id) + self.problem = self.store.unpublish(self.problem.usage_key, self.user.id) root_dir = path(mkdtemp_clean()) export_course_to_xml(self.store, None, self.course.id, root_dir, 'test_export') @@ -726,20 +726,20 @@ def test_get_items(self): Unfortunately, None = published for the revision field, so get_items() would return both draft and non-draft copies. """ - self.problem = self.store.unpublish(self.problem.location, self.user.id) + self.problem = self.store.unpublish(self.problem.usage_key, self.user.id) # Query get_items() and find the html item. This should just return back a single item (not 2). direct_store_items = self.store.get_items( self.course.id, revision=ModuleStoreEnum.RevisionOption.published_only ) - items_from_direct_store = [item for item in direct_store_items if item.location == self.problem.location] + items_from_direct_store = [item for item in direct_store_items if item.usage_key == self.problem.usage_key] self.assertEqual(len(items_from_direct_store), 0) # Fetch from the draft store. draft_store_items = self.store.get_items( self.course.id, revision=ModuleStoreEnum.RevisionOption.draft_only ) - items_from_draft_store = [item for item in draft_store_items if item.location == self.problem.location] + items_from_draft_store = [item for item in draft_store_items if item.usage_key == self.problem.usage_key] self.assertEqual(len(items_from_draft_store), 1) def test_draft_metadata(self): @@ -752,31 +752,31 @@ def test_draft_metadata(self): course = self.store.update_item(self.course, self.user.id) course.graceperiod = timedelta(days=1, hours=5, minutes=59, seconds=59) course = self.store.update_item(course, self.user.id) - problem = self.store.get_item(self.problem.location) + problem = self.store.get_item(self.problem.usage_key) self.assertEqual(problem.graceperiod, course.graceperiod) self.assertNotIn('graceperiod', own_metadata(problem)) - self.store.convert_to_draft(problem.location, self.user.id) + self.store.convert_to_draft(problem.usage_key, self.user.id) # refetch to check metadata - problem = self.store.get_item(problem.location) + problem = self.store.get_item(problem.usage_key) self.assertEqual(problem.graceperiod, course.graceperiod) self.assertNotIn('graceperiod', own_metadata(problem)) # publish block - self.store.publish(problem.location, self.user.id) + self.store.publish(problem.usage_key, self.user.id) # refetch to check metadata - problem = self.store.get_item(problem.location) + problem = self.store.get_item(problem.usage_key) self.assertEqual(problem.graceperiod, course.graceperiod) self.assertNotIn('graceperiod', own_metadata(problem)) # put back in draft and change metadata and see if it's now marked as 'own_metadata' - self.store.convert_to_draft(problem.location, self.user.id) - problem = self.store.get_item(problem.location) + self.store.convert_to_draft(problem.usage_key, self.user.id) + problem = self.store.get_item(problem.usage_key) new_graceperiod = timedelta(hours=1) @@ -791,17 +791,17 @@ def test_draft_metadata(self): self.store.update_item(problem, self.user.id) # read back to make sure it reads as 'own-metadata' - problem = self.store.get_item(problem.location) + problem = self.store.get_item(problem.usage_key) self.assertIn('graceperiod', own_metadata(problem)) self.assertEqual(problem.graceperiod, new_graceperiod) # republish - self.store.publish(problem.location, self.user.id) + self.store.publish(problem.usage_key, self.user.id) # and re-read and verify 'own-metadata' - self.store.convert_to_draft(problem.location, self.user.id) - problem = self.store.get_item(problem.location) + self.store.convert_to_draft(problem.usage_key, self.user.id) + problem = self.store.get_item(problem.usage_key) self.assertIn('graceperiod', own_metadata(problem)) self.assertEqual(problem.graceperiod, new_graceperiod) @@ -812,10 +812,10 @@ def test_get_depth_with_drafts(self): self.assertEqual(num_drafts, 0) # put into draft - self.problem = self.store.unpublish(self.problem.location, self.user.id) + self.problem = self.store.unpublish(self.problem.usage_key, self.user.id) # make sure we can query that item and verify that it is a draft - draft_problem = self.store.get_item(self.problem.location) + draft_problem = self.store.get_item(self.problem.usage_key) self.assertEqual(self.store.has_published_version(draft_problem), False) # now requery with depth @@ -1006,7 +1006,7 @@ def test_course_handouts_rewrites(self): ) # get block info (json) - resp = self.client.get(get_url('xblock_handler', handouts.location)) + resp = self.client.get(get_url('xblock_handler', handouts.usage_key)) # make sure we got a successful response self.assertEqual(resp.status_code, 200) @@ -1397,7 +1397,7 @@ def test_course_factory(self): def test_item_factory(self): """Test that the item factory works correctly.""" course = CourseFactory.create() - item = BlockFactory.create(parent_location=course.location) + item = BlockFactory.create(parent_location=course.usage_key) self.assertIsInstance(item, SequenceBlock) def test_create_block(self): @@ -1405,7 +1405,7 @@ def test_create_block(self): course = CourseFactory.create() section_data = { - 'parent_locator': str(course.location), + 'parent_locator': str(course.usage_key), 'category': 'chapter', 'display_name': 'Section One', } @@ -1423,15 +1423,15 @@ def test_create_block(self): def test_hide_xblock_from_toc_via_handler(self, hide_from_toc): """Test that the hide_from_toc field can be set via the xblock_handler.""" course = CourseFactory.create() - sequential = BlockFactory.create(parent_location=course.location) + sequential = BlockFactory.create(parent_location=course.usage_key) data = { "metadata": { "hide_from_toc": hide_from_toc } } - response = self.client.ajax_post(get_url("xblock_handler", sequential.location), data) - sequential = self.store.get_item(sequential.location) + response = self.client.ajax_post(get_url("xblock_handler", sequential.usage_key), data) + sequential = self.store.get_item(sequential.usage_key) self.assertEqual(response.status_code, 200) self.assertEqual(hide_from_toc, sequential.hide_from_toc) @@ -1441,7 +1441,7 @@ def test_capa_block(self): course = CourseFactory.create() problem_data = { - 'parent_locator': str(course.location), + 'parent_locator': str(course.usage_key), 'category': 'problem' } @@ -1632,10 +1632,10 @@ def test_forum_id_generation(self): discussion_item = self.store.create_item(self.user.id, course.id, 'discussion', 'new_component') # now fetch it from the modulestore to instantiate its descriptor - fetched = self.store.get_item(discussion_item.location) + fetched = self.store.get_item(discussion_item.usage_key) # refetch it to be safe - refetched = self.store.get_item(discussion_item.location) + refetched = self.store.get_item(discussion_item.usage_key) # and make sure the same discussion items have the same discussion ids self.assertEqual(fetched.discussion_id, discussion_item.discussion_id) @@ -1662,11 +1662,11 @@ def test_metadata_inheritance(self): # crate a new block and add it as a child to a vertical parent = verticals[0] new_block = self.store.create_child( - self.user.id, parent.location, 'html', 'new_component' + self.user.id, parent.usage_key, 'html', 'new_component' ) # flush the cache - new_block = self.store.get_item(new_block.location) + new_block = self.store.get_item(new_block.usage_key) # check for grace period definition which should be defined at the course level self.assertEqual(parent.graceperiod, new_block.graceperiod) @@ -1682,13 +1682,13 @@ def test_metadata_inheritance(self): self.store.update_item(new_block, self.user.id) # flush the cache and refetch - new_block = self.store.get_item(new_block.location) + new_block = self.store.get_item(new_block.usage_key) self.assertEqual(timedelta(1), new_block.graceperiod) def test_default_metadata_inheritance(self): course = CourseFactory.create() - vertical = BlockFactory.create(parent_location=course.location) + vertical = BlockFactory.create(parent_location=course.usage_key) course.children.append(vertical) # in memory self.assertIsNotNone(course.start) @@ -1698,8 +1698,8 @@ def test_default_metadata_inheritance(self): self.assertIn('GRADE_CUTOFFS', course.grading_policy) # by fetching - fetched_course = self.store.get_item(course.location) - fetched_item = self.store.get_item(vertical.location) + fetched_course = self.store.get_item(course.usage_key) + fetched_item = self.store.get_item(vertical.usage_key) self.assertIsNotNone(fetched_course.start) self.assertEqual(course.start, fetched_course.start) self.assertEqual(fetched_course.start, fetched_item.start) @@ -1772,7 +1772,7 @@ def setUp(self): video_data = VideoBlock.parse_video_xml(video_sample_xml) video_data.pop('source') self.video_block = BlockFactory.create( - parent_location=course.location, category='video', + parent_location=course.usage_key, category='video', **video_data ) @@ -1794,7 +1794,7 @@ def test_metadata_not_persistence(self): 'track' } - location = self.video_block.location + location = self.video_block.usage_key for field_name in attrs_to_strip: delattr(self.video_block, field_name) @@ -2113,7 +2113,7 @@ def test_video_license_export(self): content_store = contentstore() root_dir = path(mkdtemp_clean()) video_block = BlockFactory.create( - parent_location=self.course.location, category='video', + parent_location=self.course.usage_key, category='video', license="all-rights-reserved" ) export_course_to_xml(self.store, content_store, self.course.id, root_dir, 'test_license') diff --git a/cms/djangoapps/contentstore/tests/test_core_caching.py b/cms/djangoapps/contentstore/tests/test_core_caching.py index e6b23c2deeed..bcf9ed9dc205 100644 --- a/cms/djangoapps/contentstore/tests/test_core_caching.py +++ b/cms/djangoapps/contentstore/tests/test_core_caching.py @@ -14,11 +14,11 @@ class Content: Mock cached content """ def __init__(self, location, content): - self.location = location + self.usage_key = location self.content = content def get_id(self): - return self.location.to_deprecated_son() + return self.usage_key.to_deprecated_son() class CachingTestCase(TestCase): diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index 876bb37ee783..27fffbc8f007 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -952,8 +952,8 @@ def test_delete_grace_period(self): def test_update_section_grader_type(self, send_signal, tracker, uuid): uuid.return_value = 'mockUUID' # Get the block and the section_grader_type and assert they are the default values - block = modulestore().get_item(self.course.location) - section_grader_type = CourseGradingModel.get_section_grader_type(self.course.location) + block = modulestore().get_item(self.course.usage_key) + section_grader_type = CourseGradingModel.get_section_grader_type(self.course.usage_key) self.assertEqual('notgraded', section_grader_type['graderType']) self.assertEqual(None, block.format) @@ -961,8 +961,8 @@ def test_update_section_grader_type(self, send_signal, tracker, uuid): # Change the default grader type to Homework, which should also mark the section as graded CourseGradingModel.update_section_grader_type(self.course, 'Homework', self.user) - block = modulestore().get_item(self.course.location) - section_grader_type = CourseGradingModel.get_section_grader_type(self.course.location) + block = modulestore().get_item(self.course.usage_key) + section_grader_type = CourseGradingModel.get_section_grader_type(self.course.usage_key) grading_policy_1 = self._grading_policy_hash_for_course() self.assertEqual('Homework', section_grader_type['graderType']) @@ -971,8 +971,8 @@ def test_update_section_grader_type(self, send_signal, tracker, uuid): # Change the grader type back to notgraded, which should also unmark the section as graded CourseGradingModel.update_section_grader_type(self.course, 'notgraded', self.user) - block = modulestore().get_item(self.course.location) - section_grader_type = CourseGradingModel.get_section_grader_type(self.course.location) + block = modulestore().get_item(self.course.usage_key) + section_grader_type = CourseGradingModel.get_section_grader_type(self.course.usage_key) grading_policy_2 = self._grading_policy_hash_for_course() self.assertEqual('notgraded', section_grader_type['graderType']) @@ -1077,7 +1077,7 @@ def setup_test_set_get_section_grader_ajax(self): # see if test makes sense self.assertGreater(len(sections), 0, "No sections found") section = sections[0] # just take the first one - return reverse_usage_url('xblock_handler', section.location) + return reverse_usage_url('xblock_handler', section.usage_key) def test_set_get_section_grader_ajax(self): """ diff --git a/cms/djangoapps/contentstore/tests/test_courseware_index.py b/cms/djangoapps/contentstore/tests/test_courseware_index.py index 3ab3fa373f81..ddb2fa203e86 100644 --- a/cms/djangoapps/contentstore/tests/test_courseware_index.py +++ b/cms/djangoapps/contentstore/tests/test_courseware_index.py @@ -51,7 +51,7 @@ def create_children(store, parent, category, load_factor): created_count = 0 for child_index in range(load_factor): child_object = BlockFactory.create( - parent_location=parent.location, + parent_location=parent.usage_key, category=category, display_name=f"{category} {child_index} {time.clock()}", # lint-amnesty, pylint: disable=no-member modulestore=store, @@ -153,7 +153,7 @@ def setup_course_base(self, store): ) self.chapter = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category='chapter', display_name="Week 1", modulestore=store, @@ -161,7 +161,7 @@ def setup_course_base(self, store): start=datetime(2015, 3, 1, tzinfo=UTC), ) self.sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category='sequential', display_name="Lesson 1", modulestore=store, @@ -169,7 +169,7 @@ def setup_course_base(self, store): start=datetime(2015, 3, 1, tzinfo=UTC), ) self.vertical = BlockFactory.create( - parent_location=self.sequential.location, + parent_location=self.sequential.usage_key, category='vertical', display_name='Subsection 1', modulestore=store, @@ -178,7 +178,7 @@ def setup_course_base(self, store): ) # unspecified start - should inherit from container self.html_unit = BlockFactory.create( - parent_location=self.vertical.location, + parent_location=self.vertical.usage_key, category="html", display_name="Html Content", modulestore=store, @@ -213,7 +213,7 @@ def _test_indexing_course(self, store): self.assertEqual(response["total"], 3) # Publish the vertical as is, and any unpublished children should now be available - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) self.reindex_course(store) response = self.search() self.assertEqual(response["total"], 4) @@ -221,14 +221,14 @@ def _test_indexing_course(self, store): def _test_not_indexing_unpublished_content(self, store): """ add a new one, only appers in index once added """ # Publish the vertical to start with - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) self.reindex_course(store) response = self.search() self.assertEqual(response["total"], 4) # Now add a new unit to the existing vertical BlockFactory.create( - parent_location=self.vertical.location, + parent_location=self.vertical.usage_key, category="html", display_name="Some other content", publish_item=False, @@ -240,7 +240,7 @@ def _test_not_indexing_unpublished_content(self, store): # Now publish it and we should find it # Publish the vertical as is, and everything should be available - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) self.reindex_course(store) response = self.search() self.assertEqual(response["total"], 5) @@ -265,19 +265,19 @@ def _test_delete_course_from_search_index_after_course_deletion(self, store): # def _test_deleting_item(self, store): """ test deleting an item """ # Publish the vertical to start with - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) self.reindex_course(store) response = self.search() self.assertEqual(response["total"], 4) # just a delete should not change anything - self.delete_item(store, self.html_unit.location) + self.delete_item(store, self.html_unit.usage_key) self.reindex_course(store) response = self.search() self.assertEqual(response["total"], 4) # but after publishing, we should no longer find the html_unit - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) self.reindex_course(store) response = self.search() self.assertEqual(response["total"], 3) @@ -288,17 +288,17 @@ def _test_start_date_propagation(self, store): later_date = self.vertical.start # Publish the vertical - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) self.reindex_course(store) response = self.search() self.assertEqual(response["total"], 4) results = response["results"] date_map = { - str(self.chapter.location): early_date, - str(self.sequential.location): early_date, - str(self.vertical.location): later_date, - str(self.html_unit.location): later_date, + str(self.chapter.usage_key): early_date, + str(self.sequential.usage_key): early_date, + str(self.vertical.usage_key): later_date, + str(self.html_unit.usage_key): later_date, } for result in results: self.assertEqual(result["data"]["start_date"], date_map[result["data"]["id"]]) @@ -311,13 +311,13 @@ def _test_search_disabled(self, store): def _test_time_based_index(self, store): """ Make sure that a time based request to index does not index anything too old """ - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) indexed_count = self.reindex_course(store) self.assertEqual(indexed_count, 4) # Add a new sequential sequential2 = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category='sequential', display_name='Section 2', modulestore=store, @@ -327,14 +327,14 @@ def _test_time_based_index(self, store): # add a new vertical vertical2 = BlockFactory.create( - parent_location=sequential2.location, + parent_location=sequential2.usage_key, category='vertical', display_name='Subsection 2', modulestore=store, publish_item=True, ) BlockFactory.create( - parent_location=vertical2.location, + parent_location=vertical2.usage_key, category="html", display_name="Some other content", publish_item=False, @@ -342,7 +342,7 @@ def _test_time_based_index(self, store): ) before_time = datetime.now(UTC) - self.publish_item(store, vertical2.location) + self.publish_item(store, vertical2.usage_key) # index based on time, will include an index of the origin sequential # because it is in a common subtree but not of the original vertical # because the original sequential's subtree is too old @@ -415,7 +415,7 @@ def _test_course_about_mode_index(self, store): def _test_course_location_info(self, store): """ Test that course location information is added to index """ - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) self.reindex_course(store) response = self.search(query_string="Html Content") self.assertEqual(response["total"], 1) @@ -427,7 +427,7 @@ def _test_course_location_info(self, store): def _test_course_location_null(self, store): """ Test that course location information is added to index """ sequential2 = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category='sequential', display_name=None, modulestore=store, @@ -436,14 +436,14 @@ def _test_course_location_null(self, store): ) # add a new vertical vertical2 = BlockFactory.create( - parent_location=sequential2.location, + parent_location=sequential2.usage_key, category='vertical', display_name='Subsection 2', modulestore=store, publish_item=True, ) BlockFactory.create( - parent_location=vertical2.location, + parent_location=vertical2.usage_key, category="html", display_name="Find Me", publish_item=True, @@ -460,7 +460,7 @@ def _test_course_location_null(self, store): @patch('django.conf.settings.SEARCH_ENGINE', 'search.tests.utils.ErroringIndexEngine') def _test_exception(self, store): """ Test that exception within indexing yields a SearchIndexingError """ - self.publish_item(store, self.vertical.location) + self.publish_item(store, self.vertical.usage_key) with self.assertRaises(SearchIndexingError): self.reindex_course(store) @@ -547,7 +547,7 @@ def _do_test_large_course_deletion(self, store, load_factor): """ Test that deleting items from a course works even when present within a very large course """ def id_list(top_parent_object): """ private function to get ids from object down the tree """ - list_of_ids = [str(top_parent_object.location)] + list_of_ids = [str(top_parent_object.usage_key)] for child in top_parent_object.get_children(): list_of_ids.extend(id_list(child)) return list_of_ids @@ -565,7 +565,7 @@ def id_list(top_parent_object): # delete the first chapter chapter_to_delete = course.get_children()[0] - self.delete_item(store, chapter_to_delete.location) + self.delete_item(store, chapter_to_delete.usage_key) # index and check correctness CoursewareSearchIndexer.do_course_reindex(store, course.id) @@ -608,21 +608,21 @@ def setUpClass(cls): cls.course = CourseFactory.create(start=datetime(2015, 3, 1, tzinfo=UTC)) cls.chapter = BlockFactory.create( - parent_location=cls.course.location, + parent_location=cls.course.usage_key, category='chapter', display_name="Week 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) cls.sequential = BlockFactory.create( - parent_location=cls.chapter.location, + parent_location=cls.chapter.usage_key, category='sequential', display_name="Lesson 1", publish_item=True, start=datetime(2015, 3, 1, tzinfo=UTC), ) cls.vertical = BlockFactory.create( - parent_location=cls.sequential.location, + parent_location=cls.sequential.usage_key, category='vertical', display_name='Subsection 1', publish_item=True, @@ -630,7 +630,7 @@ def setUpClass(cls): ) # unspecified start - should inherit from container cls.html_unit = BlockFactory.create( - parent_location=cls.vertical.location, + parent_location=cls.vertical.usage_key, category="html", display_name="Html Content", publish_item=False, @@ -639,14 +639,14 @@ def setUpClass(cls): cls.library = LibraryFactory.create() cls.library_block1 = BlockFactory.create( - parent_location=cls.library.location, + parent_location=cls.library.usage_key, category="html", display_name="Html Content", publish_item=False, ) cls.library_block2 = BlockFactory.create( - parent_location=cls.library.location, + parent_location=cls.library.usage_key, category="html", display_name="Html Content 2", publish_item=False, @@ -680,11 +680,11 @@ def test_task_indexing_course(self): def test_task_library_update(self): """ Making sure that the receiver correctly fires off the task when invoked by signal """ searcher = SearchEngine.get_search_engine(LibrarySearchIndexer.INDEX_NAME) - library_search_key = str(normalize_key_for_search(self.library.location.library_key)) + library_search_key = str(normalize_key_for_search(self.library.usage_key.library_key)) response = searcher.search(field_dictionary={"library": library_search_key}) self.assertEqual(response["total"], 0) - listen_for_library_update(self, self.library.location.library_key) + listen_for_library_update(self, self.library.usage_key.library_key) # Note that this test will only succeed if celery is working in inline mode response = searcher.search(field_dictionary={"library": library_search_key}) @@ -727,7 +727,7 @@ def setup_course_base(self, store): self.library = LibraryFactory.create(modulestore=store) self.html_unit1 = BlockFactory.create( - parent_location=self.library.location, + parent_location=self.library.usage_key, category="html", display_name="Html Content", modulestore=store, @@ -735,7 +735,7 @@ def setup_course_base(self, store): ) self.html_unit2 = BlockFactory.create( - parent_location=self.library.location, + parent_location=self.library.usage_key, category="html", display_name="Html Content 2", modulestore=store, @@ -746,11 +746,11 @@ def setup_course_base(self, store): def _get_default_search(self): """ Returns field_dictionary for default search """ - return {"library": str(self.library.location.library_key.replace(version_guid=None, branch=None))} + return {"library": str(self.library.usage_key.library_key.replace(version_guid=None, branch=None))} def reindex_library(self, store): """ kick off complete reindex of the course """ - return LibrarySearchIndexer.do_library_reindex(store, self.library.location.library_key) + return LibrarySearchIndexer.do_library_reindex(store, self.library.usage_key.library_key) def _get_contents(self, response): """ Extracts contents from search response """ @@ -776,7 +776,7 @@ def _test_creating_item(self, store): # updating a library item causes immediate reindexing data = "Some data" BlockFactory.create( - parent_location=self.library.location, + parent_location=self.library.usage_key, category="html", display_name="Html Content 3", data=data, @@ -813,7 +813,7 @@ def _test_deleting_item(self, store): self.assertEqual(response["total"], 2) # deleting a library item causes immediate reindexing - self.delete_item(store, self.html_unit1.location) + self.delete_item(store, self.html_unit1.usage_key) self.reindex_library(store) response = self.search() self.assertEqual(response["total"], 1) @@ -876,7 +876,7 @@ def _setup_course_with_content(self): Set up course with html content in it. """ self.chapter = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category='chapter', display_name="Week 1", modulestore=self.store, @@ -885,7 +885,7 @@ def _setup_course_with_content(self): ) self.sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category='sequential', display_name="Lesson 1", modulestore=self.store, @@ -894,7 +894,7 @@ def _setup_course_with_content(self): ) self.sequential2 = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category='sequential', display_name="Lesson 2", modulestore=self.store, @@ -903,7 +903,7 @@ def _setup_course_with_content(self): ) self.vertical = BlockFactory.create( - parent_location=self.sequential.location, + parent_location=self.sequential.usage_key, category='vertical', display_name='Subsection 1', modulestore=self.store, @@ -912,7 +912,7 @@ def _setup_course_with_content(self): ) self.vertical2 = BlockFactory.create( - parent_location=self.sequential.location, + parent_location=self.sequential.usage_key, category='vertical', display_name='Subsection 2', modulestore=self.store, @@ -921,7 +921,7 @@ def _setup_course_with_content(self): ) self.vertical3 = BlockFactory.create( - parent_location=self.sequential2.location, + parent_location=self.sequential2.usage_key, category='vertical', display_name='Subsection 3', modulestore=self.store, @@ -931,7 +931,7 @@ def _setup_course_with_content(self): # unspecified start - should inherit from container self.html_unit1 = BlockFactory.create( - parent_location=self.vertical.location, + parent_location=self.vertical.usage_key, category="html", display_name="Html Content 1", modulestore=self.store, @@ -940,7 +940,7 @@ def _setup_course_with_content(self): self.html_unit1.parent = self.vertical self.html_unit2 = BlockFactory.create( - parent_location=self.vertical2.location, + parent_location=self.vertical2.usage_key, category="html", display_name="Html Content 2", modulestore=self.store, @@ -949,7 +949,7 @@ def _setup_course_with_content(self): self.html_unit2.parent = self.vertical2 self.html_unit3 = BlockFactory.create( - parent_location=self.vertical2.location, + parent_location=self.vertical2.usage_key, category="html", display_name="Html Content 3", modulestore=self.store, @@ -966,7 +966,7 @@ def _setup_split_test_block(self): c2_url = self.course.id.make_usage_key("vertical", "condition_2_vertical") self.split_test_unit = BlockFactory.create( - parent_location=self.vertical3.location, + parent_location=self.vertical3.usage_key, category='split_test', user_partition_id=0, display_name="Test Content Experiment 1", @@ -974,7 +974,7 @@ def _setup_split_test_block(self): ) self.condition_0_vertical = BlockFactory.create( - parent_location=self.split_test_unit.location, + parent_location=self.split_test_unit.usage_key, category="vertical", display_name="Group ID 2", location=c0_url, @@ -982,7 +982,7 @@ def _setup_split_test_block(self): self.condition_0_vertical.parent = self.vertical3 self.condition_1_vertical = BlockFactory.create( - parent_location=self.split_test_unit.location, + parent_location=self.split_test_unit.usage_key, category="vertical", display_name="Group ID 3", location=c1_url, @@ -990,7 +990,7 @@ def _setup_split_test_block(self): self.condition_1_vertical.parent = self.vertical3 self.condition_2_vertical = BlockFactory.create( - parent_location=self.split_test_unit.location, + parent_location=self.split_test_unit.usage_key, category="vertical", display_name="Group ID 4", location=c2_url, @@ -998,7 +998,7 @@ def _setup_split_test_block(self): self.condition_2_vertical.parent = self.vertical3 self.html_unit4 = BlockFactory.create( - parent_location=self.condition_0_vertical.location, + parent_location=self.condition_0_vertical.usage_key, category="html", display_name="Split A", publish_item=True, @@ -1006,7 +1006,7 @@ def _setup_split_test_block(self): self.html_unit4.parent = self.condition_0_vertical self.html_unit5 = BlockFactory.create( - parent_location=self.condition_1_vertical.location, + parent_location=self.condition_1_vertical.usage_key, category="html", display_name="Split B", publish_item=True, @@ -1014,7 +1014,7 @@ def _setup_split_test_block(self): self.html_unit5.parent = self.condition_1_vertical self.html_unit6 = BlockFactory.create( - parent_location=self.condition_2_vertical.location, + parent_location=self.condition_2_vertical.usage_key, category="html", display_name="Split C", publish_item=True, @@ -1080,7 +1080,7 @@ def _html_group_result(self, html_unit, content_groups): """ return { 'course_name': self.course.display_name, - 'id': str(html_unit.location), + 'id': str(html_unit.usage_key), 'content': {'html_content': '', 'display_name': html_unit.display_name}, 'course': str(self.course.id), 'location': [ @@ -1100,7 +1100,7 @@ def _html_experiment_group_result(self, html_unit, content_groups): """ return { 'course_name': self.course.display_name, - 'id': str(html_unit.location), + 'id': str(html_unit.usage_key), 'content': {'html_content': '', 'display_name': html_unit.display_name}, 'course': str(self.course.id), 'location': [ @@ -1129,7 +1129,7 @@ def _vertical_experiment_group_result(self, vertical, content_groups): ], 'content_type': 'Sequence', 'content_groups': content_groups, - 'id': str(vertical.location), + 'id': str(vertical.usage_key), 'course_name': self.course.display_name, 'org': self.course.org } @@ -1140,7 +1140,7 @@ def _html_nogroup_result(self, html_unit): """ return { 'course_name': self.course.display_name, - 'id': str(html_unit.location), + 'id': str(html_unit.usage_key), 'content': {'html_content': '', 'display_name': html_unit.display_name}, 'course': str(self.course.id), 'location': [ @@ -1180,12 +1180,12 @@ def test_content_group_gets_indexed(self): group_access_content = {'group_access': {666: [1]}} self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit1.location), + reverse_usage_url("xblock_handler", self.html_unit1.usage_key), data={'metadata': group_access_content} ) - self.publish_item(self.store, self.html_unit1.location) - self.publish_item(self.store, self.split_test_unit.location) + self.publish_item(self.store, self.html_unit1.usage_key) + self.publish_item(self.store, self.split_test_unit.usage_key) with patch(settings.SEARCH_ENGINE + '.index') as mock_index: self.reindex_course(self.store) @@ -1250,11 +1250,11 @@ def test_content_group_not_indexed_on_delete(self): group_access_content = {'group_access': {666: [1]}} self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit1.location), + reverse_usage_url("xblock_handler", self.html_unit1.usage_key), data={'metadata': group_access_content} ) - self.publish_item(self.store, self.html_unit1.location) + self.publish_item(self.store, self.html_unit1.usage_key) # Checking group indexed correctly with patch(settings.SEARCH_ENGINE + '.index') as mock_index: @@ -1267,11 +1267,11 @@ def test_content_group_not_indexed_on_delete(self): empty_group_access = {'group_access': {}} self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit1.location), + reverse_usage_url("xblock_handler", self.html_unit1.usage_key), data={'metadata': empty_group_access} ) - self.publish_item(self.store, self.html_unit1.location) + self.publish_item(self.store, self.html_unit1.usage_key) # Checking group removed and not indexed any more with patch(settings.SEARCH_ENGINE + '.index') as mock_index: @@ -1285,11 +1285,11 @@ def test_group_indexed_only_on_assigned_html_block(self): """ indexing course with content groups assigned to one of multiple html units """ group_access_content = {'group_access': {666: [1]}} self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit1.location), + reverse_usage_url("xblock_handler", self.html_unit1.usage_key), data={'metadata': group_access_content} ) - self.publish_item(self.store, self.html_unit1.location) + self.publish_item(self.store, self.html_unit1.usage_key) with patch(settings.SEARCH_ENGINE + '.index') as mock_index: self.reindex_course(self.store) @@ -1305,16 +1305,16 @@ def test_different_groups_indexed_on_assigned_html_blocks(self): group_access_content_2 = {'group_access': {666: [0]}} self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit1.location), + reverse_usage_url("xblock_handler", self.html_unit1.usage_key), data={'metadata': group_access_content_1} ) self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit2.location), + reverse_usage_url("xblock_handler", self.html_unit2.usage_key), data={'metadata': group_access_content_2} ) - self.publish_item(self.store, self.html_unit1.location) - self.publish_item(self.store, self.html_unit2.location) + self.publish_item(self.store, self.html_unit1.usage_key) + self.publish_item(self.store, self.html_unit2.usage_key) with patch(settings.SEARCH_ENGINE + '.index') as mock_index: self.reindex_course(self.store) @@ -1334,16 +1334,16 @@ def test_different_groups_indexed_on_same_vertical_html_blocks(self): group_access_content_2 = {'group_access': {666: [0]}} self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit2.location), + reverse_usage_url("xblock_handler", self.html_unit2.usage_key), data={'metadata': group_access_content_1} ) self.client.ajax_post( - reverse_usage_url("xblock_handler", self.html_unit3.location), + reverse_usage_url("xblock_handler", self.html_unit3.usage_key), data={'metadata': group_access_content_2} ) - self.publish_item(self.store, self.html_unit2.location) - self.publish_item(self.store, self.html_unit3.location) + self.publish_item(self.store, self.html_unit2.usage_key) + self.publish_item(self.store, self.html_unit3.usage_key) with patch(settings.SEARCH_ENGINE + '.index') as mock_index: self.reindex_course(self.store) diff --git a/cms/djangoapps/contentstore/tests/test_crud.py b/cms/djangoapps/contentstore/tests/test_crud.py index 792d0386ac48..116b13cef448 100644 --- a/cms/djangoapps/contentstore/tests/test_crud.py +++ b/cms/djangoapps/contentstore/tests/test_crud.py @@ -26,7 +26,7 @@ def test_get_templates(self): def test_get_some_templates(self): course = CourseFactory.create() - htmlblock = BlockFactory.create(category="html", parent_location=course.location) + htmlblock = BlockFactory.create(category="html", parent_location=course.usage_key) self.assertEqual(len(SequenceBlock.templates()), 0) self.assertGreater(len(htmlblock.templates()), 0) @@ -50,14 +50,14 @@ def test_factories(self): self.assertEqual(course_from_store.id.run, '2014') test_chapter = BlockFactory.create( - parent_location=test_course.location, + parent_location=test_course.usage_key, category='chapter', display_name='chapter 1' ) self.assertIsInstance(test_chapter, SequenceBlock) # refetch parent which should now point to child test_course = self.store.get_course(test_course.id.version_agnostic()) - self.assertIn(test_chapter.location, test_course.children) + self.assertIn(test_chapter.usage_key, test_course.children) with self.assertRaises(DuplicateCourseError): CourseFactory.create( @@ -106,7 +106,7 @@ def test_delete_course(self): user_id=ModuleStoreEnum.UserID.test, ) BlockFactory.create( - parent_location=test_course.location, + parent_location=test_course.usage_key, category='chapter', display_name='chapter 1' ) @@ -115,7 +115,7 @@ def test_delete_course(self): # verify it can be retrieved by id self.assertIsInstance(self.store.get_course(id_locator), CourseBlock) # TODO reenable when split_draft supports getting specific versions - # guid_locator = test_course.location.course_agnostic() + # guid_locator = test_course.usage_key.course_agnostic() # Verify it can be retrieved by guid # self.assertIsInstance(self.store.get_item(guid_locator), CourseBlock) self.store.delete_course(id_locator, ModuleStoreEnum.UserID.test) diff --git a/cms/djangoapps/contentstore/tests/test_exams.py b/cms/djangoapps/contentstore/tests/test_exams.py index 823038957714..f65a1ce961a2 100644 --- a/cms/djangoapps/contentstore/tests/test_exams.py +++ b/cms/djangoapps/contentstore/tests/test_exams.py @@ -120,7 +120,7 @@ def test_publishing_exam(self, is_proctored_exam, is_practice_exam, expected_exams = [{ 'course_id': self.course_key, - 'content_id': str(sequence.location), + 'content_id': str(sequence.usage_key), 'exam_name': sequence.display_name, 'time_limit_mins': sequence.default_time_limit_minutes, 'due_date': expected_due_date, @@ -155,7 +155,7 @@ def test_dangling_exam(self, mock_patch_course_exams): is_proctored_enabled=True, hide_after_due=False, ) - self.store.delete_item(self.chapter.location, self.user.id) + self.store.delete_item(self.chapter.usage_key, self.user.id) listen_for_course_publish(self, self.course.id) mock_patch_course_exams.assert_called_once_with([], self.course_key) diff --git a/cms/djangoapps/contentstore/tests/test_filters.py b/cms/djangoapps/contentstore/tests/test_filters.py index 4011ae728b34..cdf0bab0ffff 100644 --- a/cms/djangoapps/contentstore/tests/test_filters.py +++ b/cms/djangoapps/contentstore/tests/test_filters.py @@ -41,10 +41,10 @@ def setUp(self): # pylint: disable=arguments-differ self.upload_date = datetime(2013, 6, 1, 10, 30, tzinfo=UTC) self.content_type = 'image/jpg' self.course_key = CourseLocator('org', 'class', 'run') - self.location = self.course_key.make_asset_key('asset', 'my_file_name.jpg') + self.usage_key = self.course_key.make_asset_key('asset', 'my_file_name.jpg') self.thumbnail_location = self.course_key.make_asset_key('thumbnail', 'my_file_name_thumb.jpg') - self.asset_url = StaticContent.serialize_asset_key_with_slash(self.location) + self.asset_url = StaticContent.serialize_asset_key_with_slash(self.usage_key) @override_settings( OPEN_EDX_FILTERS_CONFIG={ @@ -68,7 +68,7 @@ def test_lms_url_requested_filter_executed(self): "my_file", self.content_type, self.upload_date, - self.location, + self.usage_key, self.thumbnail_location, True, self.course_key @@ -89,7 +89,7 @@ def test_lms_url_requested_without_filter_configuration(self): "my_file", self.content_type, self.upload_date, - self.location, + self.usage_key, self.thumbnail_location, True, self.course_key diff --git a/cms/djangoapps/contentstore/tests/test_gating.py b/cms/djangoapps/contentstore/tests/test_gating.py index 91d2395bfde4..d5af490b0bd1 100644 --- a/cms/djangoapps/contentstore/tests/test_gating.py +++ b/cms/djangoapps/contentstore/tests/test_gating.py @@ -43,25 +43,25 @@ def setUp(self): category='sequential', display_name="Gated Sequential" ) - gating_api.add_prerequisite(self.course.id, self.open_seq.location) - gating_api.set_required_content(self.course.id, self.gated_seq.location, self.open_seq.location, 100, 100) + gating_api.add_prerequisite(self.course.id, self.open_seq.usage_key) + gating_api.set_required_content(self.course.id, self.gated_seq.usage_key, self.open_seq.usage_key, 100, 100) @patch('cms.djangoapps.contentstore.signals.handlers.gating_api.set_required_content') @patch('cms.djangoapps.contentstore.signals.handlers.gating_api.remove_prerequisite') def test_chapter_deleted(self, mock_remove_prereq, mock_set_required): """ Test gating milestone data is cleanup up when course content item is deleted """ - handle_item_deleted(usage_key=self.chapter.location, user_id=0) - mock_remove_prereq.assert_called_with(self.open_seq.location) + handle_item_deleted(usage_key=self.chapter.usage_key, user_id=0) + mock_remove_prereq.assert_called_with(self.open_seq.usage_key) mock_set_required.assert_called_with( - self.open_seq.location.course_key, self.open_seq.location, None, None, None + self.open_seq.usage_key.course_key, self.open_seq.usage_key, None, None, None ) @patch('cms.djangoapps.contentstore.signals.handlers.gating_api.set_required_content') @patch('cms.djangoapps.contentstore.signals.handlers.gating_api.remove_prerequisite') def test_sequential_deleted(self, mock_remove_prereq, mock_set_required): """ Test gating milestone data is cleanup up when course content item is deleted """ - handle_item_deleted(usage_key=self.open_seq.location, user_id=0) - mock_remove_prereq.assert_called_with(self.open_seq.location) + handle_item_deleted(usage_key=self.open_seq.usage_key, user_id=0) + mock_remove_prereq.assert_called_with(self.open_seq.usage_key) mock_set_required.assert_called_with( - self.open_seq.location.course_key, self.open_seq.location, None, None, None + self.open_seq.usage_key.course_key, self.open_seq.usage_key, None, None, None ) diff --git a/cms/djangoapps/contentstore/tests/test_libraries.py b/cms/djangoapps/contentstore/tests/test_libraries.py index 376ba56d8dd9..ea7177dd2772 100644 --- a/cms/djangoapps/contentstore/tests/test_libraries.py +++ b/cms/djangoapps/contentstore/tests/test_libraries.py @@ -82,7 +82,7 @@ def _add_library_content_block(self, course, library_key, publish_item=False, ot """ return BlockFactory.create( category='library_content', - parent_location=course.location, + parent_location=course.usage_key, user_id=self.user.id, publish_item=publish_item, source_library_id=str(library_key), @@ -92,7 +92,7 @@ def _add_library_content_block(self, course, library_key, publish_item=False, ot def _add_simple_content_block(self): """ Adds simple HTML block to library """ return BlockFactory.create( - category="html", parent_location=self.library.location, + category="html", parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False ) @@ -107,12 +107,12 @@ def _upgrade_and_sync(self, lib_content_block, status_code_expected=200): handler_url = reverse_usage_url( 'preview_handler', - lib_content_block.location, + lib_content_block.usage_key, kwargs={'handler': 'upgrade_and_sync'} ) response = self.client.ajax_post(handler_url) self.assertEqual(response.status_code, status_code_expected) - return modulestore().get_item(lib_content_block.location) + return modulestore().get_item(lib_content_block.usage_key) def _bind_block(self, block, user=None): """ @@ -190,14 +190,14 @@ def test_consistent_children(self): for num in range(8): BlockFactory.create( data=f"This is #{num + 1}", - category="html", parent_location=self.library.location, user_id=self.user.id, publish_item=False + category="html", parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False ) with modulestore().default_store(ModuleStoreEnum.Type.split): course = CourseFactory.create() lc_block = self._add_library_content_block(course, self.lib_key, {'max_count': 1}) - lc_block_key = lc_block.location + lc_block_key = lc_block.usage_key lc_block = self._upgrade_and_sync(lc_block) def get_child_of_lc_block(block): @@ -225,7 +225,7 @@ def check(): lc_block = modulestore().get_item(lc_block_key) # Reload block from the database self._bind_block(lc_block) current_child = get_child_of_lc_block(lc_block) - self.assertEqual(current_child.location, chosen_child.location) + self.assertEqual(current_child.usage_key, chosen_child.usage_key) self.assertEqual(current_child.data, chosen_child.data) self.assertEqual(current_child.definition_locator.definition_id, chosen_child_defn_id) @@ -266,7 +266,7 @@ def test_fields(self): name_value = "A Scope.settings value" lib_block = BlockFactory.create( category="html", - parent_location=self.library.location, + parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False, display_name=name_value, @@ -296,13 +296,13 @@ def test_block_with_children(self): # In the library, create a vertical block with a child: vert_block = BlockFactory.create( category="vertical", - parent_location=self.library.location, + parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False, ) child_block = BlockFactory.create( category="html", - parent_location=vert_block.location, + parent_location=vert_block.usage_key, user_id=self.user.id, publish_item=False, display_name=name_value, @@ -337,7 +337,7 @@ def test_switch_to_unknown_source_library_preserves_settings(self): data_value = "Hello world!" BlockFactory.create( category="html", - parent_location=self.library.location, + parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False, display_name="HTML BLock", @@ -360,12 +360,12 @@ def test_switch_to_unknown_source_library_preserves_settings(self): # Now, change the block settings to have an invalid library key: bad_library_id = "library-v1:NOT+FOUND" resp = self._update_block( - lc_block.location, + lc_block.usage_key, {"source_library_id": bad_library_id}, ) self.assertEqual(resp.status_code, 200) - lc_block = modulestore().get_item(lc_block.location) + lc_block = modulestore().get_item(lc_block.usage_key) # Source library id should be set to the new bad one... assert lc_block.source_library_id == bad_library_id # ...but old source library version should be preserved... @@ -379,7 +379,7 @@ def test_switch_to_unknown_source_library_preserves_settings(self): self._upgrade_and_sync(lc_block, status_code_expected=400) # (Repeat the exact same checks) - lc_block = modulestore().get_item(lc_block.location) + lc_block = modulestore().get_item(lc_block.usage_key) # Source library id should be set to the new bad one... assert lc_block.source_library_id == bad_library_id # ...but old source library version should be preserved... @@ -397,7 +397,7 @@ def test_sync_if_source_library_changed(self): data1, data2 = "Hello world from lib 1!", "Hello other world from lib 2" BlockFactory.create( category="html", - parent_location=self.library.location, + parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False, display_name="Lib 1: HTML BLock", @@ -406,7 +406,7 @@ def test_sync_if_source_library_changed(self): BlockFactory.create( category="html", - parent_location=library2.location, + parent_location=library2.usage_key, user_id=self.user.id, publish_item=False, display_name="Lib 2: HTML BLock", @@ -429,13 +429,13 @@ def test_sync_if_source_library_changed(self): # Now, switch over to new library. Don't call upgrade_and_sync, because we are # testing that it happens automatically. resp = self._update_block( - lc_block.location, + lc_block.usage_key, {"source_library_id": str(library2key)}, ) self.assertEqual(resp.status_code, 200) # Check that the course now has the new lib's new block. - lc_block = modulestore().get_item(lc_block.location) + lc_block = modulestore().get_item(lc_block.usage_key) self.assertEqual(len(lc_block.children), 1) html_block_2 = modulestore().get_item(lc_block.children[0]) self.assertEqual(html_block_2.data, data2) @@ -445,7 +445,7 @@ def test_sync_if_capa_type_changed(self): name1, name2 = "Option Problem", "Multiple Choice Problem" BlockFactory.create( category="problem", - parent_location=self.library.location, + parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False, display_name=name1, @@ -453,7 +453,7 @@ def test_sync_if_capa_type_changed(self): ) BlockFactory.create( category="problem", - parent_location=self.library.location, + parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False, display_name=name2, @@ -470,22 +470,22 @@ def test_sync_if_capa_type_changed(self): self.assertEqual(len(lc_block.children), 2) resp = self._update_block( - lc_block.location, + lc_block.usage_key, {"capa_type": 'optionresponse'}, ) self.assertEqual(resp.status_code, 200) - lc_block = modulestore().get_item(lc_block.location) + lc_block = modulestore().get_item(lc_block.usage_key) self.assertEqual(len(lc_block.children), 1) html_block = modulestore().get_item(lc_block.children[0]) self.assertEqual(html_block.display_name, name1) resp = self._update_block( - lc_block.location, + lc_block.usage_key, {"capa_type": 'multiplechoiceresponse'}, ) self.assertEqual(resp.status_code, 200) - lc_block = modulestore().get_item(lc_block.location) + lc_block = modulestore().get_item(lc_block.usage_key) self.assertEqual(len(lc_block.children), 1) html_block = modulestore().get_item(lc_block.children[0]) @@ -547,7 +547,7 @@ def _can_access_library(self, library): if isinstance(library, (str, LibraryLocator)): lib_key = library else: - lib_key = library.location.library_key + lib_key = library.usage_key.library_key response = self.client.get(reverse_library_url('library_handler', str(lib_key))) self.assertIn(response.status_code, (200, 302, 403)) return response.status_code == 200 @@ -656,7 +656,7 @@ def test_read_only_role(self, use_org_level_role): self._login_as_non_staff_user() self.assertFalse(self._can_access_library(self.library)) - block_url = reverse_usage_url('xblock_handler', block.location) + block_url = reverse_usage_url('xblock_handler', block.usage_key) def can_read_block(): """ Check if studio lets us view the XBlock in the library """ @@ -679,8 +679,8 @@ def can_delete_block(): def can_copy_block(): """ Check if studio lets us duplicate the XBlock in the library """ response = self.client.ajax_post(reverse_url('xblock_handler'), { - 'parent_locator': str(self.library.location), - 'duplicate_source_locator': str(block.location), + 'parent_locator': str(self.library.usage_key), + 'duplicate_source_locator': str(block.usage_key), }) self.assertIn(response.status_code, (200, 403)) # 400 would be ambiguous return response.status_code == 200 @@ -688,7 +688,7 @@ def can_copy_block(): def can_create_block(): """ Check if studio lets us make a new XBlock in the library """ response = self.client.ajax_post(reverse_url('xblock_handler'), { - 'parent_locator': str(self.library.location), 'category': 'html', + 'parent_locator': str(self.library.usage_key), 'category': 'html', }) self.assertIn(response.status_code, (200, 403)) # 400 would be ambiguous return response.status_code == 200 @@ -737,12 +737,12 @@ def test_duplicate_across_courses(self, library_role, course_role, expected_resu if library_role: library_role(self.lib_key).add_users(self.non_staff_user) if course_role: - course_role(course.location.course_key).add_users(self.non_staff_user) + course_role(course.usage_key.course_key).add_users(self.non_staff_user) # Copy block to the course: response = self.client.ajax_post(reverse_url('xblock_handler'), { - 'parent_locator': str(course.location), - 'duplicate_source_locator': str(block.location), + 'parent_locator': str(course.usage_key), + 'duplicate_source_locator': str(block.usage_key), }) self.assertIn(response.status_code, (200, 403)) # 400 would be ambiguous duplicate_action_allowed = (response.status_code == 200) @@ -774,7 +774,7 @@ def test_upgrade_and_sync_handler_content_permissions(self, library_role, course if library_role: library_role(self.lib_key).add_users(self.non_staff_user) if course_role: - course_role(course.location.course_key).add_users(self.non_staff_user) + course_role(course.usage_key.course_key).add_users(self.non_staff_user) # Try updating our library content block: lc_block = self._add_library_content_block(course, self.lib_key) @@ -806,7 +806,7 @@ def test_studio_user_permissions(self): lib_block = BlockFactory.create( category='library_content', - parent_location=course.location, + parent_location=course.usage_key, user_id=self.non_staff_user.id, publish_item=False ) @@ -816,7 +816,7 @@ def _get_settings_html(): Helper function to get block settings HTML Used to check the available libraries. """ - edit_view_url = reverse_usage_url("xblock_view_handler", lib_block.location, {"view_name": STUDIO_VIEW}) + edit_view_url = reverse_usage_url("xblock_view_handler", lib_block.usage_key, {"view_name": STUDIO_VIEW}) resp = self.client.get_json(edit_view_url) self.assertEqual(resp.status_code, 200) @@ -857,7 +857,7 @@ def setUp(self): # Create a problem block in the library: self.problem = BlockFactory.create( category="problem", - parent_location=self.library.location, + parent_location=self.library.usage_key, display_name=self.original_display_name, # display_name is a Scope.settings field weight=self.original_weight, # weight is also a Scope.settings field user_id=self.user.id, @@ -908,7 +908,7 @@ def test_reset_override(self): self.problem_in_course.display_name = new_display_name self.problem_in_course.weight = new_weight modulestore().update_item(self.problem_in_course, self.user.id) - self.problem_in_course = modulestore().get_item(self.problem_in_course.location) + self.problem_in_course = modulestore().get_item(self.problem_in_course.usage_key) self.assertEqual(self.problem_in_course.display_name, new_display_name) self.assertEqual(self.problem_in_course.weight, new_weight) @@ -919,7 +919,7 @@ def test_reset_override(self): # Save, reload, and verify: modulestore().update_item(self.problem_in_course, self.user.id) - self.problem_in_course = modulestore().get_item(self.problem_in_course.location) + self.problem_in_course = modulestore().get_item(self.problem_in_course.usage_key) self.assertEqual(self.problem_in_course.display_name, self.original_display_name) self.assertEqual(self.problem_in_course.weight, self.original_weight) @@ -939,7 +939,7 @@ def test_consistent_definitions(self): self.problem.display_name = "NEW" modulestore().update_item(self.problem, self.user.id) self.lc_block = self._upgrade_and_sync(self.lc_block) - self.problem_in_course = modulestore().get_item(self.problem_in_course.location) + self.problem_in_course = modulestore().get_item(self.problem_in_course.usage_key) self.assertEqual(self.problem.definition_locator.definition_id, definition_id) self.assertEqual(self.problem_in_course.definition_locator.definition_id, definition_id) @@ -960,11 +960,11 @@ def test_persistent_overrides(self, duplicate): if duplicate: # Check that this also works when the RCB is duplicated. self.lc_block = modulestore().get_item( - duplicate_block(self.course.location, self.lc_block.location, self.user) + duplicate_block(self.course.usage_key, self.lc_block.usage_key, self.user) ) self.problem_in_course = modulestore().get_item(self.lc_block.children[0]) else: - self.problem_in_course = modulestore().get_item(self.problem_in_course.location) + self.problem_in_course = modulestore().get_item(self.problem_in_course.usage_key) self.assertEqual(self.problem_in_course.display_name, new_display_name) self.assertEqual(self.problem_in_course.weight, new_weight) @@ -976,7 +976,7 @@ def test_persistent_overrides(self, duplicate): modulestore().update_item(self.problem, self.user.id) self.lc_block = self._upgrade_and_sync(self.lc_block) - self.problem_in_course = modulestore().get_item(self.problem_in_course.location) + self.problem_in_course = modulestore().get_item(self.problem_in_course.usage_key) self.assertEqual(self.problem_in_course.display_name, new_display_name) self.assertEqual(self.problem_in_course.weight, new_weight) @@ -997,7 +997,7 @@ def test_duplicated_version(self): # Create an additional problem block in the library: BlockFactory.create( category="problem", - parent_location=self.library.location, + parent_location=self.library.usage_key, user_id=self.user.id, publish_item=False, ) @@ -1009,14 +1009,14 @@ def test_duplicated_version(self): self.assertEqual(len(self.library.children), 2) # But the block hasn't. - self.lc_block = store.get_item(self.lc_block.location) + self.lc_block = store.get_item(self.lc_block.usage_key) self.assertEqual(len(self.lc_block.children), 1) - self.assertEqual(self.problem_in_course.location, self.lc_block.children[0]) + self.assertEqual(self.problem_in_course.usage_key, self.lc_block.children[0]) self.assertEqual(self.problem_in_course.display_name, self.original_display_name) # Duplicate self.lc_block: duplicate = store.get_item( - duplicate_block(self.course.location, self.lc_block.location, self.user) + duplicate_block(self.course.usage_key, self.lc_block.usage_key, self.user) ) # The duplicate should have identical children to the original: self.assertTrue(self.lc_block.source_library_version) @@ -1027,7 +1027,7 @@ def test_duplicated_version(self): # Refresh our reference to the block self.lc_block = self._upgrade_and_sync(self.lc_block) - self.problem_in_course = store.get_item(self.problem_in_course.location) + self.problem_in_course = store.get_item(self.problem_in_course.usage_key) # and the block has changed too. self.assertEqual(len(self.lc_block.children), 2) diff --git a/cms/djangoapps/contentstore/tests/test_orphan.py b/cms/djangoapps/contentstore/tests/test_orphan.py index 244eecebf9af..45e03f010743 100644 --- a/cms/djangoapps/contentstore/tests/test_orphan.py +++ b/cms/djangoapps/contentstore/tests/test_orphan.py @@ -27,41 +27,41 @@ def create_course_with_orphans(self, default_store): course = CourseFactory.create(default_store=default_store) # create chapters and add them to course tree - chapter1 = self.store.create_child(self.user.id, course.location, 'chapter', "Chapter1") - self.store.publish(chapter1.location, self.user.id) + chapter1 = self.store.create_child(self.user.id, course.usage_key, 'chapter', "Chapter1") + self.store.publish(chapter1.usage_key, self.user.id) - chapter2 = self.store.create_child(self.user.id, course.location, 'chapter', "Chapter2") - self.store.publish(chapter2.location, self.user.id) + chapter2 = self.store.create_child(self.user.id, course.usage_key, 'chapter', "Chapter2") + self.store.publish(chapter2.usage_key, self.user.id) # orphan chapter orphan_chapter = self.store.create_item(self.user.id, course.id, 'chapter', "OrphanChapter") - self.store.publish(orphan_chapter.location, self.user.id) + self.store.publish(orphan_chapter.usage_key, self.user.id) # create vertical and add it as child to chapter1 - vertical1 = self.store.create_child(self.user.id, chapter1.location, 'vertical', "Vertical1") - self.store.publish(vertical1.location, self.user.id) + vertical1 = self.store.create_child(self.user.id, chapter1.usage_key, 'vertical', "Vertical1") + self.store.publish(vertical1.usage_key, self.user.id) # create orphan vertical orphan_vertical = self.store.create_item(self.user.id, course.id, 'vertical', "OrphanVert") - self.store.publish(orphan_vertical.location, self.user.id) + self.store.publish(orphan_vertical.usage_key, self.user.id) # create component and add it to vertical1 - html1 = self.store.create_child(self.user.id, vertical1.location, 'html', "Html1") - self.store.publish(html1.location, self.user.id) + html1 = self.store.create_child(self.user.id, vertical1.usage_key, 'html', "Html1") + self.store.publish(html1.usage_key, self.user.id) # create component and add it as a child to vertical1 and orphan_vertical - multi_parent_html = self.store.create_child(self.user.id, vertical1.location, 'html', "multi_parent_html") - self.store.publish(multi_parent_html.location, self.user.id) + multi_parent_html = self.store.create_child(self.user.id, vertical1.usage_key, 'html', "multi_parent_html") + self.store.publish(multi_parent_html.usage_key, self.user.id) - orphan_vertical.children.append(multi_parent_html.location) + orphan_vertical.children.append(multi_parent_html.usage_key) self.store.update_item(orphan_vertical, self.user.id) # create an orphaned html block orphan_html = self.store.create_item(self.user.id, course.id, 'html', "OrphanHtml") - self.store.publish(orphan_html.location, self.user.id) + self.store.publish(orphan_html.usage_key, self.user.id) - self.store.create_child(self.user.id, course.location, 'static_tab', "staticuno") - self.store.create_child(self.user.id, course.location, 'course_info', "updates") + self.store.create_child(self.user.id, course.usage_key, 'static_tab', "staticuno") + self.store.create_child(self.user.id, course.usage_key, 'course_info', "updates") return course @@ -92,11 +92,11 @@ def test_get_orphans(self): ).content.decode('utf-8') ) self.assertEqual(len(orphans), 3, f"Wrong # {orphans}") - location = course.location.replace(category='chapter', name='OrphanChapter') + location = course.usage_key.replace(category='chapter', name='OrphanChapter') self.assertIn(str(location), orphans) - location = course.location.replace(category='vertical', name='OrphanVert') + location = course.usage_key.replace(category='vertical', name='OrphanVert') self.assertIn(str(location), orphans) - location = course.location.replace(category='html', name='OrphanHtml') + location = course.usage_key.replace(category='html', name='OrphanHtml') self.assertIn(str(location), orphans) def test_delete_orphans(self): @@ -155,24 +155,24 @@ def test_path_to_location_for_orphan_vertical(self): multi_parent_html = self.store.get_item(BlockUsageLocator(course.id, 'html', 'multi_parent_html')) # Verify `OrphanVert` is an orphan - self.assertIn(orphan_vertical.location, self.store.get_orphans(course.id)) + self.assertIn(orphan_vertical.usage_key, self.store.get_orphans(course.id)) # Verify `multi_parent_html` is child of both `Vertical1` and `OrphanVert` - self.assertIn(multi_parent_html.location, orphan_vertical.children) - self.assertIn(multi_parent_html.location, vertical1.children) + self.assertIn(multi_parent_html.usage_key, orphan_vertical.children) + self.assertIn(multi_parent_html.usage_key, vertical1.children) # HTML component has `vertical1` as its parent. - html_parent = self.store.get_parent_location(multi_parent_html.location) - self.assertNotEqual(str(html_parent), str(orphan_vertical.location)) - self.assertEqual(str(html_parent), str(vertical1.location)) + html_parent = self.store.get_parent_location(multi_parent_html.usage_key) + self.assertNotEqual(str(html_parent), str(orphan_vertical.usage_key)) + self.assertEqual(str(html_parent), str(vertical1.usage_key)) # Get path of the `multi_parent_html` & verify path_to_location returns a expected path - path = path_to_location(self.store, multi_parent_html.location) + path = path_to_location(self.store, multi_parent_html.usage_key) expected_path = ( course.id, - chapter1.location.block_id, - vertical1.location.block_id, - multi_parent_html.location.block_id, + chapter1.usage_key.block_id, + vertical1.usage_key.block_id, + multi_parent_html.usage_key.block_id, "", path[-1] ) @@ -201,38 +201,38 @@ def test_path_to_location_for_orphan_chapter(self): vertical1 = self.store.get_item(BlockUsageLocator(course.id, 'vertical', 'Vertical1')) # Verify `OrhanChapter` is an orphan - self.assertIn(orphan_chapter.location, self.store.get_orphans(course.id)) + self.assertIn(orphan_chapter.usage_key, self.store.get_orphans(course.id)) # Create a vertical (`Vertical0`) in orphan chapter (`OrphanChapter`). # OrphanChapter -> Vertical0 - vertical0 = self.store.create_child(self.user.id, orphan_chapter.location, 'vertical', "Vertical0") - self.store.publish(vertical0.location, self.user.id) + vertical0 = self.store.create_child(self.user.id, orphan_chapter.usage_key, 'vertical', "Vertical0") + self.store.publish(vertical0.usage_key, self.user.id) # Create a component in `Vertical0` # OrphanChapter -> Vertical0 -> Html - html = self.store.create_child(self.user.id, vertical0.location, 'html', "HTML0") - self.store.publish(html.location, self.user.id) + html = self.store.create_child(self.user.id, vertical0.usage_key, 'html', "HTML0") + self.store.publish(html.usage_key, self.user.id) # Verify chapter1 is parent of vertical1. - vertical1_parent = self.store.get_parent_location(vertical1.location) - self.assertEqual(str(vertical1_parent), str(chapter1.location)) + vertical1_parent = self.store.get_parent_location(vertical1.usage_key) + self.assertEqual(str(vertical1_parent), str(chapter1.usage_key)) # Make `Vertical1` the parent of `HTML0`. So `HTML0` will have to parents (`Vertical0` & `Vertical1`) - vertical1.children.append(html.location) + vertical1.children.append(html.usage_key) self.store.update_item(vertical1, self.user.id) # Get parent location & verify its either of the two verticals. As both parents are non-orphan, # alphabetically least is returned - html_parent = self.store.get_parent_location(html.location) - self.assertEqual(str(html_parent), str(vertical1.location)) + html_parent = self.store.get_parent_location(html.usage_key) + self.assertEqual(str(html_parent), str(vertical1.usage_key)) # verify path_to_location returns a expected path - path = path_to_location(self.store, html.location) + path = path_to_location(self.store, html.usage_key) expected_path = ( course.id, - chapter1.location.block_id, - vertical1.location.block_id, - html.location.block_id, + chapter1.usage_key.block_id, + vertical1.usage_key.block_id, + html.usage_key.block_id, "", path[-1] ) diff --git a/cms/djangoapps/contentstore/tests/test_outlines.py b/cms/djangoapps/contentstore/tests/test_outlines.py index 108edd82df43..f424fba5cbe8 100644 --- a/cms/djangoapps/contentstore/tests/test_outlines.py +++ b/cms/djangoapps/contentstore/tests/test_outlines.py @@ -177,13 +177,13 @@ def test_duplicate_children(self): parent=self.draft_course, category='chapter', display_name="Section 2", - children=[seq.location] + children=[seq.usage_key] ) section_3 = BlockFactory.create( parent=self.draft_course, category='chapter', display_name="Section 3", - children=[seq.location] + children=[seq.usage_key] ) self.store.update_item(section_2, self.user.id) @@ -291,8 +291,8 @@ def test_sequence_without_section(self): outline, errs = get_outline_from_modulestore(self.course_key) assert len(errs) == 1 - # Strip version information from seq.location before comparison. - assert errs[0].usage_key == seq.location.map_into_course(self.course_key) + # Strip version information from seq.usage_key before comparison. + assert errs[0].usage_key == seq.usage_key.map_into_course(self.course_key) assert outline.sections == [] assert outline.sequences == {} @@ -479,7 +479,7 @@ def _outline_seq_data(self, modulestore_seq): # Recently modified content can have full version information on their # CourseKeys. We need to strip that out and have versionless-CourseKeys # or they won't be found properly. - versionless_usage_key = modulestore_seq.location.map_into_course(self.course_key) + versionless_usage_key = modulestore_seq.usage_key.map_into_course(self.course_key) outline_seq_data = outline.sequences[versionless_usage_key] return outline_seq_data, versionless_usage_key @@ -527,21 +527,21 @@ def test_task_invocation(self): default_store=ModuleStoreEnum.Type.split, ) section = BlockFactory.create( - parent_location=course.location, + parent_location=course.usage_key, category="chapter", display_name="First Section" ) BlockFactory.create( - parent_location=section.location, + parent_location=section.usage_key, category="sequential", display_name="First Sequence" ) BlockFactory.create( - parent_location=section.location, + parent_location=section.usage_key, category="sequential", display_name="Second Sequence" ) - self.store.publish(course.location, self.user.id) + self.store.publish(course.usage_key, self.user.id) outline = get_course_outline(course_key) assert len(outline.sections) == 1 diff --git a/cms/djangoapps/contentstore/tests/test_proctoring.py b/cms/djangoapps/contentstore/tests/test_proctoring.py index d9b83a811ef0..768185995a98 100644 --- a/cms/djangoapps/contentstore/tests/test_proctoring.py +++ b/cms/djangoapps/contentstore/tests/test_proctoring.py @@ -66,7 +66,7 @@ def _verify_exam_data(self, sequence, expected_active): self.assertEqual(exam['hide_after_due'], sequence.hide_after_due) self.assertEqual(exam['course_id'], str(self.course.id)) - self.assertEqual(exam['content_id'], str(sequence.location)) + self.assertEqual(exam['content_id'], str(sequence.usage_key)) self.assertEqual(exam['exam_name'], sequence.display_name) self.assertEqual(exam['time_limit_mins'], sequence.default_time_limit_minutes) self.assertEqual(exam['is_proctored'], sequence.is_proctored_exam) @@ -207,7 +207,7 @@ def test_dangling_exam(self): exams = get_all_exams_for_course(str(self.course.id)) self.assertEqual(len(exams), 1) - self.store.delete_item(chapter.location, self.user.id) + self.store.delete_item(chapter.usage_key, self.user.id) # republish course listen_for_course_publish(self, self.course.id) diff --git a/cms/djangoapps/contentstore/tests/test_tasks.py b/cms/djangoapps/contentstore/tests/test_tasks.py index 5a76b7d67fe7..0d71aa2086f0 100644 --- a/cms/djangoapps/contentstore/tests/test_tasks.py +++ b/cms/djangoapps/contentstore/tests/test_tasks.py @@ -67,7 +67,7 @@ def test_success(self): """ Verify that a routine course export task succeeds """ - key = str(self.course.location.course_key) + key = str(self.course.usage_key.course_key) result = export_olx.delay(self.user.id, key, 'en') status = UserTaskStatus.objects.get(task_id=result.id) self.assertEqual(status.state, UserTaskStatus.SUCCEEDED) @@ -81,7 +81,7 @@ def test_exception(self, mock_export): # pylint: disable=unused-argument """ The export task should fail gracefully if an exception is thrown """ - key = str(self.course.location.course_key) + key = str(self.course.usage_key.course_key) result = export_olx.delay(self.user.id, key, 'en') self._assert_failed(result, json.dumps({'raw_error_msg': 'Boom!'})) @@ -91,7 +91,7 @@ def test_invalid_user_id(self, mock_raise_exc): # pylint: disable=unused-argume Verify that attempts to export a course as an invalid user fail """ user = UserFactory(id=User.objects.order_by('-id').first().pk + 100) - key = str(self.course.location.course_key) + key = str(self.course.usage_key.course_key) result = export_olx.delay(user.id, key, 'en') self._assert_failed(result, f'Unknown User ID: {user.id}') @@ -100,7 +100,7 @@ def test_non_course_author(self): Verify that users who aren't authors of the course are unable to export it """ _, nonstaff_user = self.create_non_staff_authed_user_client() - key = str(self.course.location.course_key) + key = str(self.course.usage_key.course_key) result = export_olx.delay(nonstaff_user.id, key, 'en') self._assert_failed(result, 'Permission denied') @@ -408,15 +408,15 @@ def test_scan_course_excludes_drag_and_drop(self, mock_modulestore, mock_get_blo """ vertical = BlockFactory.create( category='vertical', - parent_location=self.test_course.location + parent_location=self.test_course.usage_key ) drag_and_drop_block = BlockFactory.create( category='drag-and-drop-v2', - parent_location=vertical.location, + parent_location=vertical.usage_key, ) text_block = BlockFactory.create( category='html', - parent_location=vertical.location, + parent_location=vertical.usage_key, data='Test Link -> Example.com' ) diff --git a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py index 9163ff1ffc75..1779cc298bbc 100644 --- a/cms/djangoapps/contentstore/tests/test_transcripts_utils.py +++ b/cms/djangoapps/contentstore/tests/test_transcripts_utils.py @@ -723,10 +723,10 @@ def setUp(self): self.sjson_mime_type = transcripts_utils.Transcript.mime_types[transcripts_utils.Transcript.SJSON] self.user = UserFactory.create() - self.vertical = BlockFactory.create(category='vertical', parent_location=self.course.location) + self.vertical = BlockFactory.create(category='vertical', parent_location=self.course.usage_key) self.video = BlockFactory.create( category='video', - parent_location=self.vertical.location, + parent_location=self.vertical.usage_key, edx_video_id='1234-5678-90' ) @@ -741,7 +741,7 @@ def create_transcript(self, subs_id, language='en', filename='video.srt', youtub html5_sources = html5_sources or [] self.video = BlockFactory.create( category='video', - parent_location=self.vertical.location, + parent_location=self.vertical.usage_key, sub=subs_id, youtube_id_1_0=youtube_id_1_0, transcripts=transcripts, @@ -857,7 +857,7 @@ def test_get_transcript_from_contentstore( Verify that `get_transcript` function returns correct data when transcript is in content store. """ base_filename = 'video_101.srt' - self.upload_file(self.create_srt_file(self.subs_srt.encode('utf-8')), self.video.location, base_filename) + self.upload_file(self.create_srt_file(self.subs_srt.encode('utf-8')), self.video.usage_key, base_filename) self.create_transcript(subs_id, language, base_filename, youtube_id_1_0, html5_sources) content, file_name, mimetype = transcripts_utils.get_transcript( self.video, @@ -919,7 +919,7 @@ def test_get_transcript_no_content(self): """ Verify that `get_transcript` function returns correct exception when transcript content is empty. """ - self.upload_file(self.create_srt_file(b''), self.video.location, 'ur_video_101.srt') + self.upload_file(self.create_srt_file(b''), self.video.usage_key, 'ur_video_101.srt') self.create_transcript('', 'ur', 'ur_video_101.srt') with self.assertRaises(NotFoundError) as no_content_exception: diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index 48e0c425cec7..d95cffd71417 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -174,12 +174,12 @@ def _create_xblock_with_start_date(self, name, start_date, publish=False, visibl """Helper to create an xblock with a start date, optionally publishing it""" vertical = modulestore().create_item( - self.dummy_user, self.course.location.course_key, 'vertical', name, + self.dummy_user, self.course.usage_key.course_key, 'vertical', name, fields={'start': start_date, 'visible_to_staff_only': visible_to_staff_only} ) if publish: - modulestore().publish(vertical.location, self.dummy_user) + modulestore().publish(vertical.usage_key, self.dummy_user) return vertical @@ -190,14 +190,14 @@ class ReleaseDateSourceTest(CourseTestCase): def setUp(self): super().setUp() - self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.location) - self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.location) - self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.location) + self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.usage_key) + self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.usage_key) + self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.usage_key) # Read again so that children lists are accurate - self.chapter = self.store.get_item(self.chapter.location) - self.sequential = self.store.get_item(self.sequential.location) - self.vertical = self.store.get_item(self.vertical.location) + self.chapter = self.store.get_item(self.chapter.usage_key) + self.sequential = self.store.get_item(self.sequential.usage_key) + self.vertical = self.store.get_item(self.vertical.usage_key) self.date_one = datetime(1980, 1, 1, tzinfo=UTC) self.date_two = datetime(2020, 1, 1, tzinfo=UTC) @@ -214,7 +214,7 @@ def _update_release_dates(self, chapter_start, sequential_start, vertical_start) def _verify_release_date_source(self, item, expected_source): """Helper to verify that the release date source of a given item matches the expected source""" source = utils.find_release_date_source(item) - self.assertEqual(source.location, expected_source.location) + self.assertEqual(source.usage_key, expected_source.usage_key) self.assertEqual(source.start, expected_source.start) def test_chapter_source_for_vertical(self): @@ -244,18 +244,18 @@ class StaffLockTest(CourseTestCase): def setUp(self): super().setUp() - self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.location) - self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.location) - self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.location) - self.orphan = BlockFactory.create(category='vertical', parent_location=self.sequential.location) + self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.usage_key) + self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.usage_key) + self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.usage_key) + self.orphan = BlockFactory.create(category='vertical', parent_location=self.sequential.usage_key) # Read again so that children lists are accurate - self.chapter = self.store.get_item(self.chapter.location) - self.sequential = self.store.get_item(self.sequential.location) - self.vertical = self.store.get_item(self.vertical.location) + self.chapter = self.store.get_item(self.chapter.usage_key) + self.sequential = self.store.get_item(self.sequential.usage_key) + self.vertical = self.store.get_item(self.vertical.usage_key) # Orphan the orphaned xblock - self.sequential.children = [self.vertical.location] + self.sequential.children = [self.vertical.usage_key] self.sequential = self.store.update_item(self.sequential, ModuleStoreEnum.UserID.test) def _set_staff_lock(self, xblock, is_locked): @@ -283,7 +283,7 @@ class StaffLockSourceTest(StaffLockTest): def _verify_staff_lock_source(self, item, expected_source): """Helper to verify that the staff lock source of a given item matches the expected source""" source = utils.find_staff_lock_source(item) - self.assertEqual(source.location, expected_source.location) + self.assertEqual(source.usage_key, expected_source.usage_key) self.assertTrue(source.visible_to_staff_only) def test_chapter_source_for_vertical(self): @@ -362,10 +362,10 @@ def setUp(self): problem = BlockFactory.create( category='problem', parent=vertical, data="" ) - self.sequential = self.store.get_item(sequential.location) - self.vertical = self.store.get_item(vertical.location) - self.html = self.store.get_item(html.location) - self.problem = self.store.get_item(problem.location) + self.sequential = self.store.get_item(sequential.usage_key) + self.vertical = self.store.get_item(vertical.usage_key) + self.html = self.store.get_item(html.usage_key) + self.problem = self.store.get_item(problem.usage_key) # Add partitions to the course self.course.user_partitions = [ @@ -433,9 +433,9 @@ def test_sequential_and_problem_have_group_access(self): self.set_group_access(self.vertical, {1: []}) self.set_group_access(self.problem, {2: [3, 4]}) # get updated sequential/vertical/problem - self.sequential = self.store.get_item(self.sequential.location) - self.vertical = self.store.get_item(self.vertical.location) - self.problem = self.store.get_item(self.problem.location) + self.sequential = self.store.get_item(self.sequential.usage_key) + self.vertical = self.store.get_item(self.vertical.usage_key) + self.problem = self.store.get_item(self.problem.usage_key) # Note that "has_children_visible_to_specific_partition_groups" only checks immediate children. self.assertFalse(utils.has_children_visible_to_specific_partition_groups(self.sequential)) @@ -459,7 +459,7 @@ def setUp(self): """Create a dummy course. """ super().setUp() self.course = CourseFactory() - self.block = BlockFactory.create(category="problem", parent_location=self.course.location) + self.block = BlockFactory.create(category="problem", parent_location=self.course.usage_key) # Set up some default partitions self._set_partitions([ diff --git a/cms/djangoapps/contentstore/tests/test_xblock_handler_permissions.py b/cms/djangoapps/contentstore/tests/test_xblock_handler_permissions.py index 84a5b51895a5..96e306aaaaac 100644 --- a/cms/djangoapps/contentstore/tests/test_xblock_handler_permissions.py +++ b/cms/djangoapps/contentstore/tests/test_xblock_handler_permissions.py @@ -17,93 +17,93 @@ class XBlockHandlerPermissionsTest(CourseTestCase): def setUp(self): super().setUp() - self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.location) - self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.location) - self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.location) - self.html_block = BlockFactory.create(category='html', parent_location=self.vertical.location) - self.static_tab = BlockFactory.create(category='static_tab', parent_location=self.course.location) + self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.usage_key) + self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.usage_key) + self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.usage_key) + self.html_block = BlockFactory.create(category='html', parent_location=self.vertical.usage_key) + self.static_tab = BlockFactory.create(category='static_tab', parent_location=self.course.usage_key) self.non_staff_client, _ = self.create_non_staff_authed_user_client() # --- GET /xblock/{blockId} --- def test_get_block_fields_staff_allowed(self): - self.assertEqual(self.client.get_json(f'/xblock/{self.html_block.location}').status_code, 200) + self.assertEqual(self.client.get_json(f'/xblock/{self.html_block.usage_key}').status_code, 200) def test_get_block_fields_non_staff_forbidden(self): - self.assertEqual(self.non_staff_client.get_json(f'/xblock/{self.html_block.location}').status_code, 403) + self.assertEqual(self.non_staff_client.get_json(f'/xblock/{self.html_block.usage_key}').status_code, 403) # --- POST /xblock/{blockId} metadata --- def test_post_metadata_staff_allowed(self): resp = self.client.ajax_post( - f'/xblock/{self.html_block.location}', data={'metadata': {'display_name': 'New Name'}} + f'/xblock/{self.html_block.usage_key}', data={'metadata': {'display_name': 'New Name'}} ) self.assertEqual(resp.status_code, 200) def test_post_metadata_non_staff_forbidden(self): resp = self.non_staff_client.ajax_post( - f'/xblock/{self.html_block.location}', data={'metadata': {'display_name': 'New Name'}} + f'/xblock/{self.html_block.usage_key}', data={'metadata': {'display_name': 'New Name'}} ) self.assertEqual(resp.status_code, 403) # --- POST /xblock/{blockId} publish --- def test_publish_staff_allowed(self): - resp = self.client.ajax_post(f'/xblock/{self.vertical.location}', data={'publish': 'make_public'}) + resp = self.client.ajax_post(f'/xblock/{self.vertical.usage_key}', data={'publish': 'make_public'}) self.assertEqual(resp.status_code, 200) def test_publish_non_staff_forbidden(self): - resp = self.non_staff_client.ajax_post(f'/xblock/{self.vertical.location}', data={'publish': 'make_public'}) + resp = self.non_staff_client.ajax_post(f'/xblock/{self.vertical.usage_key}', data={'publish': 'make_public'}) self.assertEqual(resp.status_code, 403) # --- DELETE /xblock/{blockId} --- def test_delete_block_staff_allowed(self): - resp = self.client.delete(f'/xblock/{self.html_block.location}', HTTP_ACCEPT='application/json') + resp = self.client.delete(f'/xblock/{self.html_block.usage_key}', HTTP_ACCEPT='application/json') self.assertEqual(resp.status_code, 204) def test_delete_block_non_staff_forbidden(self): - resp = self.non_staff_client.delete(f'/xblock/{self.html_block.location}', HTTP_ACCEPT='application/json') + resp = self.non_staff_client.delete(f'/xblock/{self.html_block.usage_key}', HTTP_ACCEPT='application/json') self.assertEqual(resp.status_code, 403) # --- POST /xblock/ (create/duplicate) --- def test_post_duplicate_staff_allowed(self): data = { - 'duplicate_source_locator': str(self.html_block.location), - 'parent_locator': str(self.vertical.location), + 'duplicate_source_locator': str(self.html_block.usage_key), + 'parent_locator': str(self.vertical.usage_key), } self.assertEqual(self.client.ajax_post('/xblock/', data=data).status_code, 200) def test_post_duplicate_non_staff_forbidden(self): data = { - 'duplicate_source_locator': str(self.html_block.location), - 'parent_locator': str(self.vertical.location), + 'duplicate_source_locator': str(self.html_block.usage_key), + 'parent_locator': str(self.vertical.usage_key), } self.assertEqual(self.non_staff_client.ajax_post('/xblock/', data=data).status_code, 403) def test_post_add_component_staff_allowed(self): - data = {'category': 'html', 'parent_locator': str(self.vertical.location)} + data = {'category': 'html', 'parent_locator': str(self.vertical.usage_key)} self.assertEqual(self.client.ajax_post('/xblock/', data=data).status_code, 200) def test_post_add_component_non_staff_forbidden(self): - data = {'category': 'html', 'parent_locator': str(self.vertical.location)} + data = {'category': 'html', 'parent_locator': str(self.vertical.usage_key)} self.assertEqual(self.non_staff_client.ajax_post('/xblock/', data=data).status_code, 403) # --- PUT /xblock/{blockId} (reorder) --- def test_put_reorder_staff_allowed(self): - data={'children': [str(self.html_block.location)]} + data={'children': [str(self.html_block.usage_key)]} resp = self.client.put( - f'/xblock/{self.vertical.location}', data=data, + f'/xblock/{self.vertical.usage_key}', data=data, content_type='application/json', HTTP_ACCEPT='application/json', ) self.assertEqual(resp.status_code, 200) def test_put_reorder_non_staff_forbidden(self): - data={'children': [str(self.html_block.location)]} + data={'children': [str(self.html_block.usage_key)]} resp = self.non_staff_client.put( - f'/xblock/{self.vertical.location}', data=data, + f'/xblock/{self.vertical.usage_key}', data=data, content_type='application/json', HTTP_ACCEPT='application/json', ) self.assertEqual(resp.status_code, 403) @@ -111,10 +111,10 @@ def test_put_reorder_non_staff_forbidden(self): # --- PATCH /xblock/ (move) --- def test_patch_move_component_staff_allowed(self): - vertical2 = BlockFactory.create(category='vertical', parent_location=self.sequential.location) + vertical2 = BlockFactory.create(category='vertical', parent_location=self.sequential.usage_key) data={ - 'move_source_locator': str(self.html_block.location), - 'parent_locator': str(vertical2.location), + 'move_source_locator': str(self.html_block.usage_key), + 'parent_locator': str(vertical2.usage_key), } resp = self.client.patch( '/xblock/', data=data, content_type='application/json', HTTP_ACCEPT='application/json', @@ -123,8 +123,8 @@ def test_patch_move_component_staff_allowed(self): def test_patch_move_component_non_staff_forbidden(self): data={ - 'move_source_locator': str(self.html_block.location), - 'parent_locator': str(self.vertical.location), + 'move_source_locator': str(self.html_block.usage_key), + 'parent_locator': str(self.vertical.usage_key), } resp = self.non_staff_client.patch( '/xblock/', data=data, content_type='application/json', HTTP_ACCEPT='application/json', @@ -136,7 +136,7 @@ def test_patch_move_component_non_staff_forbidden(self): def test_put_update_custom_page_staff_allowed(self): data={'metadata': {'display_name': 'Updated Page'}} resp = self.client.put( - f'/xblock/{self.static_tab.location}', data=data, + f'/xblock/{self.static_tab.usage_key}', data=data, content_type='application/json', HTTP_ACCEPT='application/json', ) self.assertEqual(resp.status_code, 200) @@ -144,38 +144,38 @@ def test_put_update_custom_page_staff_allowed(self): def test_put_update_custom_page_non_staff_forbidden(self): data={'metadata': {'display_name': 'Updated Page'}} resp = self.non_staff_client.put( - f'/xblock/{self.static_tab.location}', data=data, + f'/xblock/{self.static_tab.usage_key}', data=data, content_type='application/json', HTTP_ACCEPT='application/json', ) self.assertEqual(resp.status_code, 403) def test_delete_custom_page_staff_allowed(self): - resp = self.client.delete(f'/xblock/{self.static_tab.location}', HTTP_ACCEPT='application/json') + resp = self.client.delete(f'/xblock/{self.static_tab.usage_key}', HTTP_ACCEPT='application/json') self.assertEqual(resp.status_code, 204) def test_delete_custom_page_non_staff_forbidden(self): - resp = self.non_staff_client.delete(f'/xblock/{self.static_tab.location}', HTTP_ACCEPT='application/json') + resp = self.non_staff_client.delete(f'/xblock/{self.static_tab.usage_key}', HTTP_ACCEPT='application/json') self.assertEqual(resp.status_code, 403) def test_post_static_tab_content_staff_allowed(self): resp = self.client.ajax_post( - f'/xblock/{self.static_tab.location}', data={'data': '

Content

', 'metadata': {'display_name': 'Page'}} + f'/xblock/{self.static_tab.usage_key}', data={'data': '

Content

', 'metadata': {'display_name': 'Page'}} ) self.assertEqual(resp.status_code, 200) def test_post_static_tab_content_non_staff_forbidden(self): resp = self.non_staff_client.ajax_post( - f'/xblock/{self.static_tab.location}', data={'data': '

Content

', 'metadata': {'display_name': 'Page'}} + f'/xblock/{self.static_tab.usage_key}', data={'data': '

Content

', 'metadata': {'display_name': 'Page'}} ) self.assertEqual(resp.status_code, 403) def test_get_handouts_staff_allowed(self): - handouts = BlockFactory.create(category='course_info', parent_location=self.course.location) - self.assertEqual(self.client.get_json(f'/xblock/{handouts.location}').status_code, 200) + handouts = BlockFactory.create(category='course_info', parent_location=self.course.usage_key) + self.assertEqual(self.client.get_json(f'/xblock/{handouts.usage_key}').status_code, 200) def test_get_handouts_non_staff_forbidden(self): - handouts = BlockFactory.create(category='course_info', parent_location=self.course.location) - self.assertEqual(self.non_staff_client.get_json(f'/xblock/{handouts.location}').status_code, 403) + handouts = BlockFactory.create(category='course_info', parent_location=self.course.usage_key) + self.assertEqual(self.non_staff_client.get_json(f'/xblock/{handouts.usage_key}').status_code, 403) @patch('cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers.authz_api.is_user_allowed', return_value=True) @@ -190,18 +190,18 @@ class XBlockHandlerAuthzPermissionsTest(CourseTestCase): def setUp(self): super().setUp() - self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.location) - self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.location) - self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.location) - self.html_block = BlockFactory.create(category='html', parent_location=self.vertical.location) - self.static_tab = BlockFactory.create(category='static_tab', parent_location=self.course.location) - self.course_info = BlockFactory.create(category='course_info', parent_location=self.course.location) + self.chapter = BlockFactory.create(category='chapter', parent_location=self.course.usage_key) + self.sequential = BlockFactory.create(category='sequential', parent_location=self.chapter.usage_key) + self.vertical = BlockFactory.create(category='vertical', parent_location=self.sequential.usage_key) + self.html_block = BlockFactory.create(category='html', parent_location=self.vertical.usage_key) + self.static_tab = BlockFactory.create(category='static_tab', parent_location=self.course.usage_key) + self.course_info = BlockFactory.create(category='course_info', parent_location=self.course.usage_key) # --- GET /xblock/{blockId} --- def test_get_regular_block_checks_view_course(self, _mock_flag, mock_is_allowed): """GET on regular block should check courses.view_course permission""" - self.client.get_json(f'/xblock/{self.html_block.location}') + self.client.get_json(f'/xblock/{self.html_block.usage_key}') mock_is_allowed.assert_called_with( self.user.username, 'courses.view_course', @@ -210,7 +210,7 @@ def test_get_regular_block_checks_view_course(self, _mock_flag, mock_is_allowed) def test_get_course_info_checks_view_course_updates(self, _mock_flag, mock_is_allowed): """GET on course_info block should check courses.view_course_updates permission""" - self.client.get_json(f'/xblock/{self.course_info.location}') + self.client.get_json(f'/xblock/{self.course_info.usage_key}') mock_is_allowed.assert_called_with( self.user.username, 'courses.view_course_updates', @@ -219,7 +219,7 @@ def test_get_course_info_checks_view_course_updates(self, _mock_flag, mock_is_al def test_get_static_tab_checks_view_course(self, _mock_flag, mock_is_allowed): """GET on static_tab should check courses.view_course""" - self.client.get_json(f'/xblock/{self.static_tab.location}') + self.client.get_json(f'/xblock/{self.static_tab.usage_key}') mock_is_allowed.assert_called_with( self.user.username, 'courses.view_course', @@ -230,7 +230,7 @@ def test_get_static_tab_checks_view_course(self, _mock_flag, mock_is_allowed): def test_post_regular_block_checks_edit_course_content(self, _mock_flag, mock_is_allowed): """POST on regular block without publish should check courses.edit_course_content""" - self.client.ajax_post(f'/xblock/{self.html_block.location}', data={'metadata': {'display_name': 'New'}}) + self.client.ajax_post(f'/xblock/{self.html_block.usage_key}', data={'metadata': {'display_name': 'New'}}) mock_is_allowed.assert_called_with( self.user.username, 'courses.edit_course_content', @@ -240,7 +240,7 @@ def test_post_regular_block_checks_edit_course_content(self, _mock_flag, mock_is def test_post_with_publish_none_and_metadata_checks_edit(self, _mock_flag, mock_is_allowed): """POST with publish=None + metadata should check courses.edit_course_content""" self.client.ajax_post( - f'/xblock/{self.vertical.location}', + f'/xblock/{self.vertical.usage_key}', data={'publish': None, 'metadata': {'visible_to_staff_only': True}} ) mock_is_allowed.assert_called_with( @@ -253,7 +253,7 @@ def test_post_with_publish_none_and_metadata_checks_edit(self, _mock_flag, mock_ def test_post_with_publish_checks_publish_course_content(self, _mock_flag, mock_is_allowed): """POST with publish='make_public' should check courses.publish_course_content""" - self.client.ajax_post(f'/xblock/{self.vertical.location}', data={'publish': 'make_public'}) + self.client.ajax_post(f'/xblock/{self.vertical.usage_key}', data={'publish': 'make_public'}) mock_is_allowed.assert_called_with( self.user.username, 'courses.publish_course_content', @@ -262,7 +262,7 @@ def test_post_with_publish_checks_publish_course_content(self, _mock_flag, mock_ def test_post_discard_changes_checks_publish(self, _mock_flag, mock_is_allowed): """POST with publish='discard_changes' should check courses.publish_course_content""" - self.client.ajax_post(f'/xblock/{self.vertical.location}', data={'publish': 'discard_changes'}) + self.client.ajax_post(f'/xblock/{self.vertical.usage_key}', data={'publish': 'discard_changes'}) mock_is_allowed.assert_called_with( self.user.username, 'courses.publish_course_content', @@ -271,7 +271,7 @@ def test_post_discard_changes_checks_publish(self, _mock_flag, mock_is_allowed): def test_post_republish_without_changes_checks_publish(self, _mock_flag, mock_is_allowed): """POST with publish='republish' and no content changes should check courses.publish_course_content""" - self.client.ajax_post(f'/xblock/{self.vertical.location}', data={'publish': 'republish'}) + self.client.ajax_post(f'/xblock/{self.vertical.usage_key}', data={'publish': 'republish'}) mock_is_allowed.assert_called_with( self.user.username, 'courses.publish_course_content', @@ -281,7 +281,7 @@ def test_post_republish_without_changes_checks_publish(self, _mock_flag, mock_is def test_post_make_public_with_content_changes_checks_edit(self, _mock_flag, mock_is_allowed): """POST with publish='make_public' + metadata should check courses.edit_course_content""" self.client.ajax_post( - f'/xblock/{self.vertical.location}', + f'/xblock/{self.vertical.usage_key}', data={'publish': 'make_public', 'metadata': {'display_name': 'New'}} ) mock_is_allowed.assert_called_with( @@ -293,7 +293,7 @@ def test_post_make_public_with_content_changes_checks_edit(self, _mock_flag, moc def test_post_republish_with_metadata_checks_edit(self, _mock_flag, mock_is_allowed): """POST with publish='republish' + metadata changes should check courses.edit_course_content""" self.client.ajax_post( - f'/xblock/{self.chapter.location}', + f'/xblock/{self.chapter.usage_key}', data={'publish': 'republish', 'metadata': {'highlights': ['Week 1']}} ) mock_is_allowed.assert_called_with( @@ -305,7 +305,7 @@ def test_post_republish_with_metadata_checks_edit(self, _mock_flag, mock_is_allo def test_post_republish_with_grader_type_checks_edit(self, _mock_flag, mock_is_allowed): """POST with publish='republish' + graderType should check courses.edit_course_content""" self.client.ajax_post( - f'/xblock/{self.sequential.location}', + f'/xblock/{self.sequential.usage_key}', data={'publish': 'republish', 'graderType': 'Homework', 'prereqMinScore': 100} ) mock_is_allowed.assert_called_with( @@ -318,7 +318,7 @@ def test_post_republish_with_grader_type_checks_edit(self, _mock_flag, mock_is_a def test_delete_regular_block_checks_edit_course_content(self, _mock_flag, mock_is_allowed): """DELETE on regular block should check courses.edit_course_content""" - self.client.delete(f'/xblock/{self.html_block.location}', HTTP_ACCEPT='application/json') + self.client.delete(f'/xblock/{self.html_block.usage_key}', HTTP_ACCEPT='application/json') mock_is_allowed.assert_called_with( self.user.username, 'courses.edit_course_content', @@ -327,7 +327,7 @@ def test_delete_regular_block_checks_edit_course_content(self, _mock_flag, mock_ def test_delete_static_tab_checks_manage_pages_and_resources(self, _mock_flag, mock_is_allowed): """DELETE on static_tab should check courses.manage_pages_and_resources""" - self.client.delete(f'/xblock/{self.static_tab.location}', HTTP_ACCEPT='application/json') + self.client.delete(f'/xblock/{self.static_tab.usage_key}', HTTP_ACCEPT='application/json') mock_is_allowed.assert_called_with( self.user.username, 'courses.manage_pages_and_resources', @@ -338,7 +338,7 @@ def test_delete_static_tab_checks_manage_pages_and_resources(self, _mock_flag, m def test_create_block_checks_edit_course_content(self, _mock_flag, mock_is_allowed): """POST /xblock/ to create block should check courses.edit_course_content""" - self.client.ajax_post('/xblock/', data={'category': 'html', 'parent_locator': str(self.vertical.location)}) + self.client.ajax_post('/xblock/', data={'category': 'html', 'parent_locator': str(self.vertical.usage_key)}) mock_is_allowed.assert_called_with( self.user.username, 'courses.edit_course_content', @@ -349,7 +349,7 @@ def test_create_static_tab_checks_manage_pages_and_resources(self, _mock_flag, m """PUT /xblock/ to create static_tab should check courses.manage_pages_and_resources""" self.client.put( '/xblock/', - data={'category': 'static_tab', 'parent_locator': str(self.course.location)}, + data={'category': 'static_tab', 'parent_locator': str(self.course.usage_key)}, content_type='application/json', HTTP_ACCEPT='application/json', ) mock_is_allowed.assert_called_with( @@ -363,8 +363,8 @@ def test_duplicate_block_checks_edit_course_content(self, _mock_flag, mock_is_al self.client.ajax_post( '/xblock/', data={ - 'duplicate_source_locator': str(self.html_block.location), - 'parent_locator': str(self.vertical.location), + 'duplicate_source_locator': str(self.html_block.usage_key), + 'parent_locator': str(self.vertical.usage_key), } ) mock_is_allowed.assert_called_with( @@ -378,8 +378,8 @@ def test_duplicate_block_checks_edit_course_content(self, _mock_flag, mock_is_al def test_put_reorder_checks_edit_course_content(self, _mock_flag, mock_is_allowed): """PUT on regular block (reorder children) should check courses.edit_course_content""" self.client.put( - f'/xblock/{self.vertical.location}', - data={'children': [str(self.html_block.location)]}, + f'/xblock/{self.vertical.usage_key}', + data={'children': [str(self.html_block.usage_key)]}, content_type='application/json', HTTP_ACCEPT='application/json', ) mock_is_allowed.assert_called_with( @@ -392,12 +392,12 @@ def test_put_reorder_checks_edit_course_content(self, _mock_flag, mock_is_allowe def test_move_block_checks_edit_course_content(self, _mock_flag, mock_is_allowed): """PATCH /xblock/ to move should check courses.edit_course_content""" - vertical2 = BlockFactory.create(category='vertical', parent_location=self.sequential.location) + vertical2 = BlockFactory.create(category='vertical', parent_location=self.sequential.usage_key) self.client.patch( '/xblock/', data={ - 'move_source_locator': str(self.html_block.location), - 'parent_locator': str(vertical2.location), + 'move_source_locator': str(self.html_block.usage_key), + 'parent_locator': str(vertical2.usage_key), }, content_type='application/json', HTTP_ACCEPT='application/json', @@ -412,7 +412,7 @@ def test_move_block_checks_edit_course_content(self, _mock_flag, mock_is_allowed def test_post_static_tab_checks_manage_pages_and_resources(self, _mock_flag, mock_is_allowed): """POST on static_tab should check courses.manage_pages_and_resources""" - self.client.ajax_post(f'/xblock/{self.static_tab.location}', data={'metadata': {'display_name': 'Updated'}}) + self.client.ajax_post(f'/xblock/{self.static_tab.usage_key}', data={'metadata': {'display_name': 'Updated'}}) mock_is_allowed.assert_called_with( self.user.username, 'courses.manage_pages_and_resources', @@ -422,7 +422,7 @@ def test_post_static_tab_checks_manage_pages_and_resources(self, _mock_flag, moc def test_put_static_tab_checks_manage_pages_and_resources(self, _mock_flag, mock_is_allowed): """PUT on static_tab should check courses.manage_pages_and_resources""" self.client.put( - f'/xblock/{self.static_tab.location}', + f'/xblock/{self.static_tab.usage_key}', data={'metadata': {'display_name': 'Updated'}}, content_type='application/json', HTTP_ACCEPT='application/json', ) @@ -434,7 +434,7 @@ def test_put_static_tab_checks_manage_pages_and_resources(self, _mock_flag, mock def test_post_course_info_checks_manage_course_updates(self, _mock_flag, mock_is_allowed): """POST on course_info block should check courses.manage_course_updates""" - self.client.ajax_post(f'/xblock/{self.course_info.location}', data={'data': '

Updated

'}) + self.client.ajax_post(f'/xblock/{self.course_info.usage_key}', data={'data': '

Updated

'}) mock_is_allowed.assert_called_with( self.user.username, 'courses.manage_course_updates', @@ -444,7 +444,7 @@ def test_post_course_info_checks_manage_course_updates(self, _mock_flag, mock_is def test_put_course_info_checks_manage_course_updates(self, _mock_flag, mock_is_allowed): """PUT on course_info should check courses.manage_course_updates""" self.client.put( - f'/xblock/{self.course_info.location}', + f'/xblock/{self.course_info.usage_key}', data={'data': '

Updated

'}, content_type='application/json', HTTP_ACCEPT='application/json', @@ -460,11 +460,11 @@ def test_put_course_info_checks_manage_course_updates(self, _mock_flag, mock_is_ def test_authz_denied_raises_permission_denied(self, _mock_flag, mock_is_allowed): """When authz denies permission, PermissionDenied should be raised""" mock_is_allowed.return_value = False - response = self.client.get_json(f'/xblock/{self.html_block.location}') + response = self.client.get_json(f'/xblock/{self.html_block.usage_key}') self.assertEqual(response.status_code, 403) def test_authz_flag_disabled_uses_legacy_permissions(self, _mock_flag, mock_is_allowed): """When authz flag is disabled, should use legacy permission checks""" with patch.object(core_toggles.AUTHZ_COURSE_AUTHORING_FLAG, 'is_enabled', return_value=False): - self.client.get_json(f'/xblock/{self.html_block.location}') + self.client.get_json(f'/xblock/{self.html_block.usage_key}') mock_is_allowed.assert_not_called() diff --git a/cms/djangoapps/contentstore/tests/utils.py b/cms/djangoapps/contentstore/tests/utils.py index 42f57563c292..5a20aeb0d894 100644 --- a/cms/djangoapps/contentstore/tests/utils.py +++ b/cms/djangoapps/contentstore/tests/utils.py @@ -133,8 +133,8 @@ def assertCoursesEqual(self, course1_id, course2_id): course2_items = self.store.get_items(course2_id) self.assertGreater(len(course1_items), 0) # ensure it found content instead of [] == [] if len(course1_items) != len(course2_items): - course1_block_ids = {item.location.block_id for item in course1_items} - course2_block_ids = {item.location.block_id for item in course2_items} + course1_block_ids = {item.usage_key.block_id for item in course1_items} + course2_block_ids = {item.usage_key.block_id for item in course2_items} raise AssertionError( "Course1 extra blocks: {}; course2 extra blocks: {}".format( course1_block_ids - course2_block_ids, course2_block_ids - course1_block_ids @@ -142,7 +142,7 @@ def assertCoursesEqual(self, course1_id, course2_id): ) for course1_item in course1_items: - course1_item_loc = course1_item.location + course1_item_loc = course1_item.usage_key course2_item_loc = course2_id.make_usage_key(course1_item_loc.block_type, course1_item_loc.block_id) if course1_item_loc.block_type == 'course': # mongo uses the run as the name, split uses 'course' @@ -194,7 +194,7 @@ def check_verticals(self, items): # assert is here to make sure that the course being tested actually has verticals (units) to check. self.assertGreater(len(items), 0, "Course has no verticals (units) to check") for block in items: - resp = self.client.get_html(get_url('container_handler', block.location)) + resp = self.client.get_html(get_url('container_handler', block.usage_key)) self.assertEqual(resp.status_code, 200) def assertAssetsEqual(self, asset_son, course1_id, course2_id): diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index f40fad42152c..6cedf852e270 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -582,7 +582,7 @@ def is_currently_visible_to_students(xblock): """ try: - published = modulestore().get_item(xblock.location, revision=ModuleStoreEnum.RevisionOption.published_only) + published = modulestore().get_item(xblock.usage_key, revision=ModuleStoreEnum.RevisionOption.published_only) # If there's no published version then the xblock is clearly not visible except ItemNotFoundError: return False @@ -637,7 +637,7 @@ def find_release_date_source(xblock): if xblock.category == 'chapter': return xblock - parent_location = modulestore().get_parent_location(xblock.location, + parent_location = modulestore().get_parent_location(xblock.usage_key, revision=ModuleStoreEnum.RevisionOption.draft_preferred) # Orphaned xblocks set their own release date if not parent_location: @@ -664,7 +664,7 @@ def find_staff_lock_source(xblock): if xblock.category == 'chapter': return None - parent_location = modulestore().get_parent_location(xblock.location, + parent_location = modulestore().get_parent_location(xblock.usage_key, revision=ModuleStoreEnum.RevisionOption.draft_preferred) # Orphaned xblocks set their own staff lock if not parent_location: @@ -680,7 +680,7 @@ def ancestor_has_staff_lock(xblock, parent_xblock=None): Can avoid mongo query by passing in parent_xblock. """ if parent_xblock is None: - parent_location = modulestore().get_parent_location(xblock.location, + parent_location = modulestore().get_parent_location(xblock.usage_key, revision=ModuleStoreEnum.RevisionOption.draft_preferred) if not parent_location: return False @@ -692,7 +692,7 @@ def get_sequence_usage_keys(course): """ Extracts a list of 'subsections' usage_keys """ - return [str(subsection.location) + return [str(subsection.usage_key) for section in course.get_children() for subsection in section.get_children()] @@ -813,12 +813,12 @@ def get_user_partition_info(xblock, schemes=None, course=None): ] """ - course = course or modulestore().get_course(xblock.location.course_key) + course = course or modulestore().get_course(xblock.usage_key.course_key) if course is None: log.warning( "Could not find course %s to retrieve user partition information", - xblock.location.course_key + xblock.usage_key.course_key ) return [] @@ -990,8 +990,8 @@ def get_subsections_in_section(): return section_subsections except AttributeError: log.error("URL Retrieval Error: subsection {subsection} included in section {section}".format( - section=section.location, - subsection=subsection.location + section=section.usage_key, + subsection=subsection.usage_key )) return None @@ -1004,7 +1004,7 @@ def get_sections_in_course(): return section_subsections except AttributeError: log.error("URL Retrieval Error: In section {section} in course".format( - section=section.location, + section=section.usage_key, )) return None @@ -1013,16 +1013,16 @@ def get_subsection_location(section_subsections, current_subsection, direction): Returns the desired location of the adjacent subsections in a section. """ location = None - subsection_index = section_subsections.index(next(s for s in subsections if s.location == - current_subsection.location)) + subsection_index = section_subsections.index(next(s for s in subsections if s.usage_key == + current_subsection.usage_key)) try: if direction == 'previous': if subsection_index > 0: prev_subsection = subsections[subsection_index - 1] - location = prev_subsection.get_children()[-1].location + location = prev_subsection.get_children()[-1].usage_key else: next_subsection = subsections[subsection_index + 1] - location = next_subsection.get_children()[0].location + location = next_subsection.get_children()[0].usage_key return location except IndexError: return None @@ -1032,15 +1032,15 @@ def get_section_location(course_sections, current_section, direction): Returns the desired location of the adjacent sections in a course. """ location = None - section_index = course_sections.index(next(s for s in sections if s.location == current_section.location)) + section_index = course_sections.index(next(s for s in sections if s.usage_key == current_section.usage_key)) try: if direction == 'previous': if section_index > 0: prev_section = sections[section_index - 1] - location = prev_section.get_children()[-1].get_children()[-1].location + location = prev_section.get_children()[-1].get_children()[-1].usage_key else: next_section = sections[section_index + 1] - location = next_section.get_children()[0].get_children()[0].location + location = next_section.get_children()[0].get_children()[0].usage_key return location except IndexError: return None @@ -1161,7 +1161,7 @@ def duplicate_block( source_item = store.get_item(duplicate_source_usage_key) if not dest_usage_key: # Change the blockID to be unique. - dest_usage_key = source_item.location.replace(name=uuid4().hex) + dest_usage_key = source_item.usage_key.replace(name=uuid4().hex) category = dest_usage_key.block_type @@ -1194,7 +1194,7 @@ def duplicate_block( if source_item.has_children and not shallow and not children_handled: dest_block.children = dest_block.children or [] for child in source_item.children: - dupe = duplicate_block(dest_block.location, child, user=user, is_child=True) + dupe = duplicate_block(dest_block.usage_key, child, user=user, is_child=True) if dupe not in dest_block.children: # _duplicate_block may add the child for us. dest_block.children.append(dupe) store.update_item(dest_block, user.id) @@ -1204,11 +1204,11 @@ def duplicate_block( parent = store.get_item(parent_usage_key) # If source was already a child of the parent, add duplicate immediately afterward. # Otherwise, add child to end. - if source_item.location in parent.children: - source_index = parent.children.index(source_item.location) - parent.children.insert(source_index + 1, dest_block.location) + if source_item.usage_key in parent.children: + source_index = parent.children.index(source_item.usage_key) + parent.children.insert(source_index + 1, dest_block.usage_key) else: - parent.children.append(dest_block.location) + parent.children.append(dest_block.usage_key) store.update_item(parent, user.id) # .. event_implemented_name: XBLOCK_DUPLICATED @@ -1216,13 +1216,13 @@ def duplicate_block( XBLOCK_DUPLICATED.send_event( time=datetime.now(timezone.utc), xblock_info=DuplicatedXBlockData( - usage_key=dest_block.location, - block_type=dest_block.location.block_type, + usage_key=dest_block.usage_key, + block_type=dest_block.usage_key.block_type, source_usage_key=duplicate_source_usage_key, ) ) - return dest_block.location + return dest_block.usage_key def update_from_source(*, source_block, destination_block, user_id): @@ -1415,17 +1415,17 @@ def get_course_settings(request, course_key, course_block): # see if the ORG of this course can be attributed to a defined configuration . In that case, the # course about page should be editable in Studio publisher_enabled = configuration_helpers.get_value_for_org( - course_block.location.org, + course_block.usage_key.org, 'ENABLE_PUBLISHER', settings.FEATURES.get('ENABLE_PUBLISHER', False) ) marketing_enabled = configuration_helpers.get_value_for_org( - course_block.location.org, + course_block.usage_key.org, 'ENABLE_MKTG_SITE', settings.FEATURES.get('ENABLE_MKTG_SITE', False) ) enable_extended_course_details = configuration_helpers.get_value_for_org( - course_block.location.org, + course_block.usage_key.org, 'ENABLE_EXTENDED_COURSE_DETAILS', settings.FEATURES.get('ENABLE_EXTENDED_COURSE_DETAILS', False) ) @@ -1433,7 +1433,7 @@ def get_course_settings(request, course_key, course_block): about_page_editable = not publisher_enabled enrollment_end_editable = GlobalStaff().has_user(request.user) or not publisher_enabled short_description_editable = configuration_helpers.get_value_for_org( - course_block.location.org, + course_block.usage_key.org, 'EDITABLE_SHORT_DESCRIPTION', settings.FEATURES.get('EDITABLE_SHORT_DESCRIPTION', True) ) @@ -1908,7 +1908,7 @@ def _get_course_index_context(request, course_key, course_block): ) from openedx.core.djangoapps.content_staging import api as content_staging_api - lms_link = get_lms_link_for_item(course_block.location) + lms_link = get_lms_link_for_item(course_block.usage_key) reindex_link = None if settings.FEATURES.get('ENABLE_COURSEWARE_INDEX', False): if GlobalStaff().has_user(request.user): @@ -1934,7 +1934,7 @@ def _get_course_index_context(request, course_key, course_block): deprecated_blocks_info = _deprecated_blocks_info(course_block, deprecated_block_names) frontend_app_publisher_url = configuration_helpers.get_value_for_org( - course_block.location.org, + course_block.usage_key.org, 'FRONTEND_APP_PUBLISHER_URL', settings.FEATURES.get('FRONTEND_APP_PUBLISHER_URL', False) ) @@ -2039,14 +2039,14 @@ def get_container_handler_context(request, usage_key, course, xblock): # pylint subsection = get_parent_xblock(unit) if subsection is None: - raise ValueError(f"Could not determine parent subsection from unit {unit.location}") + raise ValueError(f"Could not determine parent subsection from unit {unit.usage_key}") section = get_parent_xblock(subsection) if section is None: - raise ValueError(f"Could not determine ancestor section from unit {unit.location}") + raise ValueError(f"Could not determine ancestor section from unit {unit.usage_key}") # for the sequence navigator - prev_url, next_url = get_sibling_urls(subsection, unit.location) + prev_url, next_url = get_sibling_urls(subsection, unit.usage_key) # these are quoted here because they'll end up in a query string on the page, # and quoting with mako will trigger the xss linter... prev_url = quote_plus(prev_url) if prev_url else None @@ -2068,21 +2068,21 @@ def get_container_handler_context(request, usage_key, course, xblock): # pylint # preview will need this index = 1 for child in subsection.get_children(): - if child.location == unit.location: + if child.usage_key == unit.usage_key: break index += 1 # Get the status of the user's clipboard so they can paste components if they have something to paste user_clipboard = content_staging_api.get_user_clipboard_json(request.user.id, request) library_block_types = [problem_type['component'] for problem_type in LIBRARY_BLOCK_TYPES] - is_library_xblock = xblock.location.block_type in library_block_types + is_library_xblock = xblock.usage_key.block_type in library_block_types context = { 'language_code': request.LANGUAGE_CODE, 'context_course': course, # Needed only for display of menus at top of page. 'action': action, 'xblock': xblock, - 'xblock_locator': xblock.location, + 'xblock_locator': xblock.usage_key, 'unit': unit, 'is_unit_page': is_unit_page, 'is_collapsible': is_library_xblock, @@ -2376,7 +2376,7 @@ def get_xblock_render_context(request, block): "reorderable_items": set(), "paging": None, "force_render": None, - "item_url": "/container/{block.location}", + "item_url": "/container/{block.usage_key}", "tags_count_map": {}, } diff --git a/cms/djangoapps/contentstore/video_storage_handlers.py b/cms/djangoapps/contentstore/video_storage_handlers.py index 46215ae90362..7b61957625c1 100644 --- a/cms/djangoapps/contentstore/video_storage_handlers.py +++ b/cms/djangoapps/contentstore/video_storage_handlers.py @@ -295,7 +295,7 @@ def get_video_usage_path(course_key, edx_video_id): try: if video_id == edx_video_id: usage_dict = {'display_location': '', 'url': ''} - video_location = str(video.location) + video_location = str(video.usage_key) xblock_display_name = getattr(video, 'display_name', '') unit = video.get_parent() unit_location = str(video.parent) diff --git a/cms/djangoapps/contentstore/views/block.py b/cms/djangoapps/contentstore/views/block.py index b57042085df2..83fa6c867ca1 100644 --- a/cms/djangoapps/contentstore/views/block.py +++ b/cms/djangoapps/contentstore/views/block.py @@ -222,7 +222,7 @@ def xblock_view_handler(request, usage_key_string, view_name): # added to the list. reorderable_items = set() if view_name == "reorderable_container_child_preview": - reorderable_items.add(xblock.location) + reorderable_items.add(xblock.usage_key) paging = None try: diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index 8b16fdbad80d..2be4873bb03c 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -163,10 +163,10 @@ def container_handler(request, usage_key_string): # pylint: disable=too-many-st if use_new_unit_page(course.id): if is_unit(xblock) or is_library_content(xblock): - return redirect(get_unit_url(course.id, xblock.location)) + return redirect(get_unit_url(course.id, xblock.usage_key)) if split_xblock := get_parent_if_split_test(xblock): - return redirect(get_unit_url(course.id, split_xblock.location)) + return redirect(get_unit_url(course.id, split_xblock.usage_key)) container_handler_context = get_container_handler_context(request, usage_key, course, xblock) container_handler_context.update({ @@ -310,7 +310,7 @@ def create_support_legend_dict(): component_types = _filter_disabled_blocks(component_types) # Filter out discussion component from component_types if non-legacy discussion provider is configured for course - component_types = _filter_discussion_for_non_legacy_provider(component_types, courselike.location.course_key) + component_types = _filter_discussion_for_non_legacy_provider(component_types, courselike.usage_key.course_key) # Content Libraries currently don't allow opting in to unsupported xblocks/problem types. allow_unsupported = getattr(courselike, "allow_unsupported_xblocks", False) @@ -549,8 +549,8 @@ def _get_item_in_course(request, usage_key): course = modulestore().get_course(course_key) item = modulestore().get_item(usage_key, depth=1) - lms_link = get_lms_link_for_item(item.location) - preview_lms_link = get_lms_link_for_item(item.location, preview=True) + lms_link = get_lms_link_for_item(item.usage_key) + preview_lms_link = get_lms_link_for_item(item.usage_key, preview=True) return course, item, lms_link, preview_lms_link diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 115aea1a83aa..3099c9c9b458 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -404,7 +404,7 @@ def course_filter(course_summary): Filter out unusable and inaccessible courses """ # TODO remove this condition when templates purged from db - if course_summary.location.course == 'templates': + if course_summary.usage_key.course == 'templates': return False return has_studio_read_access(request.user, course_summary.id) @@ -489,7 +489,7 @@ def course_filter(course): return False # TODO remove this condition when templates purged from db - if course.location.course == 'templates': + if course.usage_key.course == 'templates': return False return has_studio_read_access(request.user, course.id) @@ -517,7 +517,7 @@ def course_filter(course): return False # TODO remove this condition when templates purged from db - if course.location.course == 'templates': + if course.usage_key.course == 'templates': return False return has_studio_read_access(request.user, course.id) @@ -646,7 +646,7 @@ def _accessible_libraries_iter(user, org=None): else: libraries = modulestore().get_library_summaries() # No need to worry about ErrorBlocks - split's get_libraries() never returns them. - return (lib for lib in libraries if has_studio_read_access(user, lib.location.library_key)) + return (lib for lib in libraries if has_studio_read_access(user, lib.usage_key.library_key)) @login_required @@ -688,11 +688,11 @@ def format_library_for_view(library, request, migration: ModulestoreMigration | } return { 'display_name': library.display_name, - 'library_key': str(library.location.library_key), - 'url': reverse_library_url('library_handler', str(library.location.library_key)), + 'library_key': str(library.usage_key.library_key), + 'url': reverse_library_url('library_handler', str(library.usage_key.library_key)), 'org': library.display_org_with_default, 'number': library.display_number_with_default, - 'can_edit': has_studio_write_access(request.user, library.location.library_key), + 'can_edit': has_studio_write_access(request.user, library.usage_key.library_key), 'is_migrated': migration is not None, **migration_info, } @@ -791,13 +791,13 @@ def format_course_for_view(course): """ course_context = { 'display_name': course.display_name, - 'course_key': str(course.location.course_key), + 'course_key': str(course.usage_key.course_key), 'url': reverse_course_url('course_handler', course.id), - 'lms_link': get_lms_link_for_item(course.location), + 'lms_link': get_lms_link_for_item(course.usage_key), 'rerun_link': _get_rerun_link_for_item(course.id), 'org': course.display_org_with_default, 'number': course.display_number_with_default, - 'run': course.location.run + 'run': course.usage_key.run } if course.id.deprecated: course_context.update({ @@ -1301,7 +1301,7 @@ def advanced_settings_handler(request, course_key_string): if use_new_advanced_settings_page(course_key): return redirect(get_advanced_settings_url(course_key)) publisher_enabled = configuration_helpers.get_value_for_org( - course_block.location.org, + course_block.usage_key.org, 'ENABLE_PUBLISHER', settings.FEATURES.get('ENABLE_PUBLISHER', False) ) @@ -1783,7 +1783,7 @@ def bulk_enable_disable_discussions(request, course_key_string): store.update_item(vertical, user.id) if store.has_published_version(vertical): - store.publish(vertical.location, user.id) + store.publish(vertical.usage_key, user.id) changed += 1 return JsonResponse({"units_updated_and_republished": changed}) except Exception as e: # lint-amnesty, pylint: disable=broad-except diff --git a/cms/djangoapps/contentstore/views/entrance_exam.py b/cms/djangoapps/contentstore/views/entrance_exam.py index 5d914366bd9e..3ba7b286bdae 100644 --- a/cms/djangoapps/contentstore/views/entrance_exam.py +++ b/cms/djangoapps/contentstore/views/entrance_exam.py @@ -132,7 +132,7 @@ def _create_entrance_exam(request, course_key, entrance_exam_minimum_score_pct=N return HttpResponse(status=400) # Create the entrance exam item (currently it's just a chapter) - parent_locator = str(course.location) + parent_locator = str(course.usage_key) created_block = create_xblock( parent_locator=parent_locator, user=request.user, @@ -147,13 +147,13 @@ def _create_entrance_exam(request, course_key, entrance_exam_minimum_score_pct=N metadata = { 'entrance_exam_enabled': True, 'entrance_exam_minimum_score_pct': entrance_exam_minimum_score_pct, - 'entrance_exam_id': str(created_block.location), + 'entrance_exam_id': str(created_block.usage_key), } CourseMetadata.update_from_dict(metadata, course, request.user) # Create the entrance exam section item. create_xblock( - parent_locator=str(created_block.location), + parent_locator=str(created_block.usage_key), user=request.user, category='sequential', display_name=_('Entrance Exam - Subsection') @@ -179,7 +179,7 @@ def _get_entrance_exam(request, course_key): try: exam_block = modulestore().get_item(exam_key) return HttpResponse( # lint-amnesty, pylint: disable=http-response-with-content-type-json - dump_js_escaped_json({'locator': str(exam_block.location)}), + dump_js_escaped_json({'locator': str(exam_block.usage_key)}), status=200, content_type='application/json') except ItemNotFoundError: return HttpResponse(status=404) @@ -262,7 +262,7 @@ def add_entrance_exam_milestone(course_id, x_block): # lint-amnesty, pylint: di ) milestones_helpers.add_course_content_milestone( str(course_id), - str(x_block.location), + str(x_block.usage_key), relationship_types['FULFILLS'], milestone ) diff --git a/cms/djangoapps/contentstore/views/library.py b/cms/djangoapps/contentstore/views/library.py index bcc0ffe84842..075b7852f3a6 100644 --- a/cms/djangoapps/contentstore/views/library.py +++ b/cms/djangoapps/contentstore/views/library.py @@ -187,16 +187,16 @@ def _list_libraries(request): lib_info = [ { "display_name": lib.display_name, - "library_key": str(lib.location.library_key), + "library_key": str(lib.usage_key.library_key), } for lib in libraries if ( ( text_search in lib.display_name.lower() or - text_search in lib.location.library_key.org.lower() or - text_search in lib.location.library_key.library.lower() + text_search in lib.usage_key.library_key.org.lower() or + text_search in lib.usage_key.library_key.library.lower() ) and - has_studio_read_access(request.user, lib.location.library_key) + has_studio_read_access(request.user, lib.usage_key.library_key) ) ] return JsonResponse(lib_info) @@ -226,7 +226,7 @@ def _create_library(request): fields={"display_name": display_name}, ) # Give the user admin ("Instructor") role for this library: - add_instructor(new_lib.location.library_key, request.user, request.user) + add_instructor(new_lib.usage_key.library_key, request.user, request.user) except PermissionDenied as error: # pylint: disable=unused-variable log.info( "User does not have the permission to create LIBRARY in this organization." @@ -267,7 +267,7 @@ def _create_library(request): ).format(organization_key=org) }) - lib_key_str = str(new_lib.location.library_key) + lib_key_str = str(new_lib.usage_key.library_key) return JsonResponse({ 'url': reverse_library_url('library_handler', lib_key_str), 'library_key': lib_key_str, @@ -284,8 +284,8 @@ def library_blocks_view(library, user, response_format): Assumes that read permissions have been checked before calling this. """ - assert isinstance(library.location.library_key, LibraryLocator) - assert isinstance(library.location, LibraryUsageLocator) + assert isinstance(library.usage_key.library_key, LibraryLocator) + assert isinstance(library.usage_key, LibraryUsageLocator) children = library.children if response_format == "json": @@ -293,13 +293,13 @@ def library_blocks_view(library, user, response_format): prev_version = library.runtime.course_entry.structure['previous_version'] return JsonResponse({ "display_name": library.display_name, - "library_id": str(library.location.library_key), + "library_id": str(library.usage_key.library_key), "version": str(library.runtime.course_entry.course_key.version_guid), "previous_version": str(prev_version) if prev_version else None, "blocks": [str(x) for x in children], }) - can_edit = has_studio_write_access(user, library.location.library_key) + can_edit = has_studio_write_access(user, library.usage_key.library_key) xblock_info = create_xblock_info(library, include_ancestor_info=False, graders=[]) component_templates = get_component_templates(library, library=True) if can_edit else [] diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 6600430a7a89..5c6333c0550f 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -162,7 +162,7 @@ def _prepare_runtime_for_preview(request, block): block: An XBlock """ - course_id = block.location.course_key + course_id = block.usage_key.course_key display_name_only = (block.category == 'static_tab') wrappers = [ @@ -298,7 +298,7 @@ def _is_xblock_reorderable(xblock, context): otherwise returns false. """ try: - return xblock.location in context['reorderable_items'] + return xblock.usage_key in context['reorderable_items'] except KeyError: return False @@ -313,12 +313,12 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False): # Only add the Studio wrapper when on the container page. The "Pages" page will remain as is for now. if not context.get('is_pages_view', None) and view in PREVIEW_VIEWS: root_xblock = context.get('root_xblock') - is_root = root_xblock and xblock.location == root_xblock.location + is_root = root_xblock and xblock.usage_key == root_xblock.usage_key is_reorderable = _is_xblock_reorderable(xblock, context) selected_groups_label = get_visibility_partition_info(xblock)['selected_groups_label'] if selected_groups_label: selected_groups_label = _('Access restricted to: {list_of_groups}').format(list_of_groups=selected_groups_label) # lint-amnesty, pylint: disable=line-too-long - course = modulestore().get_course(xblock.location.course_key) + course = modulestore().get_course(xblock.usage_key.course_key) can_edit = context.get('can_edit', True) can_add = context.get('can_add', True) @@ -344,7 +344,7 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False): tags_count_map = context.get('tags_count_map') tags_count = 0 if tags_count_map: - tags_count = tags_count_map.get(str(xblock.location), 0) + tags_count = tags_count_map.get(str(xblock.usage_key), 0) template_context = { 'xblock_context': context, 'xblock': xblock, diff --git a/cms/djangoapps/contentstore/views/tabs.py b/cms/djangoapps/contentstore/views/tabs.py index 8fa9d024458d..83976d418cf0 100644 --- a/cms/djangoapps/contentstore/views/tabs.py +++ b/cms/djangoapps/contentstore/views/tabs.py @@ -199,7 +199,7 @@ def get_tab_by_locator(tab_list: List[CourseTab], tab_location: Union[str, Usage item = modulestore().get_item(tab_location) static_tab = StaticTab( name=item.display_name, - url_slug=item.location.name, + url_slug=item.usage_key.name, ) return CourseTabList.get_tab_by_id(tab_list, static_tab.tab_id) diff --git a/cms/djangoapps/contentstore/views/tests/test_block.py b/cms/djangoapps/contentstore/views/tests/test_block.py index 31f5244e2f55..0789c9d84b67 100644 --- a/cms/djangoapps/contentstore/views/tests/test_block.py +++ b/cms/djangoapps/contentstore/views/tests/test_block.py @@ -111,7 +111,7 @@ def setUp(self): super().setUp() self.course_key = self.course.id - self.usage_key = self.course.location + self.usage_key = self.course.usage_key def get_item_from_modulestore(self, usage_key): """ @@ -489,7 +489,7 @@ def test_ancestor_info(self, field_type): # Create a parent chapter chap1 = self.create_xblock( - parent_usage_key=self.course.location, + parent_usage_key=self.course.usage_key, display_name="chapter1", category="chapter", ) @@ -526,7 +526,7 @@ def assert_xblock_info(xblock, xblock_info): xblock (XBlock): An XBlock item. xblock_info (dict): A dict containing xblock information. """ - self.assertEqual(str(xblock.location), xblock_info["id"]) + self.assertEqual(str(xblock.usage_key), xblock_info["id"]) self.assertEqual(xblock.display_name, xblock_info["display_name"]) self.assertEqual(xblock.category, xblock_info["category"]) @@ -563,7 +563,7 @@ def test_delete_static_page(self): course = CourseFactory.create() # Add static tab resp = self.create_xblock( - category="static_tab", parent_usage_key=course.location + category="static_tab", parent_usage_key=course.usage_key ) usage_key = self.response_usage_key(resp) @@ -590,8 +590,8 @@ def test_create_nicely(self): new_obj = self.get_item_from_modulestore(chap_usage_key) self.assertEqual(new_obj.scope_ids.block_type, "chapter") self.assertEqual(new_obj.display_name, display_name) - self.assertEqual(new_obj.location.org, self.course.location.org) - self.assertEqual(new_obj.location.course, self.course.location.course) + self.assertEqual(new_obj.usage_key.org, self.course.usage_key.org) + self.assertEqual(new_obj.usage_key.course, self.course.usage_key.course) # get the course and ensure it now points to this one course = self.get_item_from_modulestore(self.usage_key) @@ -674,8 +674,8 @@ def _check_equality( self.assertEqual(duplicated_asides[0].field13, "aside1_default_value3") self.assertNotEqual( - str(original_item.location), - str(duplicated_item.location), + str(original_item.usage_key), + str(duplicated_item.usage_key), "Location of duplicate should be different from original", ) @@ -696,7 +696,7 @@ def _check_equality( # Set the location and parent to be the same so we can make sure the rest of the # duplicate is equal. - duplicated_item.location = original_item.location + duplicated_item.usage_key = original_item.usage_key duplicated_item.parent = original_item.parent # Children will also be duplicated, so for the purposes of testing equality, we will set @@ -930,12 +930,12 @@ def test_shallow_duplicate(self): ) BlockFactory(parent=source_chapter, category="html", display_name="Child") # Refresh. - source_chapter = self.store.get_item(source_chapter.location) + source_chapter = self.store.get_item(source_chapter.usage_key) self.assertEqual(len(source_chapter.get_children()), 1) destination_course = CourseFactory() destination_location = duplicate_block( - parent_usage_key=destination_course.location, - duplicate_source_usage_key=source_chapter.location, + parent_usage_key=destination_course.usage_key, + duplicate_source_usage_key=source_chapter.usage_key, user=user, display_name=source_chapter.display_name, shallow=True, @@ -969,8 +969,8 @@ def test_duplicate_library_content_block(self): # pylint: disable=too-many-stat publish_item=False, ) original_lib_version = store.get_library( - lib.location.library_key, remove_version=False, remove_branch=False, - ).location.library_key.version_guid + lib.usage_key.library_key, remove_version=False, remove_branch=False, + ).usage_key.library_key.version_guid assert original_lib_version is not None # Create a library content block (lc), point it out our library, and sync it. @@ -983,13 +983,13 @@ def test_duplicate_library_content_block(self): # pylint: disable=too-many-stat lc = BlockFactory( parent=unit, category="library_content", - source_library_id=str(lib.location.library_key), + source_library_id=str(lib.usage_key.library_key), display_name="LC Block", max_count=1, publish_item=False, ) lc.sync_from_library() - lc = store.get_item(lc.location) # we must reload because sync_from_library happens out-of-thread + lc = store.get_item(lc.usage_key) # we must reload because sync_from_library happens out-of-thread assert lc.source_library_version == str(original_lib_version) lc_html_1 = store.get_item(lc.children[0]) lc_html_2 = store.get_item(lc.children[1]) @@ -1017,8 +1017,8 @@ def test_duplicate_library_content_block(self): # pylint: disable=too-many-stat store.update_item(lib_html_1, self.user.id) store.update_item(lib_html_2, self.user.id) updated_lib_version = store.get_library( - lib.location.library_key, remove_version=False, remove_branch=False, - ).location.library_key.version_guid + lib.usage_key.library_key, remove_version=False, remove_branch=False, + ).usage_key.library_key.version_guid assert updated_lib_version is not None assert updated_lib_version != original_lib_version @@ -1027,17 +1027,17 @@ def test_duplicate_library_content_block(self): # pylint: disable=too-many-stat # All settings should match between lc and dupe. dupe = store.get_item( self._duplicate_item( - parent_usage_key=unit.location, - source_usage_key=lc.location, + parent_usage_key=unit.usage_key, + source_usage_key=lc.usage_key, display_name="Dupe LC Block", ) ) - lc = store.get_item(lc.location) - unit = store.get_item(unit.location) - assert unit.children == [lc.location, dupe.location] + lc = store.get_item(lc.usage_key) + unit = store.get_item(unit.usage_key) + assert unit.children == [lc.usage_key, dupe.usage_key] assert len(lc.children) == len(dupe.children) == 2 assert lc.max_count == dupe.max_count == 1 - assert lc.source_library_id == dupe.source_library_id == str(lib.location.library_key) + assert lc.source_library_id == dupe.source_library_id == str(lib.usage_key.library_key) assert lc.source_library_version == dupe.source_library_version == str(original_lib_version) # The lc block's children should remain unchanged. @@ -1064,7 +1064,7 @@ def test_duplicate_library_content_block(self): # pylint: disable=too-many-stat # Finally, upgrade the dupe's library version, and make sure it pulls in updated library block *content*, # whilst preserving *settings overrides* (specifically, HTML 1's title override). dupe.sync_from_library(upgrade_to_latest=True) - dupe = store.get_item(dupe.location) + dupe = store.get_item(dupe.usage_key) assert dupe.source_library_version == str(updated_lib_version) assert len(dupe.children) == 2 dupe_html_1 = store.get_item(dupe.children[0]) @@ -1096,16 +1096,16 @@ def test_duplicate_tags(self): tagging_api.add_tag_to_taxonomy(taxonomyB, "four") # Tag the chapter - tagging_api.tag_object(str(source_chapter.location), taxonomyA, ["one", "two"]) - tagging_api.tag_object(str(source_chapter.location), taxonomyB, ["three", "four"]) + tagging_api.tag_object(str(source_chapter.usage_key), taxonomyA, ["one", "two"]) + tagging_api.tag_object(str(source_chapter.usage_key), taxonomyB, ["three", "four"]) # Tag the child block - tagging_api.tag_object(str(source_block.location), taxonomyA, ["two"],) + tagging_api.tag_object(str(source_block.usage_key), taxonomyA, ["two"],) # Duplicate the chapter (and its children) dupe_location = duplicate_block( - parent_usage_key=source_course.location, - duplicate_source_usage_key=source_chapter.location, + parent_usage_key=source_course.usage_key, + duplicate_source_usage_key=source_chapter.usage_key, user=user, ) dupe_chapter = self.store.get_item(dupe_location) @@ -1114,17 +1114,17 @@ def test_duplicate_tags(self): # Check that the duplicated blocks also duplicated tags expected_chapter_tags = [ - f' {str(dupe_chapter.location)}: A=one', - f' {str(dupe_chapter.location)}: A=two', - f' {str(dupe_chapter.location)}: B=four', - f' {str(dupe_chapter.location)}: B=three', + f' {str(dupe_chapter.usage_key)}: A=one', + f' {str(dupe_chapter.usage_key)}: A=two', + f' {str(dupe_chapter.usage_key)}: B=four', + f' {str(dupe_chapter.usage_key)}: B=three', ] - dupe_chapter_tags = [str(object_tag) for object_tag in tagging_api.get_object_tags(str(dupe_chapter.location))] + dupe_chapter_tags = [str(object_tag) for object_tag in tagging_api.get_object_tags(str(dupe_chapter.usage_key))] assert dupe_chapter_tags == expected_chapter_tags expected_block_tags = [ - f' {str(dupe_block.location)}: A=two', + f' {str(dupe_block.usage_key)}: A=two', ] - dupe_block_tags = [str(object_tag) for object_tag in tagging_api.get_object_tags(str(dupe_block.location))] + dupe_block_tags = [str(object_tag) for object_tag in tagging_api.get_object_tags(str(dupe_block.usage_key))] assert dupe_block_tags == expected_block_tags @@ -1163,14 +1163,14 @@ def setup_course(self, default_store=None): # Create a parent chapter chap1 = self.create_xblock( - parent_usage_key=course.location, + parent_usage_key=course.usage_key, display_name="chapter1", category="chapter", ) self.chapter_usage_key = self.response_usage_key(chap1) chap2 = self.create_xblock( - parent_usage_key=course.location, + parent_usage_key=course.usage_key, display_name="chapter2", category="chapter", ) @@ -1225,7 +1225,7 @@ def setup_course(self, default_store=None): ) self.split_test_usage_key = self.response_usage_key(resp) - self.course = self.store.get_item(course.location) + self.course = self.store.get_item(course.usage_key) def setup_and_verify_content_experiment(self, partition_id): """ @@ -1342,7 +1342,7 @@ def test_move_source_index(self): parent = self.get_item_from_modulestore(self.vert_usage_key) children = parent.get_children() self.assertEqual(len(children), 4) - self.assertEqual(children[1].location, html2_usage_key) + self.assertEqual(children[1].usage_key, html2_usage_key) def test_move_undo(self): """ @@ -2078,7 +2078,7 @@ def test_move_orphaned_child_error(self): """ unit_1_key = self.store.create_item( self.user.id, self.course_key, "vertical", "unit1" - ).location + ).usage_key # adding orphaned unit 1 should return an error resp = self.client.ajax_post( @@ -2251,7 +2251,7 @@ def _make_draft_content_different_from_published(self): self.assertIsNone(published.due) # Fetch the published version again to make sure the due date is still unset. published = modulestore().get_item( - published.location, revision=ModuleStoreEnum.RevisionOption.published_only + published.usage_key, revision=ModuleStoreEnum.RevisionOption.published_only ) self.assertIsNone(published.due) @@ -2308,7 +2308,7 @@ def test_published_and_draft_contents_with_update(self): self.assertNotEqual(draft.data, published.data) # Fetch the published version again to make sure the data is correct. published = modulestore().get_item( - published.location, revision=ModuleStoreEnum.RevisionOption.published_only + published.usage_key, revision=ModuleStoreEnum.RevisionOption.published_only ) self.assertNotEqual(draft.data, published.data) @@ -2481,11 +2481,11 @@ def test_create_groups(self): # Verify that the group_id_to_child mapping is correct. self.assertEqual(2, len(split_test.group_id_to_child)) self.assertEqual( - vertical_0.location, + vertical_0.usage_key, split_test.group_id_to_child[str(self.first_user_partition_group_1.id)], ) self.assertEqual( - vertical_1.location, + vertical_1.usage_key, split_test.group_id_to_child[str(self.first_user_partition_group_2.id)], ) @@ -2542,19 +2542,19 @@ def test_change_user_partition_id(self): # Verify that the group_id_to child mapping is correct. self.assertEqual(3, len(split_test.group_id_to_child)) self.assertEqual( - vertical_0.location, + vertical_0.usage_key, split_test.group_id_to_child[str(self.second_user_partition_group_1.id)], ) self.assertEqual( - vertical_1.location, + vertical_1.usage_key, split_test.group_id_to_child[str(self.second_user_partition_group_2.id)], ) self.assertEqual( - vertical_2.location, + vertical_2.usage_key, split_test.group_id_to_child[str(self.second_user_partition_group_3.id)], ) - self.assertNotEqual(initial_vertical_0_location, vertical_0.location) - self.assertNotEqual(initial_vertical_1_location, vertical_1.location) + self.assertNotEqual(initial_vertical_0_location, vertical_0.usage_key) + self.assertNotEqual(initial_vertical_1_location, vertical_1.usage_key) def test_change_same_user_partition_id(self): """ @@ -3082,7 +3082,7 @@ def test_discussion_button_present_legacy_provider(self): """ Test the Discussion button present when legacy discussion provider configured for course """ - course_key = self.course.location.course_key + course_key = self.course.usage_key.course_key # Create a discussion configuration with discussion provider set as legacy DiscussionsConfiguration.objects.create( @@ -3097,7 +3097,7 @@ def test_discussion_button_absent_non_legacy_provider(self): """ Test the Discussion button not present when non-legacy discussion provider configured for course """ - course_key = self.course.location.course_key + course_key = self.course.usage_key.course_key # Create a discussion configuration with discussion provider set as legacy DiscussionsConfiguration.objects.create( @@ -3154,26 +3154,26 @@ def setUp(self): super().setUp() user_id = self.user.id self.chapter = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category="chapter", display_name="Week 1", user_id=user_id, highlights=["highlight"], ) self.sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Lesson 1", user_id=user_id, ) self.vertical = BlockFactory.create( - parent_location=self.sequential.location, + parent_location=self.sequential.usage_key, category="vertical", display_name="Unit 1", user_id=user_id, ) self.video = BlockFactory.create( - parent_location=self.vertical.location, + parent_location=self.vertical.usage_key, category="video", display_name="My Video", user_id=user_id, @@ -3188,18 +3188,18 @@ def test_json_responses(self): def test_xblock_outline_handler_mongo_calls(self): course = CourseFactory.create() chapter = BlockFactory.create( - parent_location=course.location, category='chapter', display_name='Week 1' + parent_location=course.usage_key, category='chapter', display_name='Week 1' ) - outline_url = reverse_usage_url('xblock_outline_handler', chapter.location) + outline_url = reverse_usage_url('xblock_outline_handler', chapter.usage_key) with check_mongo_calls(3): self.client.get(outline_url, HTTP_ACCEPT='application/json') sequential = BlockFactory.create( - parent_location=chapter.location, category='sequential', display_name='Sequential 1' + parent_location=chapter.usage_key, category='sequential', display_name='Sequential 1' ) BlockFactory.create( - parent_location=sequential.location, category='vertical', display_name='Vertical 1' + parent_location=sequential.usage_key, category='vertical', display_name='Vertical 1' ) # calls should be same after adding two new children for split only. with check_mongo_calls(3): @@ -3207,13 +3207,13 @@ def test_xblock_outline_handler_mongo_calls(self): def test_entrance_exam_chapter_xblock_info(self): chapter = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category="chapter", display_name="Entrance Exam", user_id=self.user.id, is_entrance_exam=True, ) - chapter = modulestore().get_item(chapter.location) + chapter = modulestore().get_item(chapter.usage_key) xblock_info = create_xblock_info( chapter, include_child_info=True, @@ -3229,12 +3229,12 @@ def test_entrance_exam_chapter_xblock_info(self): def test_none_entrance_exam_chapter_xblock_info(self): chapter = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category="chapter", display_name="Test Chapter", user_id=self.user.id, ) - chapter = modulestore().get_item(chapter.location) + chapter = modulestore().get_item(chapter.usage_key) xblock_info = create_xblock_info( chapter, include_child_info=True, @@ -3251,7 +3251,7 @@ def test_none_entrance_exam_chapter_xblock_info(self): def test_entrance_exam_sequential_xblock_info(self): chapter = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category="chapter", display_name="Entrance Exam", user_id=self.user.id, @@ -3260,13 +3260,13 @@ def test_entrance_exam_sequential_xblock_info(self): ) subsection = BlockFactory.create( - parent_location=chapter.location, + parent_location=chapter.usage_key, category="sequential", display_name="Subsection - Entrance Exam", user_id=self.user.id, in_entrance_exam=True, ) - subsection = modulestore().get_item(subsection.location) + subsection = modulestore().get_item(subsection.usage_key) xblock_info = create_xblock_info( subsection, include_child_info=True, include_children_predicate=ALWAYS ) @@ -3276,12 +3276,12 @@ def test_entrance_exam_sequential_xblock_info(self): def test_none_entrance_exam_sequential_xblock_info(self): subsection = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Subsection - Exam", user_id=self.user.id, ) - subsection = modulestore().get_item(subsection.location) + subsection = modulestore().get_item(subsection.usage_key) xblock_info = create_xblock_info( subsection, include_child_info=True, @@ -3292,7 +3292,7 @@ def test_none_entrance_exam_sequential_xblock_info(self): self.assertIsNone(xblock_info.get("is_header_visible", None)) def test_chapter_xblock_info(self): - chapter = modulestore().get_item(self.chapter.location) + chapter = modulestore().get_item(self.chapter.usage_key) xblock_info = create_xblock_info( chapter, include_child_info=True, @@ -3301,7 +3301,7 @@ def test_chapter_xblock_info(self): self.validate_chapter_xblock_info(xblock_info) def test_sequential_xblock_info(self): - sequential = modulestore().get_item(self.sequential.location) + sequential = modulestore().get_item(self.sequential.usage_key) xblock_info = create_xblock_info( sequential, include_child_info=True, @@ -3310,7 +3310,7 @@ def test_sequential_xblock_info(self): self.validate_sequential_xblock_info(xblock_info) def test_vertical_xblock_info(self): - vertical = modulestore().get_item(self.vertical.location) + vertical = modulestore().get_item(self.vertical.usage_key) xblock_info = create_xblock_info( vertical, @@ -3323,7 +3323,7 @@ def test_vertical_xblock_info(self): self.validate_vertical_xblock_info(xblock_info) def test_component_xblock_info(self): - video = modulestore().get_item(self.video.location) + video = modulestore().get_item(self.video.usage_key) xblock_info = create_xblock_info( video, include_child_info=True, include_children_predicate=ALWAYS ) @@ -3335,7 +3335,7 @@ def test_validate_start_date(self): """ course = CourseFactory.create() chapter = BlockFactory.create( - parent_location=course.location, category='chapter', display_name='Week 1' + parent_location=course.usage_key, category='chapter', display_name='Week 1' ) chapter.start = datetime(year=1899, month=1, day=1, tzinfo=UTC) @@ -3385,7 +3385,7 @@ def validate_course_xblock_info( Validate that the xblock info is correct for the test course. """ self.assertEqual(xblock_info["category"], "course") - self.assertEqual(xblock_info["id"], str(self.course.location)) + self.assertEqual(xblock_info["id"], str(self.course.usage_key)) self.assertEqual(xblock_info["display_name"], self.course.display_name) self.assertTrue(xblock_info["published"]) self.assertFalse(xblock_info["highlights_enabled_for_messaging"]) @@ -3400,7 +3400,7 @@ def validate_chapter_xblock_info(self, xblock_info, has_child_info=True): Validate that the xblock info is correct for the test chapter. """ self.assertEqual(xblock_info["category"], "chapter") - self.assertEqual(xblock_info["id"], str(self.chapter.location)) + self.assertEqual(xblock_info["id"], str(self.chapter.usage_key)) self.assertEqual(xblock_info["display_name"], "Week 1") self.assertTrue(xblock_info["published"]) self.assertIsNone(xblock_info.get("edited_by", None)) @@ -3425,7 +3425,7 @@ def validate_sequential_xblock_info(self, xblock_info, has_child_info=True): Validate that the xblock info is correct for the test sequential. """ self.assertEqual(xblock_info["category"], "sequential") - self.assertEqual(xblock_info["id"], str(self.sequential.location)) + self.assertEqual(xblock_info["id"], str(self.sequential.usage_key)) self.assertEqual(xblock_info["display_name"], "Lesson 1") self.assertTrue(xblock_info["published"]) self.assertIsNone(xblock_info.get("edited_by", None)) @@ -3440,7 +3440,7 @@ def validate_vertical_xblock_info(self, xblock_info): Validate that the xblock info is correct for the test vertical. """ self.assertEqual(xblock_info["category"], "vertical") - self.assertEqual(xblock_info["id"], str(self.vertical.location)) + self.assertEqual(xblock_info["id"], str(self.vertical.usage_key)) self.assertEqual(xblock_info["display_name"], "Unit 1") self.assertTrue(xblock_info["published"]) self.assertEqual(xblock_info["edited_by"], "testuser") @@ -3464,7 +3464,7 @@ def validate_component_xblock_info(self, xblock_info): Validate that the xblock info is correct for the test component. """ self.assertEqual(xblock_info["category"], "video") - self.assertEqual(xblock_info["id"], str(self.video.location)) + self.assertEqual(xblock_info["id"], str(self.video.usage_key)) self.assertEqual(xblock_info["display_name"], "My Video") self.assertTrue(xblock_info["published"]) self.assertIsNone(xblock_info.get("edited_by", None)) @@ -3542,20 +3542,20 @@ def setUp(self): super().setUp() user_id = self.user.id self.chapter = BlockFactory.create( - parent_location=self.course.location, + parent_location=self.course.usage_key, category="chapter", display_name="Week 1", user_id=user_id, highlights=["highlight"], ) # get updated course - self.course = self.store.get_item(self.course.location) + self.course = self.store.get_item(self.course.usage_key) self.course.enable_proctored_exams = True self.course.save() self.course = self.store.update_item(self.course, self.user.id) def test_proctoring_is_enabled_for_course(self): - course = modulestore().get_item(self.course.location) + course = modulestore().get_item(self.course.usage_key) xblock_info = create_xblock_info( course, include_child_info=True, @@ -3574,7 +3574,7 @@ def test_special_exam_xblock_info( mock_get_exam_configuration_dashboard_url, ): sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Test Lesson 1", user_id=self.user.id, @@ -3583,7 +3583,7 @@ def test_special_exam_xblock_info( default_time_limit_minutes=100, is_onboarding_exam=False, ) - sequential = modulestore().get_item(sequential.location) + sequential = modulestore().get_item(sequential.usage_key) xblock_info = create_xblock_info( sequential, include_child_info=True, @@ -3621,7 +3621,7 @@ def test_show_review_rules_xblock_info( # Set course.proctoring_provider to test_proctoring_provider self.course.proctoring_provider = 'test_proctoring_provider' sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Test Lesson 1", user_id=self.user.id, @@ -3630,7 +3630,7 @@ def test_show_review_rules_xblock_info( default_time_limit_minutes=100, is_onboarding_exam=False, ) - sequential = modulestore().get_item(sequential.location) + sequential = modulestore().get_item(sequential.usage_key) xblock_info = create_xblock_info( sequential, include_child_info=True, @@ -3658,7 +3658,7 @@ def test_proctoring_values_correct_depending_on_lti_external( _mock_get_exam_configuration_dashboard_url, ): sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Test Lesson 1", user_id=self.user.id, @@ -3674,7 +3674,7 @@ def test_proctoring_values_correct_depending_on_lti_external( # mock_does_backend_support_onboarding returns True mock_does_backend_support_onboarding.return_value = True - sequential = modulestore().get_item(sequential.location) + sequential = modulestore().get_item(sequential.usage_key) xblock_info = create_xblock_info( sequential, include_child_info=True, @@ -3701,7 +3701,7 @@ def test_xblock_was_ever_linked_to_external_exam( _mock_get_exam_configuration_dashboard_url, ): sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Test Lesson 1", user_id=self.user.id, @@ -3710,7 +3710,7 @@ def test_xblock_was_ever_linked_to_external_exam( is_onboarding_exam=False, ) mock_get_exam_by_content_id.return_value = {"external_id": external_id} - sequential = modulestore().get_item(sequential.location) + sequential = modulestore().get_item(sequential.usage_key) xblock_info = create_xblock_info( sequential, include_child_info=True, @@ -3729,7 +3729,7 @@ def test_xblock_was_never_linked_to_external_exam( _mock_get_exam_configuration_dashboard_url, ): sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Test Lesson 1", user_id=self.user.id, @@ -3737,7 +3737,7 @@ def test_xblock_was_never_linked_to_external_exam( is_time_limited=False, is_onboarding_exam=False, ) - sequential = modulestore().get_item(sequential.location) + sequential = modulestore().get_item(sequential.usage_key) xblock_info = create_xblock_info( sequential, include_child_info=True, @@ -3756,7 +3756,7 @@ def test_special_exam_xblock_info_get_dashboard_error( mock_get_exam_configuration_dashboard_url, ): sequential = BlockFactory.create( - parent_location=self.chapter.location, + parent_location=self.chapter.usage_key, category="sequential", display_name="Test Lesson 1", user_id=self.user.id, @@ -3765,7 +3765,7 @@ def test_special_exam_xblock_info_get_dashboard_error( default_time_limit_minutes=100, is_onboarding_exam=False, ) - sequential = modulestore().get_item(sequential.location) + sequential = modulestore().get_item(sequential.usage_key) mock_get_exam_configuration_dashboard_url.side_effect = Exception("proctoring error") xblock_info = create_xblock_info( sequential, @@ -3794,19 +3794,19 @@ def setUp(self): user_id = self.user.id self.library = LibraryFactory.create() self.top_level_html = BlockFactory.create( - parent_location=self.library.location, + parent_location=self.library.usage_key, category="html", user_id=user_id, publish_item=False, ) self.vertical = BlockFactory.create( - parent_location=self.library.location, + parent_location=self.library.usage_key, category="vertical", user_id=user_id, publish_item=False, ) self.child_html = BlockFactory.create( - parent_location=self.vertical.location, + parent_location=self.vertical.usage_key, category="html", display_name="Test HTML Child Block", user_id=user_id, @@ -3814,13 +3814,13 @@ def setUp(self): ) def test_lib_xblock_info(self): - html_block = modulestore().get_item(self.top_level_html.location) + html_block = modulestore().get_item(self.top_level_html.usage_key) xblock_info = create_xblock_info(html_block) self.validate_component_xblock_info(xblock_info, html_block) self.assertIsNone(xblock_info.get("child_info", None)) def test_lib_child_xblock_info(self): - html_block = modulestore().get_item(self.child_html.location) + html_block = modulestore().get_item(self.child_html.usage_key) xblock_info = create_xblock_info( html_block, include_ancestor_info=True, include_child_info=True ) @@ -3829,7 +3829,7 @@ def test_lib_child_xblock_info(self): ancestors = xblock_info["ancestor_info"]["ancestors"] self.assertEqual(len(ancestors), 2) self.assertEqual(ancestors[0]["category"], "vertical") - self.assertEqual(ancestors[0]["id"], str(self.vertical.location)) + self.assertEqual(ancestors[0]["id"], str(self.vertical.usage_key)) self.assertEqual(ancestors[1]["category"], "library") def validate_component_xblock_info(self, xblock_info, original_block): @@ -3837,7 +3837,7 @@ def validate_component_xblock_info(self, xblock_info, original_block): Validate that the xblock info is correct for the test component. """ self.assertEqual(xblock_info["category"], original_block.category) - self.assertEqual(xblock_info["id"], str(original_block.location)) + self.assertEqual(xblock_info["id"], str(original_block.usage_key)) self.assertEqual(xblock_info["display_name"], original_block.display_name) self.assertIsNone(xblock_info.get("has_changes", None)) self.assertIsNone(xblock_info.get("published", None)) @@ -3856,9 +3856,9 @@ def test_add_xblock(self): """ lib = LibraryFactory.create() self.create_xblock( - parent_usage_key=lib.location, display_name="Test", category="html" + parent_usage_key=lib.usage_key, display_name="Test", category="html" ) - lib = self.store.get_library(lib.location.library_key) + lib = self.store.get_library(lib.usage_key.library_key) self.assertTrue(lib.children) xblock_locator = lib.children[0] self.assertEqual(self.store.get_item(xblock_locator).display_name, "Test") @@ -3869,10 +3869,10 @@ def test_no_add_discussion(self): """ lib = LibraryFactory.create() response = self.create_xblock( - parent_usage_key=lib.location, display_name="Test", category="discussion" + parent_usage_key=lib.usage_key, display_name="Test", category="discussion" ) self.assertEqual(response.status_code, 400) - lib = self.store.get_library(lib.location.library_key) + lib = self.store.get_library(lib.usage_key.library_key) self.assertFalse(lib.children) def test_no_add_advanced(self): @@ -3880,10 +3880,10 @@ def test_no_add_advanced(self): lib.advanced_modules = ["lti"] lib.save() response = self.create_xblock( - parent_usage_key=lib.location, display_name="Test", category="lti" + parent_usage_key=lib.usage_key, display_name="Test", category="lti" ) self.assertEqual(response.status_code, 400) - lib = self.store.get_library(lib.location.library_key) + lib = self.store.get_library(lib.usage_key.library_key) self.assertFalse(lib.children) @@ -3904,16 +3904,16 @@ def _create_child( Creates a child xblock for the given parent. """ child = BlockFactory.create( - parent_location=parent.location, + parent_location=parent.usage_key, category=category, display_name=display_name, user_id=self.user.id, publish_item=publish_item, ) if staff_only: - self._enable_staff_only(child.location) + self._enable_staff_only(child.usage_key) # In case the staff_only state was set, return the updated xblock. - return modulestore().get_item(child.location) + return modulestore().get_item(child.usage_key) def _get_child_xblock_info(self, xblock_info, index): """ @@ -4027,7 +4027,7 @@ def _verify_explicit_staff_lock_state( def test_empty_chapter(self): empty_chapter = self._create_child(self.course, "chapter", "Empty Chapter") - xblock_info = self._get_xblock_info(empty_chapter.location) + xblock_info = self._get_xblock_info(empty_chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.unscheduled) def test_chapter_self_paced_default_start_date(self): @@ -4037,14 +4037,14 @@ def test_chapter_self_paced_default_start_date(self): chapter = self._create_child(course, "chapter", "Test Chapter") sequential = self._create_child(chapter, "sequential", "Test Sequential") self._create_child(sequential, "vertical", "Published Unit", publish_item=True) - self._set_release_date(chapter.location, DEFAULT_START_DATE) - xblock_info = self._get_xblock_info(chapter.location) + self._set_release_date(chapter.usage_key, DEFAULT_START_DATE) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.live) def test_empty_sequential(self): chapter = self._create_child(self.course, "chapter", "Test Chapter") self._create_child(chapter, "sequential", "Empty Sequential") - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.unscheduled) self._verify_visibility_state( xblock_info, VisibilityState.unscheduled, path=self.FIRST_SUBSECTION_PATH @@ -4058,8 +4058,8 @@ def test_published_unit(self): sequential = self._create_child(chapter, "sequential", "Test Sequential") self._create_child(sequential, "vertical", "Published Unit", publish_item=True) self._create_child(sequential, "vertical", "Staff Only Unit", staff_only=True) - self._set_release_date(chapter.location, datetime.now(UTC) + timedelta(days=1)) - xblock_info = self._get_xblock_info(chapter.location) + self._set_release_date(chapter.usage_key, datetime.now(UTC) + timedelta(days=1)) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.ready) self._verify_visibility_state( xblock_info, VisibilityState.ready, path=self.FIRST_SUBSECTION_PATH @@ -4079,8 +4079,8 @@ def test_released_unit(self): sequential = self._create_child(chapter, "sequential", "Test Sequential") self._create_child(sequential, "vertical", "Published Unit", publish_item=True) self._create_child(sequential, "vertical", "Staff Only Unit", staff_only=True) - self._set_release_date(chapter.location, datetime.now(UTC) - timedelta(days=1)) - xblock_info = self._get_xblock_info(chapter.location) + self._set_release_date(chapter.usage_key, datetime.now(UTC) - timedelta(days=1)) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.live) self._verify_visibility_state( xblock_info, VisibilityState.live, path=self.FIRST_SUBSECTION_PATH @@ -4103,8 +4103,8 @@ def test_unpublished_changes(self): ) self._create_child(sequential, "vertical", "Staff Only Unit", staff_only=True) # Setting the display name creates a draft version of unit. - self._set_display_name(unit.location, "Updated Unit") - xblock_info = self._get_xblock_info(chapter.location) + self._set_display_name(unit.usage_key, "Updated Unit") + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.needs_attention) self._verify_visibility_state( xblock_info, @@ -4123,12 +4123,12 @@ def test_partially_released_section(self): released_sequential = self._create_child(chapter, 'sequential', "Released Sequential") self._create_child(released_sequential, 'vertical', "Released Unit", publish_item=True) self._create_child(released_sequential, 'vertical', "Staff Only Unit 1", staff_only=True) - self._set_release_date(chapter.location, datetime.now(UTC) - timedelta(days=1)) + self._set_release_date(chapter.usage_key, datetime.now(UTC) - timedelta(days=1)) published_sequential = self._create_child(chapter, 'sequential', "Published Sequential") self._create_child(published_sequential, 'vertical', "Published Unit", publish_item=True) self._create_child(published_sequential, 'vertical', "Staff Only Unit 2", staff_only=True) - self._set_release_date(published_sequential.location, datetime.now(UTC) + timedelta(days=1)) - xblock_info = self._get_xblock_info(chapter.location) + self._set_release_date(published_sequential.usage_key, datetime.now(UTC) + timedelta(days=1)) + xblock_info = self._get_xblock_info(chapter.usage_key) # Verify the state of the released sequential self._verify_visibility_state(xblock_info, VisibilityState.live, path=[0]) @@ -4156,7 +4156,7 @@ def test_staff_only_section(self): ) sequential = self._create_child(chapter, "sequential", "Test Sequential") vertical = self._create_child(sequential, "vertical", "Unit") - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.staff_only) self._verify_visibility_state( xblock_info, VisibilityState.staff_only, path=self.FIRST_SUBSECTION_PATH @@ -4173,7 +4173,7 @@ def test_staff_only_section(self): xblock_info, False, path=self.FIRST_UNIT_PATH ) - vertical_info = self._get_xblock_info(vertical.location) + vertical_info = self._get_xblock_info(vertical.usage_key) add_container_page_publishing_info(vertical, vertical_info) self.assertEqual( _xblock_type_and_display_name(chapter), vertical_info["staff_lock_from"] @@ -4188,7 +4188,7 @@ def test_no_staff_only_section(self): self._create_child( chapter, "sequential", "Test Staff Locked Sequential", staff_only=True ) - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state( xblock_info, VisibilityState.staff_only, should_equal=False ) @@ -4207,7 +4207,7 @@ def test_staff_only_subsection(self): chapter, "sequential", "Test Sequential", staff_only=True ) vertical = self._create_child(sequential, "vertical", "Unit") - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.staff_only) self._verify_visibility_state( xblock_info, VisibilityState.staff_only, path=self.FIRST_SUBSECTION_PATH @@ -4224,7 +4224,7 @@ def test_staff_only_subsection(self): xblock_info, False, path=self.FIRST_UNIT_PATH ) - vertical_info = self._get_xblock_info(vertical.location) + vertical_info = self._get_xblock_info(vertical.usage_key) add_container_page_publishing_info(vertical, vertical_info) self.assertEqual( _xblock_type_and_display_name(sequential), vertical_info["staff_lock_from"] @@ -4238,7 +4238,7 @@ def test_no_staff_only_subsection(self): sequential = self._create_child(chapter, "sequential", "Test Sequential") self._create_child(sequential, "vertical", "Unit") self._create_child(sequential, "vertical", "Locked Unit", staff_only=True) - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state( xblock_info, VisibilityState.staff_only, @@ -4259,7 +4259,7 @@ def test_staff_only_unit(self): chapter = self._create_child(self.course, "chapter", "Test Chapter") sequential = self._create_child(chapter, "sequential", "Test Sequential") vertical = self._create_child(sequential, "vertical", "Unit", staff_only=True) - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.staff_only) self._verify_visibility_state( xblock_info, VisibilityState.staff_only, path=self.FIRST_SUBSECTION_PATH @@ -4276,7 +4276,7 @@ def test_staff_only_unit(self): xblock_info, True, path=self.FIRST_UNIT_PATH ) - vertical_info = self._get_xblock_info(vertical.location) + vertical_info = self._get_xblock_info(vertical.usage_key) add_container_page_publishing_info(vertical, vertical_info) self.assertEqual( _xblock_type_and_display_name(vertical), vertical_info["staff_lock_from"] @@ -4288,9 +4288,9 @@ def test_unscheduled_section_with_live_subsection(self): self._create_child(sequential, "vertical", "Published Unit", publish_item=True) self._create_child(sequential, "vertical", "Staff Only Unit", staff_only=True) self._set_release_date( - sequential.location, datetime.now(UTC) - timedelta(days=1) + sequential.usage_key, datetime.now(UTC) - timedelta(days=1) ) - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.needs_attention) self._verify_visibility_state( xblock_info, VisibilityState.live, path=self.FIRST_SUBSECTION_PATH @@ -4307,11 +4307,11 @@ def test_unreleased_section_with_live_subsection(self): sequential = self._create_child(chapter, "sequential", "Test Sequential") self._create_child(sequential, "vertical", "Published Unit", publish_item=True) self._create_child(sequential, "vertical", "Staff Only Unit", staff_only=True) - self._set_release_date(chapter.location, datetime.now(UTC) + timedelta(days=1)) + self._set_release_date(chapter.usage_key, datetime.now(UTC) + timedelta(days=1)) self._set_release_date( - sequential.location, datetime.now(UTC) - timedelta(days=1) + sequential.usage_key, datetime.now(UTC) - timedelta(days=1) ) - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.needs_attention) self._verify_visibility_state( xblock_info, VisibilityState.live, path=self.FIRST_SUBSECTION_PATH @@ -4332,7 +4332,7 @@ def test_locked_section_staff_only_message(self): ) sequential = self._create_child(chapter, "sequential", "Test Sequential") self._create_child(sequential, "vertical", "Unit") - xblock_info = self._get_xblock_outline_info(chapter.location) + xblock_info = self._get_xblock_outline_info(chapter.usage_key) self._verify_has_staff_only_message(xblock_info, True) self._verify_has_staff_only_message( xblock_info, False, path=self.FIRST_SUBSECTION_PATH @@ -4348,7 +4348,7 @@ def test_locked_unit_staff_only_message(self): chapter = self._create_child(self.course, "chapter", "Test Chapter") sequential = self._create_child(chapter, "sequential", "Test Sequential") self._create_child(sequential, "vertical", "Unit", staff_only=True) - xblock_info = self._get_xblock_outline_info(chapter.location) + xblock_info = self._get_xblock_outline_info(chapter.usage_key) self._verify_has_staff_only_message(xblock_info, True) self._verify_has_staff_only_message( xblock_info, True, path=self.FIRST_SUBSECTION_PATH @@ -4367,10 +4367,10 @@ def test_self_paced_item_visibility_state(self): # Create course, chapter and setup future release date to make chapter in scheduled state course = CourseFactory.create() chapter = self._create_child(course, "chapter", "Test Chapter") - self._set_release_date(chapter.location, datetime.now(UTC) + timedelta(days=1)) + self._set_release_date(chapter.usage_key, datetime.now(UTC) + timedelta(days=1)) # Check that chapter has scheduled state - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.ready) self.assertFalse(course.self_paced) @@ -4380,7 +4380,7 @@ def test_self_paced_item_visibility_state(self): self.assertTrue(course.self_paced) # Check that in self paced course content has live state now - xblock_info = self._get_xblock_info(chapter.location) + xblock_info = self._get_xblock_info(chapter.usage_key) self._verify_visibility_state(xblock_info, VisibilityState.live) @@ -4429,7 +4429,7 @@ def create_source_block(self, course): self.store.update_item(source_block, self.user.id, asides=[aside]) # quick sanity checks - source_block = self.store.get_item(source_block.location) + source_block = self.store.get_item(source_block.usage_key) self.assertEqual(source_block.due, datetime(2010, 11, 22, 4, 0, tzinfo=UTC)) self.assertEqual(source_block.display_name, "Source Block") self.assertEqual( @@ -4473,7 +4473,7 @@ def test_update_from_source(self): destination_block=destination_block, user_id=user.id, ) - self.check_updated(source_block, destination_block.location) + self.check_updated(source_block, destination_block.usage_key) @XBlockAside.register_temp_plugin(AsideTest, "test_aside") def test_update_clobbers(self): @@ -4507,7 +4507,7 @@ def test_update_clobbers(self): destination_block=destination_block, user_id=user.id, ) - self.check_updated(source_block, destination_block.location) + self.check_updated(source_block, destination_block.usage_key) class TestXblockEditView(CourseTestCase): @@ -4530,7 +4530,7 @@ def setUp(self): self.video = self._create_block(self.child_vertical, "video", "My Video") self.store = modulestore() - self.store.publish(self.vertical.location, self.user.id) + self.store.publish(self.vertical.usage_key, self.user.id) def _create_block(self, parent, category, display_name, **kwargs): """ @@ -4546,7 +4546,7 @@ def _create_block(self, parent, category, display_name, **kwargs): ) def test_xblock_edit_view(self): - url = reverse_usage_url("xblock_edit_handler", self.video.location) + url = reverse_usage_url("xblock_edit_handler", self.video.usage_key) resp = self.client.get_html(url) self.assertEqual(resp.status_code, 200) @@ -4554,7 +4554,7 @@ def test_xblock_edit_view(self): self.assertIn("var decodedActionName = 'edit';", html_content) def test_xblock_edit_view_contains_resources(self): - url = reverse_usage_url("xblock_edit_handler", self.video.location) + url = reverse_usage_url("xblock_edit_handler", self.video.usage_key) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) diff --git a/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py b/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py index ba6d0b243165..9d4f23421b8a 100644 --- a/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py +++ b/cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py @@ -93,14 +93,14 @@ def test_copy_and_paste_unit(self): # Paste the unit paste_response = client.post(XBLOCK_ENDPOINT, { - "parent_locator": str(dest_sequential.location), + "parent_locator": str(dest_sequential.usage_key), "staged_content": "clipboard", }, format="json") assert paste_response.status_code == 200 dest_unit_key = UsageKey.from_string(paste_response.json()["locator"]) # Now there should be a one unit/vertical as a child of the destination sequential/subsection: - updated_sequential = self.store.get_item(dest_sequential.location) + updated_sequential = self.store.get_item(dest_sequential.usage_key) assert updated_sequential.children == [dest_unit_key] # And it should match the original: orig_unit = self.store.get_item(unit_key) @@ -124,7 +124,7 @@ def test_copy_and_paste_component(self, block_args): Test copying a component (XBlock) from one course into another """ source_course = CourseFactory.create(display_name='Source Course') - source_block = BlockFactory.create(parent_location=source_course.location, **block_args) + source_block = BlockFactory.create(parent_location=source_course.usage_key, **block_args) dest_course = CourseFactory.create(display_name='Destination Course') with self.store.bulk_operations(dest_course.id): @@ -134,12 +134,12 @@ def test_copy_and_paste_component(self, block_args): # Copy the block client = APIClient() client.login(username=self.user.username, password=self.user_password) - copy_response = client.post(CLIPBOARD_ENDPOINT, {"usage_key": str(source_block.location)}, format="json") + copy_response = client.post(CLIPBOARD_ENDPOINT, {"usage_key": str(source_block.usage_key)}, format="json") assert copy_response.status_code == 200 # Paste the unit paste_response = client.post(XBLOCK_ENDPOINT, { - "parent_locator": str(dest_sequential.location), + "parent_locator": str(dest_sequential.usage_key), "staged_content": "clipboard", }, format="json") assert paste_response.status_code == 200 @@ -148,7 +148,7 @@ def test_copy_and_paste_component(self, block_args): dest_block = self.store.get_item(dest_block_key) assert dest_block.display_name == source_block.display_name # The new block should store a reference to where it was copied from - assert dest_block.copied_from_block == str(source_block.location) + assert dest_block.copied_from_block == str(source_block.usage_key) def _setup_tagged_content(self, course_key) -> dict: """ @@ -163,14 +163,14 @@ def _setup_tagged_content(self, course_key) -> dict: category='discussion', display_name='Toy_forum', publish_item=True, - ).location + ).usage_key with self.store.bulk_operations(course_key): html_block_key = BlockFactory.create( parent=self.store.get_item(unit_key), category="html", display_name="Toy_text", publish_item=True, - ).location + ).usage_key library = ClipboardPasteFromV1LibraryTestCase.setup_library() with self.store.bulk_operations(course_key): @@ -180,7 +180,7 @@ def _setup_tagged_content(self, course_key) -> dict: source_library_id=str(library.context_key), display_name="LC Block", publish_item=True, - ).location + ).usage_key # Add tags to the unit taxonomy_all_org = tagging_api.create_taxonomy( @@ -290,7 +290,7 @@ def test_copy_and_paste_unit_with_tags(self): # Paste the unit paste_response = client.post(XBLOCK_ENDPOINT, { - "parent_locator": str(dest_sequential.location), + "parent_locator": str(dest_sequential.usage_key), "staged_content": "clipboard", }, format="json") assert paste_response.status_code == 200 @@ -351,7 +351,7 @@ def test_paste_with_assets(self): target_filename="picture2.jpg", ) source_html = BlockFactory.create( - parent_location=source_course.location, + parent_location=source_course.usage_key, category="html", display_name="Some HTML", data=""" @@ -373,7 +373,7 @@ def test_paste_with_assets(self): ) # Now copy the HTML block from the source cost and paste it into the destination: - copy_response = client.post(CLIPBOARD_ENDPOINT, {"usage_key": str(source_html.location)}, format="json") + copy_response = client.post(CLIPBOARD_ENDPOINT, {"usage_key": str(source_html.usage_key)}, format="json") assert copy_response.status_code == 200 # Paste the video @@ -646,13 +646,13 @@ def test_paste_library_content_block(self): """ # Copy a library content block that has children: copy_response = self.client.post(CLIPBOARD_ENDPOINT, { - "usage_key": str(self.orig_lc_block.location) + "usage_key": str(self.orig_lc_block.usage_key) }, format="json") assert copy_response.status_code == 200 # Paste the Library content block: paste_response = self.client.post(XBLOCK_ENDPOINT, { - "parent_locator": str(self.course.location), + "parent_locator": str(self.course.usage_key), "staged_content": "clipboard", }, format="json") assert paste_response.status_code == 200 @@ -667,14 +667,14 @@ def test_paste_library_content_block(self): # Otherwise, user state saved against this child will be lost when it syncs. self._sync_lc_block_from_library('dest_lc_block') updated_dest_child = self.store.get_item(self.dest_lc_block.children[0]) - assert dest_child.location == updated_dest_child.location + assert dest_child.usage_key == updated_dest_child.usage_key def _sync_lc_block_from_library(self, attr_name): """ Helper method to "sync" a Library Content Block by [re-]fetching its children from the library. """ - usage_key = getattr(self, attr_name).location + usage_key = getattr(self, attr_name).usage_key # It's easiest to do this via the REST API: handler_url = reverse_usage_url('preview_handler', usage_key, kwargs={'handler': 'upgrade_and_sync'}) response = self.client.post(handler_url) diff --git a/cms/djangoapps/contentstore/views/tests/test_container_page.py b/cms/djangoapps/contentstore/views/tests/test_container_page.py index e6b58257b69d..9ba1264aa48c 100644 --- a/cms/djangoapps/contentstore/views/tests/test_container_page.py +++ b/cms/djangoapps/contentstore/views/tests/test_container_page.py @@ -55,20 +55,20 @@ def setUp(self): self.unreleased_public_vertical = self._create_block( parent=self.sequential, category='vertical', display_name='Unreleased Public Unit', start=future) - self.store.publish(self.unreleased_public_vertical.location, self.user.id) - self.store.publish(self.released_public_vertical.location, self.user.id) - self.store.publish(self.vertical.location, self.user.id) + self.store.publish(self.unreleased_public_vertical.usage_key, self.user.id) + self.store.publish(self.released_public_vertical.usage_key, self.user.id) + self.store.publish(self.vertical.usage_key, self.user.id) def test_container_html(self): assets_url = reverse( - 'assets_handler', kwargs={'course_key_string': str(self.child_container.location.course_key)} + 'assets_handler', kwargs={'course_key_string': str(self.child_container.usage_key.course_key)} ) self._test_html_content( self.child_container, expected_section_tag=( '