Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] EDXOLDMNG-110 Modify StaticContentServer middleware #2459

Closed

This file was deleted.

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,41 @@ 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 +84,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 +95,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
Expand Up @@ -4,6 +4,8 @@
"""


from unittest import skip

from django.conf import settings
from django.core.management import call_command
from opaque_keys.edx.keys import CourseKey
Expand All @@ -20,6 +22,7 @@
TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT


@skip("OldMongo Deprecation")
class ExportAllCourses(ModuleStoreTestCase):
"""
Tests assets cleanup for all courses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,23 @@ class TestCreateCourse(ModuleStoreTestCase):
Unit tests for creating a course in either old mongo or split mongo via command line
"""

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_all_stores_user_email(self, store):
def test_all_stores_user_email(self):
call_command(
"create_course",
store,
ModuleStoreEnum.Type.split,
str(self.user.email),
"org", "course", "run", "dummy-course-name"
)
new_key = modulestore().make_course_key("org", "course", "run")
self.assertTrue(
modulestore().has_course(new_key),
f"Could not find course in {store}"
f"Could not find course in {ModuleStoreEnum.Type.split}"
)
# pylint: disable=protected-access
self.assertEqual(store, modulestore()._get_modulestore_for_courselike(new_key).get_modulestore_type())
self.assertEqual(
ModuleStoreEnum.Type.split,
modulestore()._get_modulestore_for_courselike(new_key).get_modulestore_type()
)

def test_duplicate_course(self):
"""
Expand All @@ -85,8 +87,7 @@ def test_duplicate_course(self):
expected = "Course already exists"
self.assertIn(out.getvalue().strip(), expected)

@ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo)
def test_get_course_with_different_case(self, default_store):
def test_get_course_with_different_case(self):
"""
Tests that course can not be accessed with different case.

Expand All @@ -98,21 +99,20 @@ def test_get_course_with_different_case(self, default_store):
org = 'org1'
number = 'course1'
run = 'run1'
with self.store.default_store(default_store):
lowercase_course_id = self.store.make_course_key(org, number, run)
with self.store.bulk_operations(lowercase_course_id, ignore_case=True):
# Create course with lowercase key & Verify that store returns course.
self.store.create_course(
lowercase_course_id.org,
lowercase_course_id.course,
lowercase_course_id.run,
self.user.id
)
course = self.store.get_course(lowercase_course_id)
self.assertIsNotNone(course, 'Course not found using lowercase course key.')
self.assertEqual(str(course.id), str(lowercase_course_id))

# Verify store does not return course with different case.
uppercase_course_id = self.store.make_course_key(org.upper(), number.upper(), run.upper())
course = self.store.get_course(uppercase_course_id)
self.assertIsNone(course, 'Course should not be accessed with uppercase course id.')
lowercase_course_id = self.store.make_course_key(org, number, run)
with self.store.bulk_operations(lowercase_course_id, ignore_case=True):
# Create course with lowercase key & Verify that store returns course.
self.store.create_course(
lowercase_course_id.org,
lowercase_course_id.course,
lowercase_course_id.run,
self.user.id
)
course = self.store.get_course(lowercase_course_id)
self.assertIsNotNone(course, 'Course not found using lowercase course key.')
self.assertEqual(str(course.id), str(lowercase_course_id))

# Verify store does not return course with different case.
uppercase_course_id = self.store.make_course_key(org.upper(), number.upper(), run.upper())
course = self.store.get_course(uppercase_course_id)
self.assertIsNone(course, 'Course should not be accessed with uppercase course id.')
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,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 @@ -45,16 +45,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()
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 @@ -5,6 +5,7 @@

import shutil
from tempfile import mkdtemp
from unittest import skip

from cms.djangoapps.contentstore.management.commands.export_all_courses import export_courses_to_output_path
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
Expand All @@ -13,6 +14,7 @@
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order


@skip("OldMongo Deprecation")
class ExportAllCourses(ModuleStoreTestCase):
"""
Tests exporting all courses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,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 +90,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)
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ def test_no_args(self):
with self.assertRaisesRegex(CommandError, msg):
call_command('fix_not_found')

def test_fix_not_found_non_split(self):
"""
The management command doesn't work on non split courses
"""
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo)
with self.assertRaisesRegex(CommandError, "The owning modulestore does not support this command."):
call_command("fix_not_found", str(course.id))

def test_fix_not_found(self):
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
ItemFactory.create(category='chapter', parent_location=course.location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ def test_course_key_not_found(self):
with self.assertRaisesRegex(CommandError, errstring):
call_command('force_publish', 'course-v1:org+course+run')

def test_force_publish_non_split(self):
"""
Test 'force_publish' command doesn't work on non split courses
"""
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo)
errstring = 'The owning modulestore does not support this command.'
with self.assertRaisesRegex(CommandError, errstring):
call_command('force_publish', str(course.id))


class TestForcePublishModifications(ModuleStoreTestCase):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_bad_git_repos(self):
course_key,
'https://user:[email protected]/r.git')

@unittest.skip("OldMongo Deprecation")
@unittest.skipIf(os.environ.get('GIT_CONFIG') or
os.environ.get('GIT_AUTHOR_EMAIL') or
os.environ.get('GIT_AUTHOR_NAME') or
Expand Down
Loading