def test_end_to_end(self): """Normal invocation, it should skip only the Old Mongo course.""" # In the beginning, we have no outlines... assert not get_course_keys_with_outlines().exists() # Run command and outlines appear for Split Mongo courses... call_command("backfill_course_outlines") course_keys_with_outlines = set(get_course_keys_with_outlines()) assert course_keys_with_outlines == { CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2"), CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run3"), }
def handle(self, *args, **options): dry_run = options.get('dry', False) force_all = options.get('force', False) log.info("Starting backfill_course_outlines: dry=%s, force=%s", dry_run, force_all) all_course_keys_qs = CourseOverview.objects.values_list('id', flat=True) if force_all: target_courses_qs = all_course_keys_qs log.info("Forcing re-generation for all %d course runs.", len(target_courses_qs)) else: # .difference() is not supported in MySQL, but this at least does the # SELECT NOT IN... subquery in the database rather than Python. target_courses_qs = all_course_keys_qs.exclude( id__in=get_course_keys_with_outlines()) log.info("Found %d courses without outlines.", len(target_courses_qs)) for course_key in target_courses_qs: if key_supports_outlines(course_key): log.info("Queuing outline creation for %s", course_key) if not dry_run: update_outline_from_modulestore_task.delay(str(course_key)) else: log.info("Outlines not supported for %s - skipping", course_key)
def test_partial(self): """Also works when we've manually created one in advance.""" course_keys_with_outlines = set(get_course_keys_with_outlines()) assert not get_course_keys_with_outlines().exists() # Manually create one update_outline_from_modulestore( CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2")) assert set(get_course_keys_with_outlines()) == { CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2") } # backfill command should fill in the other call_command("backfill_course_outlines") course_keys_with_outlines = set(get_course_keys_with_outlines()) assert course_keys_with_outlines == { CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2"), CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run3"), }
def handle(self, *args, **options): dry_run = options.get('dry', False) log.info("Starting backfill_course_outlines{}".format( " (dry run)" if dry_run else "")) all_course_keys_qs = CourseOverview.objects.values_list('id', flat=True) # .difference() is not supported in MySQL, but this at least does the # SELECT NOT IN... subquery in the database rather than Python. missing_outlines_qs = all_course_keys_qs.exclude( id__in=get_course_keys_with_outlines()) num_courses_needing_outlines = len(missing_outlines_qs) log.info("Found %d courses without outlines. Queuing tasks...", num_courses_needing_outlines) for course_key in missing_outlines_qs: if key_supports_outlines(course_key): log.info("Queuing outline creation for %s", course_key) if not dry_run: update_outline_from_modulestore_task.delay(str(course_key)) else: log.info("Outlines not supported for %s - skipping", course_key)