Add test of iterating over a course tree multiple times in the same request
This commit is contained in:
@@ -2,25 +2,32 @@
|
||||
"""
|
||||
Tests for course access
|
||||
"""
|
||||
import ddt
|
||||
import itertools
|
||||
import mock
|
||||
|
||||
from django.conf import settings
|
||||
from django.test.utils import override_settings
|
||||
import mock
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.client import RequestFactory
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
|
||||
from courseware.courses import (
|
||||
get_course_by_id, get_cms_course_link, course_image_url,
|
||||
get_course_info_section, get_course_about_section, get_cms_block_link
|
||||
)
|
||||
from courseware.module_render import get_module_for_descriptor
|
||||
from courseware.tests.helpers import get_request_for_user
|
||||
from courseware.model_data import FieldDataCache
|
||||
from student.tests.factories import UserFactory
|
||||
import xmodule.modulestore.django as store_django
|
||||
from xmodule.modulestore.django import _get_modulestore_branch_setting, modulestore
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.xml_importer import import_course_from_xml
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.django_utils import (
|
||||
TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_TOY_MODULESTORE
|
||||
)
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
|
||||
from xmodule.tests.xml import factories as xml
|
||||
from xmodule.tests.xml import XModuleXmlImportTest
|
||||
|
||||
@@ -60,7 +67,7 @@ class ModuleStoreBranchSettingTest(ModuleStoreTestCase):
|
||||
MODULESTORE_BRANCH='fake_default_branch',
|
||||
)
|
||||
def test_default_modulestore_preview_mapping(self):
|
||||
self.assertEqual(store_django._get_modulestore_branch_setting(), ModuleStoreEnum.Branch.draft_preferred)
|
||||
self.assertEqual(_get_modulestore_branch_setting(), ModuleStoreEnum.Branch.draft_preferred)
|
||||
|
||||
@mock.patch(
|
||||
'xmodule.modulestore.django.get_current_request_hostname',
|
||||
@@ -71,7 +78,7 @@ class ModuleStoreBranchSettingTest(ModuleStoreTestCase):
|
||||
MODULESTORE_BRANCH='fake_default_branch',
|
||||
)
|
||||
def test_default_modulestore_branch_mapping(self):
|
||||
self.assertEqual(store_django._get_modulestore_branch_setting(), 'fake_default_branch')
|
||||
self.assertEqual(_get_modulestore_branch_setting(), 'fake_default_branch')
|
||||
|
||||
|
||||
@override_settings(
|
||||
@@ -159,7 +166,7 @@ class CoursesRenderTest(ModuleStoreTestCase):
|
||||
"""
|
||||
super(CoursesRenderTest, self).setUp()
|
||||
|
||||
store = store_django.modulestore()
|
||||
store = modulestore()
|
||||
course_items = import_course_from_xml(store, self.user.id, TEST_DATA_DIR, ['toy'])
|
||||
course_key = course_items[0].id
|
||||
self.course = get_course_by_id(course_key)
|
||||
@@ -216,3 +223,46 @@ class XmlCoursesRenderTest(ModuleStoreTestCase):
|
||||
)
|
||||
course_info = get_course_info_section(request, course, 'handouts')
|
||||
self.assertIn("this module is temporarily unavailable", course_info)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class CourseInstantiationTests(ModuleStoreTestCase):
|
||||
"""
|
||||
Tests around instantiating a course multiple times in the same request.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(CourseInstantiationTests, self).setUp()
|
||||
|
||||
self.factory = RequestFactory()
|
||||
|
||||
@ddt.data(*itertools.product(xrange(5), [ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split], [None, 0, 5]))
|
||||
@ddt.unpack
|
||||
def test_repeated_course_module_instantiation(self, loops, default_store, course_depth):
|
||||
|
||||
with modulestore().default_store(default_store):
|
||||
course = CourseFactory.create()
|
||||
chapter = ItemFactory(parent=course, category='chapter', graded=True)
|
||||
section = ItemFactory(parent=chapter, category='sequential')
|
||||
__ = ItemFactory(parent=section, category='problem')
|
||||
|
||||
fake_request = self.factory.get(
|
||||
reverse('progress', kwargs={'course_id': unicode(course.id)})
|
||||
)
|
||||
|
||||
course = modulestore().get_course(course.id, depth=course_depth)
|
||||
|
||||
for _ in xrange(loops):
|
||||
field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
|
||||
course.id, self.user, course, depth=course_depth
|
||||
)
|
||||
course_module = get_module_for_descriptor(
|
||||
self.user,
|
||||
fake_request,
|
||||
course,
|
||||
field_data_cache,
|
||||
course.id
|
||||
)
|
||||
for chapter in course_module.get_children():
|
||||
for section in chapter.get_children():
|
||||
for item in section.get_children():
|
||||
self.assertTrue(item.graded)
|
||||
|
||||
@@ -1404,10 +1404,19 @@ class TestFilteredChildren(ModuleStoreTestCase):
|
||||
return key in self.children_for_user[user]
|
||||
|
||||
def assertBoundChildren(self, block, user):
|
||||
"""
|
||||
Ensure the bound children are indeed children.
|
||||
"""
|
||||
self.assertChildren(block, self.children_for_user[user])
|
||||
|
||||
def assertUnboundChildren(self, block):
|
||||
"""
|
||||
Ensure unbound children are indeed children.
|
||||
"""
|
||||
self.assertChildren(block, self.all_children)
|
||||
|
||||
def assertChildren(self, block, child_usage_ids):
|
||||
"""
|
||||
Used to assert that sets of children are equivalent.
|
||||
"""
|
||||
self.assertEquals(set(child_usage_ids), set(child.scope_ids.usage_id for child in block.get_children()))
|
||||
|
||||
Reference in New Issue
Block a user