Skip to content

Commit d2c33c4

Browse files
committed
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.
1 parent 38860a1 commit d2c33c4

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

lms/djangoapps/course_blocks/transformers/tests/test_library_content.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from openedx.core.djangoapps.content.block_structure.api import clear_course_from_cache
99
from openedx.core.djangoapps.content.block_structure.transformers import BlockStructureTransformers
1010

11+
import openedx.core.djangoapps.content.block_structure.api as bs_api
1112
from ...api import get_course_blocks
1213
from ..library_content import ContentLibraryOrderTransformer, ContentLibraryTransformer
1314
from .helpers import CourseStructureTestCase
@@ -41,6 +42,8 @@ def setUp(self):
4142
self.course_hierarchy = self.get_course_hierarchy()
4243
self.blocks = self.build_course(self.course_hierarchy)
4344
self.course = self.blocks['course']
45+
# Do this manually because publish signals are not fired by default in tests.
46+
bs_api.update_course_in_cache(self.course.id)
4447
clear_course_from_cache(self.course.id)
4548

4649
# Enroll user in course.
@@ -122,6 +125,7 @@ def test_content_library(self):
122125
)
123126
assert len(list(raw_block_structure.get_block_keys())) == len(self.blocks)
124127

128+
bs_api.update_course_in_cache(self.course.id)
125129
clear_course_from_cache(self.course.id)
126130
trans_block_structure = get_course_blocks(
127131
self.user,
@@ -175,6 +179,7 @@ def setUp(self):
175179
self.course_hierarchy = self.get_course_hierarchy()
176180
self.blocks = self.build_course(self.course_hierarchy)
177181
self.course = self.blocks['course']
182+
bs_api.update_course_in_cache(self.course.id)
178183
clear_course_from_cache(self.course.id)
179184

180185
# Enroll user in course.

lms/djangoapps/grades/rest_api/v1/tests/test_gradebook_views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
2323
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
2424

25+
import openedx.core.djangoapps.content.block_structure.api as bs_api
2526
from common.djangoapps.course_modes.models import CourseMode
2627
from common.djangoapps.student.roles import (
2728
CourseBetaTesterRole,
@@ -2228,6 +2229,12 @@ def test_get_override_for_unreleased_block(self):
22282229
display_name='Unreleased Section',
22292230
)
22302231

2232+
# We need to update the course in the cache after we create the new block.
2233+
# Review Question: Should we be doing this here? Does it make sense to do
2234+
# this in the xmodule/modulestore/tests/factories.py BlockFactory class
2235+
# as a part of the publish there?
2236+
bs_api.update_course_in_cache(self.course_data.course_key)
2237+
22312238
resp = self.client.get(
22322239
self.get_url(subsection_id=unreleased_subsection.location)
22332240
)

lms/djangoapps/grades/tests/integration/test_events.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from crum import set_current_request
99

10+
import openedx.core.djangoapps.content.block_structure.api as bs_api
1011
from xmodule.capa.tests.response_xml_factory import MultipleChoiceResponseXMLFactory
1112
from common.djangoapps.student.models import CourseEnrollment
1213
from common.djangoapps.student.tests.factories import UserFactory
@@ -76,6 +77,9 @@ def setUp(self):
7677
CourseEnrollment.enroll(self.student, self.course.id)
7778
self.instructor = UserFactory.create(is_staff=True, username='test_instructor', password=self.TEST_PASSWORD)
7879
self.refresh_course()
80+
# Since this doesn't happen automatically and we don't want to run all the publish signal handlers
81+
# Just make sure we have the latest version of the course in cache before we test the problem.
82+
bs_api.update_course_in_cache(self.course.id)
7983

8084
@patch('lms.djangoapps.grades.events.tracker')
8185
def test_submit_answer(self, events_tracker):

lms/djangoapps/grades/tests/test_transformer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
1414
from xmodule.modulestore.tests.factories import check_mongo_calls_range
1515

16+
import openedx.core.djangoapps.content.block_structure.api as bs_api
1617
from common.djangoapps.student.tests.factories import UserFactory
1718
from lms.djangoapps.course_blocks.api import get_course_blocks
1819
from lms.djangoapps.course_blocks.transformers.tests.helpers import CourseStructureTestCase
@@ -462,6 +463,7 @@ def test_modulestore_performance(self, store_type, max_mongo_calls, min_mongo_ca
462463
)
463464
with self.store.default_store(store_type):
464465
blocks = self.build_course(course)
466+
bs_api.update_course_in_cache(blocks['course'].id)
465467
clear_course_from_cache(blocks['course'].id)
466468
with check_mongo_calls_range(max_mongo_calls, min_mongo_calls):
467469
get_course_blocks(self.student, blocks['course'].location, self.transformers)

0 commit comments

Comments
 (0)