Merge pull request #26988 from edx/AA-461

[AA-461] Add management command to export course metadata for all courses
This commit is contained in:
Matthew Piatetsky
2021-03-15 10:57:59 -04:00
committed by GitHub
5 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
"""
Export course metadata for all courses
"""
from django.core.management.base import BaseCommand
from xmodule.modulestore.django import modulestore
from cms.djangoapps.export_course_metadata.signals import export_course_metadata
class Command(BaseCommand):
"""
Export course metadata for all courses
"""
help = 'Export course metadata for all courses'
def handle(self, *args, **options):
"""
Execute the command
"""
export_course_metadata_for_all_courses()
def export_course_metadata_for_all_courses():
"""
Export course metadata for all courses
"""
module_store = modulestore()
courses = module_store.get_courses()
for course in courses:
export_course_metadata(None, course.id)

View File

@@ -0,0 +1,32 @@
"""
Tests for exporting course metadata for all courses.
"""
from unittest.mock import patch
from edx_toggles.toggles.testutils import override_waffle_flag
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from cms.djangoapps.export_course_metadata.toggles import EXPORT_COURSE_METADATA_FLAG
from ..export_course_metadata_for_all_courses import export_course_metadata_for_all_courses
@override_waffle_flag(EXPORT_COURSE_METADATA_FLAG, True)
class ExportAllCourses(ModuleStoreTestCase):
"""
Tests for exporting course metadata for all courses.
"""
def setUp(self):
super().setUp()
CourseFactory.create()
CourseFactory.create()
@patch('cms.djangoapps.export_course_metadata.tasks.course_metadata_export_storage.save')
def test_exporting_all_courses(self, patched_storage):
"""
Test for exporting course metadata for all courses.
"""
export_course_metadata_for_all_courses()
assert len(patched_storage.mock_calls) == 2