test: Update the course in the cache after it's got new content.
Because signals are disabled by default for performance reasons, this doesn't happen automatically. So we manually refresh the course in the cache after all the changes have been made so that the course in the cache matches the latest version in the modulestore.
This commit is contained in:
@@ -8,6 +8,7 @@ from common.djangoapps.student.tests.factories import CourseEnrollmentFactory
|
||||
from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
|
||||
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
|
||||
|
||||
import openedx.core.djangoapps.content.block_structure.api as bs_api
|
||||
from ...api import get_course_blocks
|
||||
from ..library_content import ContentLibraryOrderTransformer, ContentLibraryTransformer
|
||||
from .helpers import CourseStructureTestCase
|
||||
@@ -41,6 +42,8 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
|
||||
self.course_hierarchy = self.get_course_hierarchy()
|
||||
self.blocks = self.build_course(self.course_hierarchy)
|
||||
self.course = self.blocks['course']
|
||||
# Do this manually because publish signals are not fired by default in tests.
|
||||
bs_api.update_course_in_cache(self.course.id)
|
||||
clear_course_from_cache(self.course.id)
|
||||
|
||||
# Enroll user in course.
|
||||
@@ -122,6 +125,7 @@ class ContentLibraryTransformerTestCase(CourseStructureTestCase):
|
||||
)
|
||||
assert len(list(raw_block_structure.get_block_keys())) == len(self.blocks)
|
||||
|
||||
bs_api.update_course_in_cache(self.course.id)
|
||||
clear_course_from_cache(self.course.id)
|
||||
trans_block_structure = get_course_blocks(
|
||||
self.user,
|
||||
@@ -175,6 +179,7 @@ class ContentLibraryOrderTransformerTestCase(CourseStructureTestCase):
|
||||
self.course_hierarchy = self.get_course_hierarchy()
|
||||
self.blocks = self.build_course(self.course_hierarchy)
|
||||
self.course = self.blocks['course']
|
||||
bs_api.update_course_in_cache(self.course.id)
|
||||
clear_course_from_cache(self.course.id)
|
||||
|
||||
# Enroll user in course.
|
||||
|
||||
@@ -22,6 +22,7 @@ from rest_framework.test import APITestCase
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
|
||||
|
||||
import openedx.core.djangoapps.content.block_structure.api as bs_api
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from common.djangoapps.student.roles import (
|
||||
CourseBetaTesterRole,
|
||||
@@ -2228,6 +2229,12 @@ class SubsectionGradeViewTest(GradebookViewTestBase):
|
||||
display_name='Unreleased Section',
|
||||
)
|
||||
|
||||
# We need to update the course in the cache after we create the new block.
|
||||
# Review Question: Should we be doing this here? Does it make sense to do
|
||||
# this in the xmodule/modulestore/tests/factories.py BlockFactory class
|
||||
# as a part of the publish there?
|
||||
bs_api.update_course_in_cache(self.course_data.course_key)
|
||||
|
||||
resp = self.client.get(
|
||||
self.get_url(subsection_id=unreleased_subsection.location)
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ from unittest.mock import patch
|
||||
|
||||
from crum import set_current_request
|
||||
|
||||
import openedx.core.djangoapps.content.block_structure.api as bs_api
|
||||
from xmodule.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
@@ -76,6 +77,9 @@ class GradesEventIntegrationTest(ProblemSubmissionTestMixin, SharedModuleStoreTe
|
||||
CourseEnrollment.enroll(self.student, self.course.id)
|
||||
self.instructor = UserFactory.create(is_staff=True, username='test_instructor', password=self.TEST_PASSWORD)
|
||||
self.refresh_course()
|
||||
# Since this doesn't happen automatically and we don't want to run all the publish signal handlers
|
||||
# Just make sure we have the latest version of the course in cache before we test the problem.
|
||||
bs_api.update_course_in_cache(self.course.id)
|
||||
|
||||
@patch('lms.djangoapps.grades.events.tracker')
|
||||
def test_submit_answer(self, events_tracker):
|
||||
|
||||
@@ -13,6 +13,7 @@ from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import check_mongo_calls_range
|
||||
|
||||
import openedx.core.djangoapps.content.block_structure.api as bs_api
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from lms.djangoapps.course_blocks.api import get_course_blocks
|
||||
from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase
|
||||
@@ -462,6 +463,7 @@ class MultiProblemModulestoreAccessTestCase(CourseStructureTestCase, SharedModul
|
||||
)
|
||||
with self.store.default_store(store_type):
|
||||
blocks = self.build_course(course)
|
||||
bs_api.update_course_in_cache(blocks['course'].id)
|
||||
clear_course_from_cache(blocks['course'].id)
|
||||
with check_mongo_calls_range(max_mongo_calls, min_mongo_calls):
|
||||
get_course_blocks(self.student, blocks['course'].location, self.transformers)
|
||||
|
||||
Reference in New Issue
Block a user