From 509522414a17ba4fa5145c7adce8b98c10b7829b Mon Sep 17 00:00:00 2001 From: muzaffaryousaf Date: Tue, 16 Feb 2016 16:55:12 +0500 Subject: [PATCH] Using display_name_with_default instead of display_name. TNL-4103 --- openedx/core/djangoapps/bookmarks/models.py | 3 +- openedx/core/djangoapps/bookmarks/tasks.py | 2 +- .../djangoapps/bookmarks/tests/test_tasks.py | 34 ++++++++++++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/openedx/core/djangoapps/bookmarks/models.py b/openedx/core/djangoapps/bookmarks/models.py index df52fbac09..a6b9c1cd88 100644 --- a/openedx/core/djangoapps/bookmarks/models.py +++ b/openedx/core/djangoapps/bookmarks/models.py @@ -177,9 +177,8 @@ class Bookmark(TimeStampedModel): block = modulestore().get_item(ancestor_usage_key) except ItemNotFoundError: return [] # No valid path can be found. - path_data.append( - PathItem(usage_key=block.location, display_name=block.display_name) + PathItem(usage_key=block.location, display_name=block.display_name_with_default) ) return path_data diff --git a/openedx/core/djangoapps/bookmarks/tasks.py b/openedx/core/djangoapps/bookmarks/tasks.py index 14c7a87fc7..5443e29fe5 100644 --- a/openedx/core/djangoapps/bookmarks/tasks.py +++ b/openedx/core/djangoapps/bookmarks/tasks.py @@ -32,7 +32,7 @@ def _calculate_course_xblocks_data(course_key): usage_id = unicode(current_block.scope_ids.usage_id) block_info = { 'usage_key': current_block.scope_ids.usage_id, - 'display_name': current_block.display_name, + 'display_name': current_block.display_name_with_default, 'children_ids': [unicode(child.scope_ids.usage_id) for child in children] } blocks_info_dict[usage_id] = block_info diff --git a/openedx/core/djangoapps/bookmarks/tests/test_tasks.py b/openedx/core/djangoapps/bookmarks/tests/test_tasks.py index 600cf0de45..8aefa79201 100644 --- a/openedx/core/djangoapps/bookmarks/tests/test_tasks.py +++ b/openedx/core/djangoapps/bookmarks/tests/test_tasks.py @@ -4,7 +4,7 @@ Tests for tasks. import ddt from xmodule.modulestore import ModuleStoreEnum -from xmodule.modulestore.tests.factories import check_mongo_calls +from xmodule.modulestore.tests.factories import check_mongo_calls, ItemFactory from ..models import XBlockCache from ..tasks import _calculate_course_xblocks_data, _update_xblocks_cache @@ -164,3 +164,35 @@ class XBlockCacheTaskTests(BookmarksTestsBase): with self.assertNumQueries(3): _update_xblocks_cache(course.id) + + def test_update_xblocks_cache_with_display_name_none(self): + """ + Test that the xblocks data is persisted correctly with display_name=None. + """ + block_with_display_name_none = ItemFactory.create( + parent_location=self.sequential_2.location, + category='vertical', display_name=None + ) + + _update_xblocks_cache(self.course.id) + + self.course_expected_cache_data.update( + { + block_with_display_name_none.location: [ + [ + self.course.location, + self.chapter_1.location, + self.sequential_2.location, + ] + ] + } + ) + + for usage_key, __ in self.course_expected_cache_data.items(): + xblock_cache = XBlockCache.objects.get(usage_key=usage_key) + for path_index, path in enumerate(xblock_cache.paths): + for path_item_index, path_item in enumerate(path): + self.assertEqual( + path_item.usage_key, + self.course_expected_cache_data[usage_key][path_index][path_item_index + 1] + )