Merge pull request #9449 from edx/ormsbee/faster_tests_ccx
Move some CCX view tests to use SharedModuleStoreTestCase (performance).
This commit is contained in:
@@ -36,6 +36,7 @@ from xmodule.x_module import XModuleMixin
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests.django_utils import (
|
||||
ModuleStoreTestCase,
|
||||
SharedModuleStoreTestCase,
|
||||
TEST_DATA_SPLIT_MODULESTORE)
|
||||
from xmodule.modulestore.tests.factories import (
|
||||
CourseFactory,
|
||||
@@ -78,30 +79,28 @@ def ccx_dummy_request():
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class TestCoachDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
class TestCoachDashboard(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
"""
|
||||
Tests for Custom Courses views.
|
||||
"""
|
||||
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Set up tests
|
||||
"""
|
||||
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")
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestCoachDashboard, cls).setUpClass()
|
||||
cls.course = course = CourseFactory.create()
|
||||
|
||||
# Create a course outline
|
||||
self.mooc_start = start = datetime.datetime(
|
||||
2010, 5, 12, 2, 42, tzinfo=pytz.UTC)
|
||||
self.mooc_due = due = datetime.datetime(
|
||||
2010, 7, 7, 0, 0, tzinfo=pytz.UTC)
|
||||
chapters = [ItemFactory.create(start=start, parent=course)
|
||||
for _ in xrange(2)]
|
||||
cls.mooc_start = start = datetime.datetime(
|
||||
2010, 5, 12, 2, 42, tzinfo=pytz.UTC
|
||||
)
|
||||
cls.mooc_due = due = datetime.datetime(
|
||||
2010, 7, 7, 0, 0, tzinfo=pytz.UTC
|
||||
)
|
||||
|
||||
chapters = [
|
||||
ItemFactory.create(start=start, parent=course) for _ in xrange(2)
|
||||
]
|
||||
sequentials = flatten([
|
||||
[
|
||||
ItemFactory.create(parent=chapter) for _ in xrange(2)
|
||||
@@ -114,11 +113,25 @@ class TestCoachDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
) for _ in xrange(2)
|
||||
] for sequential in sequentials
|
||||
])
|
||||
blocks = flatten([ # pylint: disable=unused-variable
|
||||
[
|
||||
ItemFactory.create(parent=vertical) for _ in xrange(2)
|
||||
] for vertical in verticals
|
||||
])
|
||||
|
||||
# Trying to wrap the whole thing in a bulk operation fails because it
|
||||
# doesn't find the parents. But we can at least wrap this part...
|
||||
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):
|
||||
"""
|
||||
@@ -451,35 +464,31 @@ def patched_get_children(self, usage_key_filter=None):
|
||||
@override_settings(FIELD_OVERRIDE_PROVIDERS=(
|
||||
'ccx.overrides.CustomCoursesForEdxOverrideProvider',))
|
||||
@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.
|
||||
"""
|
||||
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Set up tests
|
||||
"""
|
||||
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")
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestCCXGrades, cls).setUpClass()
|
||||
cls._course = course = CourseFactory.create(enable_ccx=True)
|
||||
|
||||
# Create a course outline
|
||||
self.mooc_start = start = datetime.datetime(
|
||||
2010, 5, 12, 2, 42, tzinfo=pytz.UTC)
|
||||
cls.mooc_start = start = datetime.datetime(
|
||||
2010, 5, 12, 2, 42, tzinfo=pytz.UTC
|
||||
)
|
||||
chapter = ItemFactory.create(
|
||||
start=start, parent=course, category='sequential')
|
||||
sections = [
|
||||
start=start, parent=course, category='sequential'
|
||||
)
|
||||
cls.sections = sections = [
|
||||
ItemFactory.create(
|
||||
parent=chapter,
|
||||
category="sequential",
|
||||
metadata={'graded': True, 'format': 'Homework'})
|
||||
for _ in xrange(4)]
|
||||
# pylint: disable=unused-variable
|
||||
for _ in xrange(4)
|
||||
]
|
||||
problems = [
|
||||
[
|
||||
ItemFactory.create(
|
||||
@@ -491,13 +500,23 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
] 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
|
||||
role = CourseCcxCoachRole(course.id)
|
||||
role = CourseCcxCoachRole(self._course.id)
|
||||
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_field_for_ccx(ccx, course, 'grading_policy', {
|
||||
override_field_for_ccx(ccx, self._course, 'grading_policy', {
|
||||
'GRADER': [
|
||||
{'drop_count': 0,
|
||||
'min_count': 2,
|
||||
@@ -508,12 +527,13 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
'GRADE_CUTOFFS': {'Pass': 0.75},
|
||||
})
|
||||
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
|
||||
# which emulates how a student would get access.
|
||||
self.ccx_key = CCXLocator.from_course_locator(course.id, ccx.id)
|
||||
self.course = get_course_by_id(self.ccx_key)
|
||||
self.ccx_key = CCXLocator.from_course_locator(self._course.id, ccx.id)
|
||||
self.course = get_course_by_id(self.ccx_key, depth=None)
|
||||
|
||||
self.student = student = UserFactory.create()
|
||||
CourseEnrollmentFactory.create(user=student, course_id=self.course.id)
|
||||
@@ -597,23 +617,29 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class CCXCoachTabTestCase(ModuleStoreTestCase):
|
||||
class CCXCoachTabTestCase(SharedModuleStoreTestCase):
|
||||
"""
|
||||
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):
|
||||
super(CCXCoachTabTestCase, self).setUp()
|
||||
self.course = CourseFactory.create()
|
||||
self.user = UserFactory.create()
|
||||
CourseEnrollmentFactory.create(user=self.user, course_id=self.course.id)
|
||||
role = CourseCcxCoachRole(self.course.id)
|
||||
role.add_users(self.user)
|
||||
for course in [self.ccx_enabled_course, self.ccx_disabled_course]:
|
||||
CourseEnrollmentFactory.create(user=self.user, course_id=course.id)
|
||||
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."""
|
||||
request = RequestFactory().request()
|
||||
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)
|
||||
|
||||
@ddt.data(
|
||||
@@ -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.
|
||||
"""
|
||||
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(
|
||||
expected_result,
|
||||
self.check_ccx_tab()
|
||||
self.check_ccx_tab(course)
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user