Skip to content

Commit

Permalink
Merge pull request #11552 from edx/perf/speed-up-contentstore-tests
Browse files Browse the repository at this point in the history
Switch to SharedModuleStoreTestCase in the 'contentstore' app where possible.
  • Loading branch information
tobz committed Feb 16, 2016
2 parents b9ccff7 + af102a6 commit d3c88d7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 57 deletions.
41 changes: 20 additions & 21 deletions cms/djangoapps/contentstore/tests/test_courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import SignalHandler, modulestore
from xmodule.modulestore.edit_info import EditInfoMixin
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.mixed import MixedModuleStore
from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase,
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.mongo_connection import MONGO_PORT_NUM, MONGO_HOST
from xmodule.modulestore.tests.utils import (
Expand Down Expand Up @@ -692,60 +690,61 @@ def test_large_course_deletion(self, store_type):
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
executed directly. The test course and library gets created without the listeners
being present, which allows us to ensure that when the listener is
executed, it is done as expected.
"""

def setUp(self):
super(TestTaskExecution, self).setUp()
@classmethod
def setUpClass(cls):
super(TestTaskExecution, cls).setUpClass()
SignalHandler.course_published.disconnect(listen_for_course_publish)
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(
parent_location=self.course.location,
cls.chapter = ItemFactory.create(
parent_location=cls.course.location,
category='chapter',
display_name="Week 1",
publish_item=True,
start=datetime(2015, 3, 1, tzinfo=UTC),
)
self.sequential = ItemFactory.create(
parent_location=self.chapter.location,
cls.sequential = ItemFactory.create(
parent_location=cls.chapter.location,
category='sequential',
display_name="Lesson 1",
publish_item=True,
start=datetime(2015, 3, 1, tzinfo=UTC),
)
self.vertical = ItemFactory.create(
parent_location=self.sequential.location,
cls.vertical = ItemFactory.create(
parent_location=cls.sequential.location,
category='vertical',
display_name='Subsection 1',
publish_item=True,
start=datetime(2015, 4, 1, tzinfo=UTC),
)
# unspecified start - should inherit from container
self.html_unit = ItemFactory.create(
parent_location=self.vertical.location,
cls.html_unit = ItemFactory.create(
parent_location=cls.vertical.location,
category="html",
display_name="Html Content",
publish_item=False,
)

self.library = LibraryFactory.create()
cls.library = LibraryFactory.create()

self.library_block1 = ItemFactory.create(
parent_location=self.library.location,
cls.library_block1 = ItemFactory.create(
parent_location=cls.library.location,
category="html",
display_name="Html Content",
publish_item=False,
)

self.library_block2 = ItemFactory.create(
parent_location=self.library.location,
cls.library_block2 = ItemFactory.create(
parent_location=cls.library.location,
category="html",
display_name="Html Content 2",
publish_item=False,
Expand Down
45 changes: 24 additions & 21 deletions cms/djangoapps/contentstore/tests/test_transcripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from xmodule.modulestore.tests.factories import CourseFactory
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.contentstore.django import contentstore
from xmodule.video_module import transcripts_utils
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_generate_subs_decrease_speed_2(self):


@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class TestSaveSubsToStore(ModuleStoreTestCase):
class TestSaveSubsToStore(SharedModuleStoreTestCase):
"""Tests for `save_subs_to_store` function."""

org = 'MITx'
Expand All @@ -92,13 +92,13 @@ def clear_subs_content(self):
except NotFoundError:
pass

def setUp(self):

super(TestSaveSubsToStore, self).setUp()
self.course = CourseFactory.create(
org=self.org, number=self.number, display_name=self.display_name)
@classmethod
def setUpClass(cls):
super(TestSaveSubsToStore, cls).setUpClass()
cls.course = CourseFactory.create(
org=cls.org, number=cls.number, display_name=cls.display_name)

self.subs = {
cls.subs = {
'start': [100, 200, 240, 390, 1000],
'end': [200, 240, 380, 1000, 1500],
'text': [
Expand All @@ -110,18 +110,20 @@ def setUp(self):
]
}

self.subs_id = str(uuid4())
filename = 'subs_{0}.srt.sjson'.format(self.subs_id)
self.content_location = StaticContent.compute_location(self.course.id, filename)
self.addCleanup(self.clear_subs_content)
cls.subs_id = str(uuid4())
filename = 'subs_{0}.srt.sjson'.format(cls.subs_id)
cls.content_location = StaticContent.compute_location(cls.course.id, filename)

# 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())
filename_unjsonable = 'subs_{0}.srt.sjson'.format(self.unjsonable_subs_id)
self.content_location_unjsonable = StaticContent.compute_location(self.course.id, filename_unjsonable)
cls.unjsonable_subs_id = str(uuid4())
filename_unjsonable = 'subs_{0}.srt.sjson'.format(cls.unjsonable_subs_id)
cls.content_location_unjsonable = StaticContent.compute_location(cls.course.id, filename_unjsonable)

def setUp(self):
super(TestSaveSubsToStore, self).setUp()
self.addCleanup(self.clear_subs_content)
self.clear_subs_content()

def test_save_subs_to_store(self):
Expand Down Expand Up @@ -154,7 +156,7 @@ def test_save_unjsonable_subs_to_store(self):


@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class TestDownloadYoutubeSubs(ModuleStoreTestCase):
class TestDownloadYoutubeSubs(SharedModuleStoreTestCase):
"""Tests for `download_youtube_subs` function."""

org = 'MITx'
Expand Down Expand Up @@ -182,10 +184,11 @@ def clear_subs_content(self, youtube_subs):
for subs_id in youtube_subs.values():
self.clear_sub_content(subs_id)

def setUp(self):
super(TestDownloadYoutubeSubs, self).setUp()
self.course = CourseFactory.create(
org=self.org, number=self.number, display_name=self.display_name)
@classmethod
def setUpClass(cls):
super(TestDownloadYoutubeSubs, cls).setUpClass()
cls.course = CourseFactory.create(
org=cls.org, number=cls.number, display_name=cls.display_name)

def test_success_downloading_subs(self):

Expand Down
31 changes: 16 additions & 15 deletions cms/djangoapps/contentstore/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.test.utils import override_settings
from xmodule.modulestore import ModuleStoreEnum
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 xmodule.modulestore.django import modulestore
from xmodule.partitions.partitions import UserPartition, Group
Expand Down Expand Up @@ -110,16 +110,17 @@ def get_course_with_tabs(self, tabs=None):
return course


class XBlockVisibilityTestCase(ModuleStoreTestCase):
class XBlockVisibilityTestCase(SharedModuleStoreTestCase):
"""Tests for xblock visibility for students."""

def setUp(self):
super(XBlockVisibilityTestCase, self).setUp()
@classmethod
def setUpClass(cls):
super(XBlockVisibilityTestCase, cls).setUpClass()

self.dummy_user = ModuleStoreEnum.UserID.test
self.past = datetime(1970, 1, 1, tzinfo=UTC)
self.future = datetime.now(UTC) + timedelta(days=1)
self.course = CourseFactory.create()
cls.dummy_user = ModuleStoreEnum.UserID.test
cls.past = datetime(1970, 1, 1, tzinfo=UTC)
cls.future = datetime.now(UTC) + timedelta(days=1)
cls.course = CourseFactory.create()

def test_private_unreleased_xblock(self):
"""Verifies that a private unreleased xblock is not visible"""
Expand Down Expand Up @@ -484,31 +485,31 @@ def test_retrieves_partition_info_with_selected_groups(self):
expected = [
{
"id": 0,
"name": "Cohort user partition",
"scheme": "cohort",
"name": u"Cohort user partition",
"scheme": u"cohort",
"groups": [
{
"id": 0,
"name": "Group A",
"name": u"Group A",
"selected": False,
"deleted": False,
},
{
"id": 1,
"name": "Group B",
"name": u"Group B",
"selected": False,
"deleted": False,
},
]
},
{
"id": 1,
"name": "Random user partition",
"scheme": "random",
"name": u"Random user partition",
"scheme": u"random",
"groups": [
{
"id": 0,
"name": "Group C",
"name": u"Group C",
"selected": False,
"deleted": False,
},
Expand Down

0 comments on commit d3c88d7

Please sign in to comment.