Commit e2cbb547 by Toby Lawrence

Switch to SharedModuleStoreTestCase in the 'contentstore' app where possible.

parent cd101d5d
...@@ -20,14 +20,12 @@ from xmodule.library_tools import normalize_key_for_search ...@@ -20,14 +20,12 @@ from xmodule.library_tools import normalize_key_for_search
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import SignalHandler, modulestore from xmodule.modulestore.django import SignalHandler, modulestore
from xmodule.modulestore.edit_info import EditInfoMixin from xmodule.modulestore.edit_info import EditInfoMixin
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.mixed import MixedModuleStore from xmodule.modulestore.mixed import MixedModuleStore
from xmodule.modulestore.tests.django_utils import ( from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase,
TEST_DATA_MONGO_MODULESTORE, TEST_DATA_MONGO_MODULESTORE,
TEST_DATA_SPLIT_MODULESTORE TEST_DATA_SPLIT_MODULESTORE,
) SharedModuleStoreTestCase)
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory, LibraryFactory
from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST from xmodule.modulestore.tests.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
from xmodule.modulestore.tests.utils import ( from xmodule.modulestore.tests.utils import (
...@@ -692,7 +690,7 @@ class TestLargeCourseDeletions(MixedWithOptionsTestCase): ...@@ -692,7 +690,7 @@ class TestLargeCourseDeletions(MixedWithOptionsTestCase):
self._perform_test_using_store(store_type, self._test_large_course_deletion) self._perform_test_using_store(store_type, self._test_large_course_deletion)
class TestTaskExecution(ModuleStoreTestCase): class TestTaskExecution(SharedModuleStoreTestCase):
""" """
Set of tests to ensure that the task code will do the right thing when Set of tests to ensure that the task code will do the right thing when
executed directly. The test course and library gets created without the listeners executed directly. The test course and library gets created without the listeners
...@@ -700,57 +698,63 @@ class TestTaskExecution(ModuleStoreTestCase): ...@@ -700,57 +698,63 @@ class TestTaskExecution(ModuleStoreTestCase):
executed, it is done as expected. executed, it is done as expected.
""" """
def setUp(self): @classmethod
super(TestTaskExecution, self).setUp() def setUpClass(cls):
super(TestTaskExecution, cls).setUpClass()
SignalHandler.course_published.disconnect(listen_for_course_publish) SignalHandler.course_published.disconnect(listen_for_course_publish)
SignalHandler.library_updated.disconnect(listen_for_library_update) SignalHandler.library_updated.disconnect(listen_for_library_update)
self.course = CourseFactory.create(start=datetime(2015, 3, 1, tzinfo=UTC)) cls.course = CourseFactory.create(start=datetime(2015, 3, 1, tzinfo=UTC))
self.chapter = ItemFactory.create( cls.chapter = ItemFactory.create(
parent_location=self.course.location, parent_location=cls.course.location,
category='chapter', category='chapter',
display_name="Week 1", display_name="Week 1",
publish_item=True, publish_item=True,
start=datetime(2015, 3, 1, tzinfo=UTC), start=datetime(2015, 3, 1, tzinfo=UTC),
) )
self.sequential = ItemFactory.create( cls.sequential = ItemFactory.create(
parent_location=self.chapter.location, parent_location=cls.chapter.location,
category='sequential', category='sequential',
display_name="Lesson 1", display_name="Lesson 1",
publish_item=True, publish_item=True,
start=datetime(2015, 3, 1, tzinfo=UTC), start=datetime(2015, 3, 1, tzinfo=UTC),
) )
self.vertical = ItemFactory.create( cls.vertical = ItemFactory.create(
parent_location=self.sequential.location, parent_location=cls.sequential.location,
category='vertical', category='vertical',
display_name='Subsection 1', display_name='Subsection 1',
publish_item=True, publish_item=True,
start=datetime(2015, 4, 1, tzinfo=UTC), start=datetime(2015, 4, 1, tzinfo=UTC),
) )
# unspecified start - should inherit from container # unspecified start - should inherit from container
self.html_unit = ItemFactory.create( cls.html_unit = ItemFactory.create(
parent_location=self.vertical.location, parent_location=cls.vertical.location,
category="html", category="html",
display_name="Html Content", display_name="Html Content",
publish_item=False, publish_item=False,
) )
self.library = LibraryFactory.create() cls.library = LibraryFactory.create()
self.library_block1 = ItemFactory.create( cls.library_block1 = ItemFactory.create(
parent_location=self.library.location, parent_location=cls.library.location,
category="html", category="html",
display_name="Html Content", display_name="Html Content",
publish_item=False, publish_item=False,
) )
self.library_block2 = ItemFactory.create( cls.library_block2 = ItemFactory.create(
parent_location=self.library.location, parent_location=cls.library.location,
category="html", category="html",
display_name="Html Content 2", display_name="Html Content 2",
publish_item=False, publish_item=False,
) )
def setUp(self):
super(TestTaskExecution, self).setUp()
SignalHandler.course_published.disconnect(listen_for_course_publish)
SignalHandler.library_updated.disconnect(listen_for_library_update)
def test_task_indexing_course(self): def test_task_indexing_course(self):
""" Making sure that the receiver correctly fires off the task when invoked by signal """ """ Making sure that the receiver correctly fires off the task when invoked by signal """
searcher = SearchEngine.get_search_engine(CoursewareSearchIndexer.INDEX_NAME) searcher = SearchEngine.get_search_engine(CoursewareSearchIndexer.INDEX_NAME)
......
...@@ -13,32 +13,32 @@ class TestHandleItemDeleted(ModuleStoreTestCase, MilestonesTestCaseMixin): ...@@ -13,32 +13,32 @@ class TestHandleItemDeleted(ModuleStoreTestCase, MilestonesTestCaseMixin):
""" """
Test case for handle_score_changed django signal handler Test case for handle_score_changed django signal handler
""" """
def setUp(self): def setUp(cls):
""" """
Initial data setup Initial data setup
""" """
super(TestHandleItemDeleted, self).setUp() super(TestHandleItemDeleted, cls).setUp()
self.course = CourseFactory.create() cls.course = CourseFactory.create()
self.course.enable_subsection_gating = True cls.course.enable_subsection_gating = True
self.course.save() cls.course.save()
self.chapter = ItemFactory.create( cls.chapter = ItemFactory.create(
parent=self.course, parent=cls.course,
category="chapter", category="chapter",
display_name="Chapter" display_name="Chapter"
) )
self.open_seq = ItemFactory.create( cls.open_seq = ItemFactory.create(
parent=self.chapter, parent=cls.chapter,
category='sequential', category='sequential',
display_name="Open Sequential" display_name="Open Sequential"
) )
self.gated_seq = ItemFactory.create( cls.gated_seq = ItemFactory.create(
parent=self.chapter, parent=cls.chapter,
category='sequential', category='sequential',
display_name="Gated Sequential" display_name="Gated Sequential"
) )
gating_api.add_prerequisite(self.course.id, self.open_seq.location) gating_api.add_prerequisite(cls.course.id, cls.open_seq.location)
gating_api.set_required_content(self.course.id, self.gated_seq.location, self.open_seq.location, 100) gating_api.set_required_content(cls.course.id, cls.gated_seq.location, cls.open_seq.location, 100)
@patch('contentstore.signals.gating_api.set_required_content') @patch('contentstore.signals.gating_api.set_required_content')
@patch('contentstore.signals.gating_api.remove_prerequisite') @patch('contentstore.signals.gating_api.remove_prerequisite')
......
...@@ -14,7 +14,7 @@ from nose.plugins.skip import SkipTest ...@@ -14,7 +14,7 @@ from nose.plugins.skip import SkipTest
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.exceptions import NotFoundError from xmodule.exceptions import NotFoundError
from xmodule.contentstore.django import contentstore from xmodule.contentstore.django import contentstore
from xmodule.video_module import transcripts_utils from xmodule.video_module import transcripts_utils
...@@ -77,7 +77,7 @@ class TestGenerateSubs(unittest.TestCase): ...@@ -77,7 +77,7 @@ class TestGenerateSubs(unittest.TestCase):
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class TestSaveSubsToStore(ModuleStoreTestCase): class TestSaveSubsToStore(SharedModuleStoreTestCase):
"""Tests for `save_subs_to_store` function.""" """Tests for `save_subs_to_store` function."""
org = 'MITx' org = 'MITx'
...@@ -92,13 +92,13 @@ class TestSaveSubsToStore(ModuleStoreTestCase): ...@@ -92,13 +92,13 @@ class TestSaveSubsToStore(ModuleStoreTestCase):
except NotFoundError: except NotFoundError:
pass pass
def setUp(self): @classmethod
def setUpClass(cls):
super(TestSaveSubsToStore, self).setUp() super(TestSaveSubsToStore, cls).setUpClass()
self.course = CourseFactory.create( cls.course = CourseFactory.create(
org=self.org, number=self.number, display_name=self.display_name) org=cls.org, number=cls.number, display_name=cls.display_name)
self.subs = { cls.subs = {
'start': [100, 200, 240, 390, 1000], 'start': [100, 200, 240, 390, 1000],
'end': [200, 240, 380, 1000, 1500], 'end': [200, 240, 380, 1000, 1500],
'text': [ 'text': [
...@@ -110,18 +110,19 @@ class TestSaveSubsToStore(ModuleStoreTestCase): ...@@ -110,18 +110,19 @@ class TestSaveSubsToStore(ModuleStoreTestCase):
] ]
} }
self.subs_id = str(uuid4()) cls.subs_id = str(uuid4())
filename = 'subs_{0}.srt.sjson'.format(self.subs_id) filename = 'subs_{0}.srt.sjson'.format(cls.subs_id)
self.content_location = StaticContent.compute_location(self.course.id, filename) cls.content_location = StaticContent.compute_location(cls.course.id, filename)
self.addCleanup(self.clear_subs_content)
# incorrect subs # incorrect subs
self.unjsonable_subs = set([1]) # set can't be serialized cls.unjsonable_subs = {1} # set can't be serialized
self.unjsonable_subs_id = str(uuid4()) cls.unjsonable_subs_id = str(uuid4())
filename_unjsonable = 'subs_{0}.srt.sjson'.format(self.unjsonable_subs_id) filename_unjsonable = 'subs_{0}.srt.sjson'.format(cls.unjsonable_subs_id)
self.content_location_unjsonable = StaticContent.compute_location(self.course.id, filename_unjsonable) cls.content_location_unjsonable = StaticContent.compute_location(cls.course.id, filename_unjsonable)
def setUp(self):
self.addCleanup(self.clear_subs_content)
self.clear_subs_content() self.clear_subs_content()
def test_save_subs_to_store(self): def test_save_subs_to_store(self):
...@@ -154,7 +155,7 @@ class TestSaveSubsToStore(ModuleStoreTestCase): ...@@ -154,7 +155,7 @@ class TestSaveSubsToStore(ModuleStoreTestCase):
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE) @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class TestDownloadYoutubeSubs(ModuleStoreTestCase): class TestDownloadYoutubeSubs(SharedModuleStoreTestCase):
"""Tests for `download_youtube_subs` function.""" """Tests for `download_youtube_subs` function."""
org = 'MITx' org = 'MITx'
...@@ -182,10 +183,11 @@ class TestDownloadYoutubeSubs(ModuleStoreTestCase): ...@@ -182,10 +183,11 @@ class TestDownloadYoutubeSubs(ModuleStoreTestCase):
for subs_id in youtube_subs.values(): for subs_id in youtube_subs.values():
self.clear_sub_content(subs_id) self.clear_sub_content(subs_id)
def setUp(self): @classmethod
super(TestDownloadYoutubeSubs, self).setUp() def setUpClass(cls):
self.course = CourseFactory.create( super(TestDownloadYoutubeSubs, cls).setUpClass()
org=self.org, number=self.number, display_name=self.display_name) cls.course = CourseFactory.create(
org=cls.org, number=cls.number, display_name=cls.display_name)
def test_success_downloading_subs(self): def test_success_downloading_subs(self):
......
...@@ -9,7 +9,7 @@ from django.test import TestCase ...@@ -9,7 +9,7 @@ from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase
from opaque_keys.edx.locations import SlashSeparatedCourseKey from opaque_keys.edx.locations import SlashSeparatedCourseKey
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.partitions.partitions import UserPartition, Group from xmodule.partitions.partitions import UserPartition, Group
...@@ -110,16 +110,17 @@ class ExtraPanelTabTestCase(TestCase): ...@@ -110,16 +110,17 @@ class ExtraPanelTabTestCase(TestCase):
return course return course
class XBlockVisibilityTestCase(ModuleStoreTestCase): class XBlockVisibilityTestCase(SharedModuleStoreTestCase):
"""Tests for xblock visibility for students.""" """Tests for xblock visibility for students."""
def setUp(self): @classmethod
super(XBlockVisibilityTestCase, self).setUp() def setUpClass(cls):
super(XBlockVisibilityTestCase, cls).setUpClass()
self.dummy_user = ModuleStoreEnum.UserID.test cls.dummy_user = ModuleStoreEnum.UserID.test
self.past = datetime(1970, 1, 1, tzinfo=UTC) cls.past = datetime(1970, 1, 1, tzinfo=UTC)
self.future = datetime.now(UTC) + timedelta(days=1) cls.future = datetime.now(UTC) + timedelta(days=1)
self.course = CourseFactory.create() cls.course = CourseFactory.create()
def test_private_unreleased_xblock(self): def test_private_unreleased_xblock(self):
"""Verifies that a private unreleased xblock is not visible""" """Verifies that a private unreleased xblock is not visible"""
...@@ -484,18 +485,18 @@ class GetUserPartitionInfoTest(ModuleStoreTestCase): ...@@ -484,18 +485,18 @@ class GetUserPartitionInfoTest(ModuleStoreTestCase):
expected = [ expected = [
{ {
"id": 0, "id": 0,
"name": "Cohort user partition", "name": u"Cohort user partition",
"scheme": "cohort", "scheme": u"cohort",
"groups": [ "groups": [
{ {
"id": 0, "id": 0,
"name": "Group A", "name": u"Group A",
"selected": False, "selected": False,
"deleted": False, "deleted": False,
}, },
{ {
"id": 1, "id": 1,
"name": "Group B", "name": u"Group B",
"selected": False, "selected": False,
"deleted": False, "deleted": False,
}, },
...@@ -503,12 +504,12 @@ class GetUserPartitionInfoTest(ModuleStoreTestCase): ...@@ -503,12 +504,12 @@ class GetUserPartitionInfoTest(ModuleStoreTestCase):
}, },
{ {
"id": 1, "id": 1,
"name": "Random user partition", "name": u"Random user partition",
"scheme": "random", "scheme": u"random",
"groups": [ "groups": [
{ {
"id": 0, "id": 0,
"name": "Group C", "name": u"Group C",
"selected": False, "selected": False,
"deleted": False, "deleted": False,
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment