test: updated CourseOverview Signals Tests for split modulestore
This commit is contained in:
committed by
David Ormsbee
parent
0870e1a758
commit
1936de4d68
@@ -6,10 +6,11 @@ from collections import namedtuple
|
||||
|
||||
import pytest
|
||||
import ddt
|
||||
from pytz import UTC
|
||||
|
||||
from xmodule.data import CertificatesDisplayBehaviors
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.tests.django_utils import TEST_DATA_MONGO_AMNESTY_MODULESTORE, ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.django_utils import TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED, ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls
|
||||
|
||||
from ..models import CourseOverview
|
||||
@@ -23,13 +24,12 @@ class CourseOverviewSignalsTestCase(ModuleStoreTestCase):
|
||||
"""
|
||||
Tests for CourseOverview signals.
|
||||
"""
|
||||
MODULESTORE = TEST_DATA_MONGO_AMNESTY_MODULESTORE
|
||||
MODULESTORE = TEST_DATA_ONLY_SPLIT_MODULESTORE_DRAFT_PREFERRED
|
||||
ENABLED_SIGNALS = ['course_deleted', 'course_published']
|
||||
TODAY = datetime.datetime.utcnow()
|
||||
TODAY = datetime.datetime.utcnow().replace(tzinfo=UTC)
|
||||
NEXT_WEEK = TODAY + datetime.timedelta(days=7)
|
||||
|
||||
@ddt.data(ModuleStoreEnum.Type.split)
|
||||
def test_caching(self, modulestore_type):
|
||||
def test_caching(self):
|
||||
"""
|
||||
Tests that CourseOverview structures are actually getting cached.
|
||||
|
||||
@@ -38,14 +38,13 @@ class CourseOverviewSignalsTestCase(ModuleStoreTestCase):
|
||||
course in.
|
||||
"""
|
||||
# Creating a new course will trigger a publish event and the course will be cached
|
||||
course = CourseFactory.create(default_store=modulestore_type, emit_signals=True)
|
||||
course = CourseFactory.create(emit_signals=True)
|
||||
|
||||
# The cache will be hit and mongo will not be queried
|
||||
with check_mongo_calls(0):
|
||||
CourseOverview.get_from_id(course.id)
|
||||
|
||||
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
|
||||
def test_cache_invalidation(self, modulestore_type):
|
||||
def test_cache_invalidation(self):
|
||||
"""
|
||||
Tests that when a course is published or deleted, the corresponding
|
||||
course_overview is removed from the cache.
|
||||
@@ -54,28 +53,26 @@ class CourseOverviewSignalsTestCase(ModuleStoreTestCase):
|
||||
modulestore_type (ModuleStoreEnum.Type): type of store to create the
|
||||
course in.
|
||||
"""
|
||||
with self.store.default_store(modulestore_type):
|
||||
# Create a course where mobile_available is True.
|
||||
course = CourseFactory.create(mobile_available=True)
|
||||
course_overview_1 = CourseOverview.get_from_id(course.id)
|
||||
assert course_overview_1.mobile_available
|
||||
|
||||
# Create a course where mobile_available is True.
|
||||
course = CourseFactory.create(mobile_available=True, default_store=modulestore_type)
|
||||
course_overview_1 = CourseOverview.get_from_id(course.id)
|
||||
assert course_overview_1.mobile_available
|
||||
# Set mobile_available to False and update the course.
|
||||
# This fires a course_published signal, which should be caught in signals.py, which should in turn
|
||||
# delete the corresponding CourseOverview from the cache.
|
||||
course.mobile_available = False
|
||||
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred):
|
||||
self.store.update_item(course, ModuleStoreEnum.UserID.test)
|
||||
|
||||
# Set mobile_available to False and update the course.
|
||||
# This fires a course_published signal, which should be caught in signals.py, which should in turn
|
||||
# delete the corresponding CourseOverview from the cache.
|
||||
course.mobile_available = False
|
||||
with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred):
|
||||
self.store.update_item(course, ModuleStoreEnum.UserID.test)
|
||||
# Make sure that when we load the CourseOverview again, mobile_available is updated.
|
||||
course_overview_2 = CourseOverview.get_from_id(course.id)
|
||||
assert not course_overview_2.mobile_available
|
||||
|
||||
# Make sure that when we load the CourseOverview again, mobile_available is updated.
|
||||
course_overview_2 = CourseOverview.get_from_id(course.id)
|
||||
assert not course_overview_2.mobile_available
|
||||
|
||||
# Verify that when the course is deleted, the corresponding CourseOverview is deleted as well.
|
||||
with pytest.raises(CourseOverview.DoesNotExist):
|
||||
self.store.delete_course(course.id, ModuleStoreEnum.UserID.test)
|
||||
CourseOverview.get_from_id(course.id)
|
||||
# Verify that when the course is deleted, the corresponding CourseOverview is deleted as well.
|
||||
with pytest.raises(CourseOverview.DoesNotExist):
|
||||
self.store.delete_course(course.id, ModuleStoreEnum.UserID.test)
|
||||
CourseOverview.get_from_id(course.id)
|
||||
|
||||
def assert_changed_signal_sent(self, changes, mock_signal): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
course = CourseFactory.create(
|
||||
@@ -86,7 +83,7 @@ class CourseOverviewSignalsTestCase(ModuleStoreTestCase):
|
||||
# changing display name doesn't fire the signal
|
||||
with self.captureOnCommitCallbacks(execute=True) as callbacks:
|
||||
course.display_name = course.display_name + 'changed'
|
||||
self.store.update_item(course, ModuleStoreEnum.UserID.test)
|
||||
course = self.store.update_item(course, ModuleStoreEnum.UserID.test)
|
||||
assert not mock_signal.called
|
||||
|
||||
# changing the given field fires the signal
|
||||
|
||||
Reference in New Issue
Block a user