Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.content.learning_sequences.api import get_course_keys_with_outlines
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order

Expand Down Expand Up @@ -40,47 +39,40 @@ def setUpClass(cls):
"""
super().setUpClass()
course_run_ids = [
"OpenEdX/OutlineCourse/OldMongoRun1",
"course-v1:OpenEdX+OutlineCourse+Run1",
"course-v1:OpenEdX+OutlineCourse+Run2",
"course-v1:OpenEdX+OutlineCourse+Run3",
]
cls.course_keys = [
CourseKey.from_string(course_run_id) for course_run_id in course_run_ids
]
for course_key in cls.course_keys:
if course_key.deprecated:
store_type = ModuleStoreEnum.Type.mongo
else:
store_type = ModuleStoreEnum.Type.split

with cls.store.default_store(store_type):
course = CourseFactory.create(
org=course_key.org,
number=course_key.course,
run=course_key.run,
display_name=f"Outline Backfill Test Course {course_key.run}"
course = CourseFactory.create(
org=course_key.org,
number=course_key.course,
run=course_key.run,
display_name=f"Outline Backfill Test Course {course_key.run}"
)
with cls.store.bulk_operations(course_key):
section = ItemFactory.create(
parent=course,
category="chapter",
display_name="A Section"
)
sequence = ItemFactory.create(
parent=section,
category="sequential",
display_name="A Sequence"
)
unit = ItemFactory.create(
parent=sequence,
category="vertical",
display_name="A Unit"
)
ItemFactory.create(
parent=unit,
category="html",
display_name="An HTML Module"
)
with cls.store.bulk_operations(course_key):
section = ItemFactory.create(
parent=course,
category="chapter",
display_name="A Section"
)
sequence = ItemFactory.create(
parent=section,
category="sequential",
display_name="A Sequence"
)
unit = ItemFactory.create(
parent=sequence,
category="vertical",
display_name="A Unit"
)
ItemFactory.create(
parent=unit,
category="html",
display_name="An HTML Module"
)

def test_end_to_end(self):
"""Normal invocation, it should skip only the Old Mongo course."""
Expand All @@ -91,8 +83,8 @@ def test_end_to_end(self):
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+Run1"),
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2"),
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run3"),
}

def test_partial(self):
Expand All @@ -102,16 +94,16 @@ def test_partial(self):

# Manually create one
update_outline_from_modulestore(
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2")
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run1")
)
assert set(get_course_keys_with_outlines()) == {
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2")
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run1")
}

# 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+Run1"),
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run2"),
CourseKey.from_string("course-v1:OpenEdX+OutlineCourse+Run3"),
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""Tests running the delete_orphan command"""


import ddt
from django.core.management import CommandError, call_command

from cms.djangoapps.contentstore.tests.test_orphan import TestOrphanBase
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order


@ddt.ddt
class TestDeleteOrphan(TestOrphanBase):
"""
Tests for running the delete_orphan management command.
Expand All @@ -23,26 +21,24 @@ def test_no_args(self):
with self.assertRaisesRegex(CommandError, errstring):
call_command('delete_orphans')

@ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo)
def test_delete_orphans_no_commit(self, default_store):
def test_delete_orphans_no_commit(self):
"""
Tests that running the command without a '--commit' argument
results in no orphans being deleted
"""
course = self.create_course_with_orphans(default_store)
course = self.create_course_with_orphans(ModuleStoreEnum.Type.split)
call_command('delete_orphans', str(course.id))
self.assertTrue(self.store.has_item(course.id.make_usage_key('html', 'multi_parent_html')))
self.assertTrue(self.store.has_item(course.id.make_usage_key('vertical', 'OrphanVert')))
self.assertTrue(self.store.has_item(course.id.make_usage_key('chapter', 'OrphanChapter')))
self.assertTrue(self.store.has_item(course.id.make_usage_key('html', 'OrphanHtml')))

@ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo)
def test_delete_orphans_commit(self, default_store):
def test_delete_orphans_commit(self):
"""
Tests that running the command WITH the '--commit' argument
results in the orphans being deleted
"""
course = self.create_course_with_orphans(default_store)
course = self.create_course_with_orphans(ModuleStoreEnum.Type.split)

call_command('delete_orphans', str(course.id), '--commit')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import unittest
from tempfile import mkdtemp

import ddt
from django.core.management import CommandError, call_command

from xmodule.modulestore import ModuleStoreEnum
Expand All @@ -29,7 +28,6 @@ def test_no_args(self):
call_command('export')


@ddt.ddt
class TestCourseExport(ModuleStoreTestCase):
"""
Test exporting a course
Expand All @@ -45,16 +43,15 @@ def setUp(self):
self.addCleanup(shutil.rmtree, self.temp_dir_1)
self.addCleanup(shutil.rmtree, self.temp_dir_2)

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_export_course_with_directory_name(self, store):
def test_export_course_with_directory_name(self):
"""
Create a new course try exporting in a path specified
"""
course = CourseFactory.create(default_store=store)
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
course_id = str(course.id)
self.assertTrue(
modulestore().has_course(course.id),
f"Could not find course in {store}"
f"Could not find course in {ModuleStoreEnum.Type.split}"
)
# Test `export` management command with invalid course_id
errstring = "Invalid course_key: 'InvalidCourseID'."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from io import StringIO
from tempfile import mkdtemp

import ddt
from django.core.management import CommandError, call_command
from path import Path as path

Expand All @@ -32,7 +31,6 @@ def test_no_args(self):
call_command('export_olx')


@ddt.ddt
class TestCourseExportOlx(ModuleStoreTestCase):
"""
Test exporting OLX content from a course or library.
Expand Down Expand Up @@ -74,9 +72,8 @@ def check_export_file(self, tar_file, course_key):
self.assertIn(f"{dirname}/assets/assets.xml", names)
self.assertIn(f"{dirname}/policies", names)

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_export_course(self, store_type):
test_course_key = self.create_dummy_course(store_type)
def test_export_course(self):
test_course_key = self.create_dummy_course(ModuleStoreEnum.Type.split)
tmp_dir = path(mkdtemp())
self.addCleanup(shutil.rmtree, tmp_dir)
filename = tmp_dir / 'test.tar.gz'
Expand All @@ -91,9 +88,8 @@ def test_export_course(self, store_type):
# django this is fixed. Howevere it's not possible to get this test to
# pass in Python3 and django 1.11
@unittest.skip("Bug in django 1.11 prevents this from working in python3. Re-enable after django 2.x upgrade.")
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_export_course_stdout(self, store_type):
test_course_key = self.create_dummy_course(store_type)
def test_export_course_stdout(self):
test_course_key = self.create_dummy_course(ModuleStoreEnum.Type.split)
out = StringIO()
call_command('export_olx', str(test_course_key), stdout=out)
out.seek(0)
Expand Down
Loading