From fb5904f776c1b3414b90d36821c9d8db95646e3a Mon Sep 17 00:00:00 2001 From: Douglas Hall Date: Wed, 4 Apr 2018 15:45:24 -0400 Subject: [PATCH] Remove uses of the course_structure API. --- cms/djangoapps/contentstore/views/course.py | 19 ++++-- .../views/tests/test_course_index.py | 68 ------------------- 2 files changed, 12 insertions(+), 75 deletions(-) diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index d8a45c0fa9..ae93fca32a 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -5,6 +5,7 @@ import copy import json import logging import random +import re import string # pylint: disable=deprecated-module import django.utils @@ -56,7 +57,6 @@ from milestones import api as milestones_api from models.settings.course_grading import CourseGradingModel from models.settings.course_metadata import CourseMetadata from models.settings.encoder import CourseSettingsEncoder -from openedx.core.djangoapps.content.course_structures.api.v0 import api, errors from openedx.core.djangoapps.credit.api import get_credit_requirements, is_credit_course from openedx.core.djangoapps.credit.tasks import update_credit_course_requirements from openedx.core.djangoapps.models.course_details import CourseDetails @@ -586,13 +586,18 @@ def _deprecated_blocks_info(course_module, deprecated_block_types): 'advance_settings_url': reverse_course_url('advanced_settings_handler', course_module.id) } - try: - structure_data = api.course_structure(course_module.id, block_types=deprecated_block_types) - except errors.CourseStructureNotAvailableError: - return data + deprecated_blocks = modulestore().get_items( + course_module.id, + qualifiers={ + 'category': re.compile('^' + '$|^'.join(deprecated_block_types) + '$') + } + ) - for block in structure_data['blocks'].values(): - data['blocks'].append([reverse_usage_url('container_handler', block['parent']), block['display_name']]) + for block in deprecated_blocks: + data['blocks'].append([ + reverse_usage_url('container_handler', block.parent), + block.display_name + ]) return data diff --git a/cms/djangoapps/contentstore/views/tests/test_course_index.py b/cms/djangoapps/contentstore/views/tests/test_course_index.py index dababa230e..a3b899f801 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_index.py @@ -628,74 +628,6 @@ class TestCourseOutline(CourseTestCase): expected_block_types ) - @ddt.data( - {'delete_vertical': True}, - {'delete_vertical': False}, - ) - @ddt.unpack - def test_deprecated_blocks_list_updated_correctly(self, delete_vertical): - """ - Verify that deprecated blocks list shown on banner is updated correctly. - - Here is the scenario: - This list of deprecated blocks shown on banner contains published - and un-published blocks. That list should be updated when we delete - un-published block(s). This behavior should be same if we delete - unpublished vertical or problem. - """ - block_types = ['notes'] - course_module = modulestore().get_item(self.course.location) - - vertical1 = ItemFactory.create( - parent_location=self.sequential.location, category='vertical', display_name='Vert1 Subsection1' - ) - problem1 = ItemFactory.create( - parent_location=vertical1.location, - category='notes', - display_name='notes problem in vert1', - publish_item=False - ) - - info = _deprecated_blocks_info(course_module, block_types) - # info['blocks'] should be empty here because there is nothing - # published or un-published present - self.assertEqual(info['blocks'], []) - - vertical2 = ItemFactory.create( - parent_location=self.sequential.location, category='vertical', display_name='Vert2 Subsection1' - ) - ItemFactory.create( - parent_location=vertical2.location, - category='notes', - display_name='notes problem in vert2', - pubish_item=True - ) - # At this point CourseStructure will contain both the above - # published and un-published verticals - - info = _deprecated_blocks_info(course_module, block_types) - self.assertItemsEqual( - info['blocks'], - [ - [reverse_usage_url('container_handler', vertical1.location), 'notes problem in vert1'], - [reverse_usage_url('container_handler', vertical2.location), 'notes problem in vert2'] - ] - ) - - # Delete the un-published vertical or problem so that CourseStructure updates its data - if delete_vertical: - self.store.delete_item(vertical1.location, self.user.id) - else: - self.store.delete_item(problem1.location, self.user.id) - - info = _deprecated_blocks_info(course_module, block_types) - # info['blocks'] should only contain the info about vertical2 which is published. - # There shouldn't be any info present about un-published vertical1 - self.assertEqual( - info['blocks'], - [[reverse_usage_url('container_handler', vertical2.location), 'notes problem in vert2']] - ) - class TestCourseReIndex(CourseTestCase): """