diff --git a/openedx/core/djangoapps/content/block_structure/signals.py b/openedx/core/djangoapps/content/block_structure/signals.py index fac42b66f3..ca312ba740 100644 --- a/openedx/core/djangoapps/content/block_structure/signals.py +++ b/openedx/core/djangoapps/content/block_structure/signals.py @@ -14,7 +14,7 @@ from .tasks import update_course_in_cache_v2 @receiver(SignalHandler.course_published) -def _update_block_structure_on_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument +def update_block_structure_on_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument """ Catches the signal that a course has been published in the module store and creates/updates the corresponding cache entry. diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py index 04eeb0dafe..1c23f3319e 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py @@ -11,7 +11,7 @@ from xmodule.modulestore.tests.factories import CourseFactory from ..api import get_block_structure_manager from ..config import INVALIDATE_CACHE_ON_PUBLISH, waffle -from ..signals import _update_block_structure_on_course_publish +from ..signals import update_block_structure_on_course_publish from .helpers import is_course_in_block_structure_cache @@ -78,5 +78,5 @@ class CourseBlocksSignalTest(ModuleStoreTestCase): @ddt.unpack @patch('openedx.core.djangoapps.content.block_structure.tasks.update_course_in_cache_v2.apply_async') def test_update_only_for_courses(self, key, expect_update_called, mock_update): - _update_block_structure_on_course_publish(sender=None, course_key=key) + update_block_structure_on_course_publish(sender=None, course_key=key) self.assertEqual(mock_update.called, expect_update_called) diff --git a/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py b/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py index e89acfbf33..50a19e6501 100644 --- a/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py +++ b/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py @@ -13,6 +13,8 @@ from django.utils import six from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from openedx.core.djangolib.testing.utils import skip_unless_lms + from openedx.core.djangoapps.coursegraph.management.commands.dump_to_neo4j import ( ModuleStoreSerializer ) @@ -27,9 +29,10 @@ from openedx.core.djangoapps.coursegraph.tasks import ( should_dump_course, strip_branch_and_version, ) -from openedx.core.djangoapps.content.course_structures.signals import ( - listen_for_course_publish +from openedx.core.djangoapps.content.block_structure.signals import ( + update_block_structure_on_course_publish ) +import openedx.core.djangoapps.content.block_structure.config as block_structure_config class TestDumpToNeo4jCommandBase(SharedModuleStoreTestCase): @@ -226,6 +229,7 @@ class TestDumpToNeo4jCommand(TestDumpToNeo4jCommandBase): ) +@skip_unless_lms @ddt.ddt class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): """ @@ -492,7 +496,8 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): self.assertEqual(len(submitted), len(self.course_strings)) # simulate one of the courses being published - listen_for_course_publish(None, self.course.id) + with block_structure_config.waffle().override(block_structure_config.STORAGE_BACKING_FOR_CACHE): + update_block_structure_on_course_publish(None, self.course.id) # make sure only the published course was dumped submitted, __ = self.mss.dump_courses_to_neo4j(mock_credentials) diff --git a/openedx/core/djangoapps/coursegraph/tasks.py b/openedx/core/djangoapps/coursegraph/tasks.py index 249fe0928e..093e4ef099 100644 --- a/openedx/core/djangoapps/coursegraph/tasks.py +++ b/openedx/core/djangoapps/coursegraph/tasks.py @@ -135,11 +135,16 @@ def get_course_last_published(course_key): was published. """ # Import is placed here to avoid model import at project startup. - from openedx.core.djangoapps.content.course_structures.models import CourseStructure + from xmodule.modulestore.django import modulestore + from openedx.core.djangoapps.content.block_structure.models import BlockStructureModel + from openedx.core.djangoapps.content.block_structure.exceptions import BlockStructureNotFound + + store = modulestore() + course_usage_key = store.make_course_usage_key(course_key) try: - structure = CourseStructure.objects.get(course_id=course_key) + structure = BlockStructureModel.get(course_usage_key) course_last_published_date = six.text_type(structure.modified) - except CourseStructure.DoesNotExist: + except BlockStructureNotFound: course_last_published_date = None return course_last_published_date