Commit fdfaa565 by David Ormsbee

Merge pull request #9449 from edx/ormsbee/faster_tests_ccx

Move some CCX view tests to use SharedModuleStoreTestCase (performance).
parents 08343b96 4053d625
...@@ -36,6 +36,7 @@ from xmodule.x_module import XModuleMixin ...@@ -36,6 +36,7 @@ from xmodule.x_module import XModuleMixin
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import ( from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase, ModuleStoreTestCase,
SharedModuleStoreTestCase,
TEST_DATA_SPLIT_MODULESTORE) TEST_DATA_SPLIT_MODULESTORE)
from xmodule.modulestore.tests.factories import ( from xmodule.modulestore.tests.factories import (
CourseFactory, CourseFactory,
...@@ -78,30 +79,28 @@ def ccx_dummy_request(): ...@@ -78,30 +79,28 @@ def ccx_dummy_request():
@attr('shard_1') @attr('shard_1')
class TestCoachDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestCoachDashboard(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Tests for Custom Courses views. Tests for Custom Courses views.
""" """
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self): @classmethod
""" def setUpClass(cls):
Set up tests super(TestCoachDashboard, cls).setUpClass()
""" cls.course = course = CourseFactory.create()
super(TestCoachDashboard, self).setUp()
self.course = course = CourseFactory.create()
# Create instructor account
self.coach = coach = AdminFactory.create()
self.client.login(username=coach.username, password="test")
# Create a course outline # Create a course outline
self.mooc_start = start = datetime.datetime( cls.mooc_start = start = datetime.datetime(
2010, 5, 12, 2, 42, tzinfo=pytz.UTC) 2010, 5, 12, 2, 42, tzinfo=pytz.UTC
self.mooc_due = due = datetime.datetime( )
2010, 7, 7, 0, 0, tzinfo=pytz.UTC) cls.mooc_due = due = datetime.datetime(
chapters = [ItemFactory.create(start=start, parent=course) 2010, 7, 7, 0, 0, tzinfo=pytz.UTC
for _ in xrange(2)] )
chapters = [
ItemFactory.create(start=start, parent=course) for _ in xrange(2)
]
sequentials = flatten([ sequentials = flatten([
[ [
ItemFactory.create(parent=chapter) for _ in xrange(2) ItemFactory.create(parent=chapter) for _ in xrange(2)
...@@ -114,11 +113,25 @@ class TestCoachDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -114,11 +113,25 @@ class TestCoachDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase):
) for _ in xrange(2) ) for _ in xrange(2)
] for sequential in sequentials ] for sequential in sequentials
]) ])
blocks = flatten([ # pylint: disable=unused-variable
[ # Trying to wrap the whole thing in a bulk operation fails because it
ItemFactory.create(parent=vertical) for _ in xrange(2) # doesn't find the parents. But we can at least wrap this part...
] for vertical in verticals with cls.store.bulk_operations(course.id, emit_signals=False):
]) blocks = flatten([ # pylint: disable=unused-variable
[
ItemFactory.create(parent=vertical) for _ in xrange(2)
] for vertical in verticals
])
def setUp(self):
"""
Set up tests
"""
super(TestCoachDashboard, self).setUp()
# Create instructor account
self.coach = coach = AdminFactory.create()
self.client.login(username=coach.username, password="test")
def make_coach(self): def make_coach(self):
""" """
...@@ -451,35 +464,31 @@ def patched_get_children(self, usage_key_filter=None): ...@@ -451,35 +464,31 @@ def patched_get_children(self, usage_key_filter=None):
@override_settings(FIELD_OVERRIDE_PROVIDERS=( @override_settings(FIELD_OVERRIDE_PROVIDERS=(
'ccx.overrides.CustomCoursesForEdxOverrideProvider',)) 'ccx.overrides.CustomCoursesForEdxOverrideProvider',))
@patch('xmodule.x_module.XModuleMixin.get_children', patched_get_children, spec=True) @patch('xmodule.x_module.XModuleMixin.get_children', patched_get_children, spec=True)
class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestCCXGrades(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Tests for Custom Courses views. Tests for Custom Courses views.
""" """
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self): @classmethod
""" def setUpClass(cls):
Set up tests super(TestCCXGrades, cls).setUpClass()
""" cls._course = course = CourseFactory.create(enable_ccx=True)
super(TestCCXGrades, self).setUp()
self.course = course = CourseFactory.create(enable_ccx=True)
# Create instructor account
self.coach = coach = AdminFactory.create()
self.client.login(username=coach.username, password="test")
# Create a course outline # Create a course outline
self.mooc_start = start = datetime.datetime( cls.mooc_start = start = datetime.datetime(
2010, 5, 12, 2, 42, tzinfo=pytz.UTC) 2010, 5, 12, 2, 42, tzinfo=pytz.UTC
)
chapter = ItemFactory.create( chapter = ItemFactory.create(
start=start, parent=course, category='sequential') start=start, parent=course, category='sequential'
sections = [ )
cls.sections = sections = [
ItemFactory.create( ItemFactory.create(
parent=chapter, parent=chapter,
category="sequential", category="sequential",
metadata={'graded': True, 'format': 'Homework'}) metadata={'graded': True, 'format': 'Homework'})
for _ in xrange(4)] for _ in xrange(4)
# pylint: disable=unused-variable ]
problems = [ problems = [
[ [
ItemFactory.create( ItemFactory.create(
...@@ -491,13 +500,23 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -491,13 +500,23 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
] for section in sections ] for section in sections
] ]
def setUp(self):
"""
Set up tests
"""
super(TestCCXGrades, self).setUp()
# Create instructor account
self.coach = coach = AdminFactory.create()
self.client.login(username=coach.username, password="test")
# Create CCX # Create CCX
role = CourseCcxCoachRole(course.id) role = CourseCcxCoachRole(self._course.id)
role.add_users(coach) role.add_users(coach)
ccx = CcxFactory(course_id=course.id, coach=self.coach) ccx = CcxFactory(course_id=self._course.id, coach=self.coach)
# override course grading policy and make last section invisible to students # override course grading policy and make last section invisible to students
override_field_for_ccx(ccx, course, 'grading_policy', { override_field_for_ccx(ccx, self._course, 'grading_policy', {
'GRADER': [ 'GRADER': [
{'drop_count': 0, {'drop_count': 0,
'min_count': 2, 'min_count': 2,
...@@ -508,12 +527,13 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -508,12 +527,13 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
'GRADE_CUTOFFS': {'Pass': 0.75}, 'GRADE_CUTOFFS': {'Pass': 0.75},
}) })
override_field_for_ccx( override_field_for_ccx(
ccx, sections[-1], 'visible_to_staff_only', True) ccx, self.sections[-1], 'visible_to_staff_only', True
)
# create a ccx locator and retrieve the course structure using that key # create a ccx locator and retrieve the course structure using that key
# which emulates how a student would get access. # which emulates how a student would get access.
self.ccx_key = CCXLocator.from_course_locator(course.id, ccx.id) self.ccx_key = CCXLocator.from_course_locator(self._course.id, ccx.id)
self.course = get_course_by_id(self.ccx_key) self.course = get_course_by_id(self.ccx_key, depth=None)
self.student = student = UserFactory.create() self.student = student = UserFactory.create()
CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
...@@ -597,23 +617,29 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -597,23 +617,29 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
@ddt.ddt @ddt.ddt
class CCXCoachTabTestCase(ModuleStoreTestCase): class CCXCoachTabTestCase(SharedModuleStoreTestCase):
""" """
Test case for CCX coach tab. Test case for CCX coach tab.
""" """
@classmethod
def setUpClass(cls):
super(CCXCoachTabTestCase, cls).setUpClass()
cls.ccx_enabled_course = CourseFactory.create(enable_ccx=True)
cls.ccx_disabled_course = CourseFactory.create(enable_ccx=False)
def setUp(self): def setUp(self):
super(CCXCoachTabTestCase, self).setUp() super(CCXCoachTabTestCase, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory.create() self.user = UserFactory.create()
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id) for course in [self.ccx_enabled_course, self.ccx_disabled_course]:
role = CourseCcxCoachRole(self.course.id) CourseEnrollmentFactory.create(user=self.user, course_id=course.id)
role.add_users(self.user) role = CourseCcxCoachRole(course.id)
role.add_users(self.user)
def check_ccx_tab(self): def check_ccx_tab(self, course):
"""Helper function for verifying the ccx tab.""" """Helper function for verifying the ccx tab."""
request = RequestFactory().request() request = RequestFactory().request()
request.user = self.user request.user = self.user
all_tabs = get_course_tab_list(request, self.course) all_tabs = get_course_tab_list(request, course)
return any(tab.type == 'ccx_coach' for tab in all_tabs) return any(tab.type == 'ccx_coach' for tab in all_tabs)
@ddt.data( @ddt.data(
...@@ -629,10 +655,10 @@ class CCXCoachTabTestCase(ModuleStoreTestCase): ...@@ -629,10 +655,10 @@ class CCXCoachTabTestCase(ModuleStoreTestCase):
Test ccx coach tab state (visible or hidden) depending on the value of enable_ccx flag, ccx feature flag. Test ccx coach tab state (visible or hidden) depending on the value of enable_ccx flag, ccx feature flag.
""" """
with self.settings(FEATURES={'CUSTOM_COURSES_EDX': ccx_feature_flag}): with self.settings(FEATURES={'CUSTOM_COURSES_EDX': ccx_feature_flag}):
self.course.enable_ccx = enable_ccx course = self.ccx_enabled_course if enable_ccx else self.ccx_disabled_course
self.assertEquals( self.assertEquals(
expected_result, expected_result,
self.check_ccx_tab() self.check_ccx_tab(course)
) )
......
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