Skip to content

Commit 7a21c22

Browse files
authored
test: updated test_import.py and test_course_index.py for split modulestore
This is part of Old Mongo removal. Also in this commit: * fixed 400 error for cms old_style assets * fix TEST_DATA_SPLIT_MODULESTORE import for test_course_index
1 parent d846ea8 commit 7a21c22

4 files changed

Lines changed: 60 additions & 43 deletions

File tree

‎cms/djangoapps/contentstore/tests/test_import.py‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
import copy
8+
from unittest import skip
89
from unittest.mock import patch
910
from uuid import uuid4
1011

@@ -174,29 +175,29 @@ def test_tab_name_imports_correctly(self):
174175
print(f"course tabs = {course.tabs}")
175176
self.assertEqual(course.tabs[1]['name'], 'Syllabus')
176177

177-
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
178-
def test_reimport(self, default_ms_type):
179-
with modulestore().default_store(default_ms_type):
180-
__, __, course = self.load_test_import_course(create_if_not_present=True)
181-
self.load_test_import_course(target_id=course.id)
178+
def test_reimport(self):
179+
__, __, course = self.load_test_import_course(create_if_not_present=True)
180+
self.load_test_import_course(target_id=course.id)
182181

182+
@skip("OldMongo Deprecation")
183183
def test_rewrite_reference_list(self):
184184
# This test fails with split modulestore (the HTML component is not in "different_course_id" namespace).
185185
# More investigation needs to be done.
186-
module_store = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.mongo)
186+
module_store = modulestore()
187187
target_id = module_store.make_course_key('testX', 'conditional_copy', 'copy_run')
188188
import_course_from_xml(
189189
module_store,
190190
self.user.id,
191191
TEST_DATA_DIR,
192192
['conditional'],
193-
target_id=target_id
193+
target_id=target_id,
194+
create_if_not_present=True
194195
)
195196
conditional_block = module_store.get_item(
196197
target_id.make_usage_key('conditional', 'condone')
197198
)
198199
self.assertIsNotNone(conditional_block)
199-
different_course_id = module_store.make_course_key('edX', 'different_course', None)
200+
different_course_id = module_store.make_course_key('edX', 'different_course', 'course_run')
200201
self.assertListEqual(
201202
[
202203
target_id.make_usage_key('problem', 'choiceprob'),
@@ -256,22 +257,20 @@ def _verify_split_test_import(self, target_course_name, source_course_name, spli
256257

257258
self.assertEqual(remapped_verticals, split_test_block.group_id_to_child)
258259

259-
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
260-
def test_video_components_present_while_import(self, store):
260+
def test_video_components_present_while_import(self):
261261
"""
262262
Test that video components with same edx_video_id are present while re-importing
263263
"""
264-
with modulestore().default_store(store):
265-
module_store = modulestore()
266-
course_id = module_store.make_course_key('edX', 'test_import_course', '2012_Fall')
264+
module_store = modulestore()
265+
course_id = module_store.make_course_key('edX', 'test_import_course', '2012_Fall')
267266

268-
# Import first time
269-
__, __, course = self.load_test_import_course(target_id=course_id, module_store=module_store)
267+
# Import first time
268+
__, __, course = self.load_test_import_course(target_id=course_id, module_store=module_store)
270269

271-
# Re-import
272-
__, __, re_course = self.load_test_import_course(target_id=course.id, module_store=module_store)
270+
# Re-import
271+
__, __, re_course = self.load_test_import_course(target_id=course.id, module_store=module_store)
273272

274-
vertical = module_store.get_item(re_course.id.make_usage_key('vertical', 'vertical_test'))
273+
vertical = module_store.get_item(re_course.id.make_usage_key('vertical', 'vertical_test'))
275274

276-
video = module_store.get_item(vertical.children[1])
277-
self.assertEqual(video.display_name, 'default')
275+
video = module_store.get_item(vertical.children[1])
276+
self.assertEqual(video.display_name, 'default')

‎cms/djangoapps/contentstore/views/tests/test_course_index.py‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import datetime
77
import json
8-
from unittest import SkipTest, mock, skip
8+
from unittest import mock, skip
99
from unittest.mock import patch
1010

1111
import ddt
@@ -35,6 +35,7 @@
3535
from openedx.core.djangoapps.waffle_utils.testutils import WAFFLE_TABLES
3636
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
3737
from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order
38+
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE
3839
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory, LibraryFactory, check_mongo_calls # lint-amnesty, pylint: disable=wrong-import-order
3940

4041
from ..course import _deprecated_blocks_info, course_outline_initial_state, reindex_course_and_check_access
@@ -46,6 +47,8 @@ class TestCourseIndex(CourseTestCase):
4647
Unit tests for getting the list of courses and the course outline.
4748
"""
4849

50+
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
51+
4952
def setUp(self):
5053
"""
5154
Add a course with odd characters in the fields
@@ -333,6 +336,9 @@ class TestCourseIndexArchived(CourseTestCase):
333336
"""
334337
Unit tests for testing the course index list when there are archived courses.
335338
"""
339+
340+
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
341+
336342
NOW = datetime.datetime.now(pytz.utc)
337343
DAY = datetime.timedelta(days=1)
338344
YESTERDAY = NOW - DAY
@@ -415,16 +421,15 @@ def check_index_page(self, separate_archived_courses, org):
415421
archived_course_tab = parsed_html.find_class('archived-courses')
416422
self.assertEqual(len(archived_course_tab), 1 if separate_archived_courses else 0)
417423

418-
@skip('Skip test for old mongo course')
419424
@ddt.data(
420425
# Staff user has course staff access
421426
(True, 'staff', None, 0, 20),
422427
(False, 'staff', None, 0, 20),
423428
# Base user has global staff access
424-
(True, 'user', ORG, 1, 20),
425-
(False, 'user', ORG, 1, 20),
426-
(True, 'user', None, 1, 20),
427-
(False, 'user', None, 1, 20),
429+
(True, 'user', ORG, 2, 20),
430+
(False, 'user', ORG, 2, 20),
431+
(True, 'user', None, 2, 20),
432+
(False, 'user', None, 2, 20),
428433
)
429434
@ddt.unpack
430435
def test_separate_archived_courses(self, separate_archived_courses, username, org, mongo_queries, sql_queries):
@@ -452,6 +457,9 @@ class TestCourseOutline(CourseTestCase):
452457
"""
453458
Unit tests for the course outline.
454459
"""
460+
461+
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
462+
455463
ENABLED_SIGNALS = ['course_published']
456464

457465
def setUp(self):
@@ -550,14 +558,16 @@ def _create_test_data(self, course_block, create_blocks=False, publish=True, blo
550558
if create_blocks:
551559
for block_type in block_types:
552560
BlockFactory.create(
553-
parent_location=self.vertical.location,
561+
parent=self.vertical,
554562
category=block_type,
555563
display_name=f'{block_type} Problem'
556564
)
557565

558566
if not publish:
559567
self.store.unpublish(self.vertical.location, self.user.id)
560568

569+
# get updated vertical
570+
self.vertical = modulestore().get_item(self.vertical.location)
561571
course_block.advanced_modules.extend(block_types)
562572

563573
def _verify_deprecated_info(self, course_id, advanced_modules, info, deprecated_block_types):
@@ -584,6 +594,7 @@ def _verify_deprecated_info(self, course_id, advanced_modules, info, deprecated_
584594
reverse_course_url('advanced_settings_handler', course_id)
585595
)
586596

597+
@skip('OldMongo Deprecation. HiddenDescriptorWithMixins is not created for split.')
587598
@ddt.data(
588599
[{'publish': True}, ['notes']],
589600
[{'publish': False}, ['notes']],
@@ -596,6 +607,9 @@ def test_verify_deprecated_warning_message(self, publish, block_types):
596607
"""
597608
course_block = modulestore().get_item(self.course.location)
598609
self._create_test_data(course_block, create_blocks=True, block_types=block_types, publish=publish)
610+
# get updated course_block
611+
course_block = modulestore().get_item(self.course.location)
612+
599613
info = _deprecated_blocks_info(course_block, block_types)
600614
self._verify_deprecated_info(
601615
course_block.id,
@@ -604,6 +618,7 @@ def test_verify_deprecated_warning_message(self, publish, block_types):
604618
block_types
605619
)
606620

621+
@skip('OldMongo Deprecation. HiddenDescriptorWithMixins is not created for split.')
607622
@ddt.data(
608623
(["a", "b", "c"], ["a", "b", "c"]),
609624
(["a", "b", "c"], ["a", "b", "d"]),
@@ -618,6 +633,8 @@ def test_verify_warn_only_on_enabled_blocks(self, enabled_block_types, deprecate
618633
expected_block_types = list(set(enabled_block_types) & set(deprecated_block_types))
619634
course_block = modulestore().get_item(self.course.location)
620635
self._create_test_data(course_block, create_blocks=True, block_types=enabled_block_types)
636+
# get updated course_module
637+
course_block = modulestore().get_item(self.course.location)
621638
info = _deprecated_blocks_info(course_block, deprecated_block_types)
622639
self._verify_deprecated_info(
623640
course_block.id,
@@ -632,8 +649,6 @@ def test_proctoring_link_is_visible(self, mock_validate_proctoring_settings):
632649
"""
633650
Test to check proctored exam settings mfe url is rendering properly
634651
"""
635-
if self.course.id.deprecated:
636-
raise SkipTest("Skip test for old mongo course")
637652
mock_validate_proctoring_settings.return_value = [
638653
{
639654
'key': 'proctoring_provider',
@@ -655,6 +670,9 @@ class TestCourseReIndex(CourseTestCase):
655670
"""
656671
Unit tests for the course outline.
657672
"""
673+
674+
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
675+
658676
SUCCESSFUL_RESPONSE = _("Course has been successfully reindexed.")
659677

660678
ENABLED_SIGNALS = ['course_published']
@@ -835,7 +853,7 @@ def test_reindex_seq_error_json_responses(self, mock_index_dictionary):
835853
with self.assertRaises(SearchIndexingError):
836854
reindex_course_and_check_access(self.course.id, self.user)
837855

838-
@mock.patch('xmodule.modulestore.mongo.base.MongoModuleStore.get_course')
856+
@mock.patch('xmodule.modulestore.split_mongo.split.SplitMongoModuleStore.get_course')
839857
def test_reindex_no_item(self, mock_get_course):
840858
"""
841859
Test system logs an error if no item found.
@@ -945,7 +963,7 @@ def test_indexing_seq_error_responses(self, mock_index_dictionary):
945963
with self.assertRaises(SearchIndexingError):
946964
CoursewareSearchIndexer.do_course_reindex(modulestore(), self.course.id)
947965

948-
@mock.patch('xmodule.modulestore.mongo.base.MongoModuleStore.get_course')
966+
@mock.patch('xmodule.modulestore.split_mongo.split.SplitMongoModuleStore.get_course')
949967
def test_indexing_no_item(self, mock_get_course):
950968
"""
951969
Test system logs an error if no item found.

‎openedx/core/djangoapps/contentserver/test/test_contentserver.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from xmodule.contentstore.django import contentstore
2121
from xmodule.contentstore.content import StaticContent, VERSIONED_ASSETS_PREFIX
2222
from xmodule.modulestore.django import modulestore
23-
from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_MODULESTORE, SharedModuleStoreTestCase
23+
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase
2424
from xmodule.modulestore.xml_importer import import_course_from_xml
2525
from xmodule.assetstore.assetmgr import AssetManager
2626
from xmodule.modulestore.exceptions import ItemNotFoundError
@@ -73,7 +73,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase):
7373
"""
7474
Tests that use the toy course.
7575
"""
76-
MODULESTORE = TEST_DATA_MONGO_MODULESTORE
76+
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
7777

7878
@classmethod
7979
def setUpClass(cls):
@@ -82,23 +82,23 @@ def setUpClass(cls):
8282
cls.contentstore = contentstore()
8383
cls.modulestore = modulestore()
8484

85-
cls.course_key = cls.modulestore.make_course_key('edX', 'toy', '2012_Fall')
86-
87-
import_course_from_xml(
85+
course_items = import_course_from_xml(
8886
cls.modulestore, 1, TEST_DATA_DIR, ['toy'],
89-
static_content_store=cls.contentstore, verbose=True
87+
static_content_store=cls.contentstore, verbose=True, create_if_not_present=True
9088
)
89+
cls.course = course_items[0]
90+
cls.course_key = cls.course.id
9191

9292
# A locked asset
9393
cls.locked_asset = cls.course_key.make_asset_key('asset', 'sample_static.html')
94-
cls.url_locked = str(cls.locked_asset)
94+
cls.url_locked = '/' + str(cls.locked_asset)
9595
cls.url_locked_versioned = get_versioned_asset_url(cls.url_locked)
9696
cls.url_locked_versioned_old_style = get_old_style_versioned_asset_url(cls.url_locked)
9797
cls.contentstore.set_attr(cls.locked_asset, 'locked', True)
9898

9999
# An unlocked asset
100100
cls.unlocked_asset = cls.course_key.make_asset_key('asset', 'another_static.txt')
101-
cls.url_unlocked = str(cls.unlocked_asset)
101+
cls.url_unlocked = '/' + str(cls.unlocked_asset)
102102
cls.url_unlocked_versioned = get_versioned_asset_url(cls.url_unlocked)
103103
cls.url_unlocked_versioned_old_style = get_old_style_versioned_asset_url(cls.url_unlocked)
104104
cls.length_unlocked = cls.contentstore.get_attr(cls.unlocked_asset, 'length')
@@ -134,7 +134,7 @@ def test_unlocked_versioned_asset_old_style(self):
134134
Test that unlocked assets that are versioned (old-style) are being served.
135135
"""
136136
self.client.logout()
137-
resp = self.client.get(self.url_unlocked_versioned_old_style)
137+
resp = self.client.get(self.url_unlocked_versioned_old_style, follow=True)
138138
assert resp.status_code == 200
139139

140140
def test_unlocked_versioned_asset_with_nonexistent_version(self):
@@ -168,7 +168,7 @@ def test_locked_versioned_old_styleasset(self):
168168
assert CourseEnrollment.is_enrolled(self.non_staff_usr, self.course_key)
169169

170170
self.client.login(username=self.non_staff_usr, password='test')
171-
resp = self.client.get(self.url_locked_versioned_old_style)
171+
resp = self.client.get(self.url_locked_versioned_old_style, follow=True)
172172
assert resp.status_code == 200
173173

174174
def test_locked_asset_not_logged_in(self):

‎xmodule/contentstore/content.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ def get_location_from_path(path):
143143
return AssetKey.from_string(path)
144144
except InvalidKeyError:
145145
# TODO - re-address this once LMS-11198 is tackled.
146-
if path.startswith('/'):
146+
if path.startswith('/') or path.endswith('/'):
147147
# try stripping off the leading slash and try again
148-
return AssetKey.from_string(path[1:])
148+
return AssetKey.from_string(path.strip('/'))
149149

150150
@staticmethod
151151
def is_versioned_asset_path(path):

0 commit comments

Comments
 (0)