Commit 569ac193 by Nimisha Asthagiri

Merge pull request #12547 from edx/naa/hotfix-course-blocks-management-command

Support force update param in generate_course_blocks Management Command
parents 4ace1d2b 16f89dda
......@@ -8,7 +8,7 @@ from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from xmodule.modulestore.django import modulestore
from ...api import get_course_in_cache
from ...api import get_course_in_cache, update_course_in_cache
log = logging.getLogger(__name__)
......@@ -39,6 +39,12 @@ class Command(BaseCommand):
action='store_true',
default=False,
)
parser.add_argument(
'--force',
help='Force update of the course blocks for the requested courses.',
action='store_true',
default=False,
)
def handle(self, *args, **options):
......@@ -57,7 +63,10 @@ class Command(BaseCommand):
for course_key in course_keys:
try:
block_structure = get_course_in_cache(course_key)
if options.get('force'):
block_structure = update_course_in_cache(course_key)
else:
block_structure = get_course_in_cache(course_key)
if options.get('dags'):
self._find_and_log_dags(block_structure, course_key)
except Exception as ex: # pylint: disable=broad-except
......
......@@ -44,6 +44,21 @@ class TestGenerateCourseBlocks(ModuleStoreTestCase):
self._assert_courses_not_in_block_cache(self.course_1.id, self.course_2.id)
self.command.handle(all=True)
self._assert_courses_in_block_cache(self.course_1.id, self.course_2.id)
with patch(
'openedx.core.lib.block_structure.factory.BlockStructureFactory.create_from_modulestore'
) as mock_update_from_store:
self.command.handle(all=True)
mock_update_from_store.assert_not_called()
def test_generate_force(self):
self._assert_courses_not_in_block_cache(self.course_1.id, self.course_2.id)
self.command.handle(all=True)
self._assert_courses_in_block_cache(self.course_1.id, self.course_2.id)
with patch(
'openedx.core.lib.block_structure.factory.BlockStructureFactory.create_from_modulestore'
) as mock_update_from_store:
self.command.handle(all=True, force=True)
mock_update_from_store.assert_called()
def test_generate_one(self):
self._assert_courses_not_in_block_cache(self.course_1.id, self.course_2.id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment