Skip to content

Commit

Permalink
test: fix modulestore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Feb 6, 2025
1 parent b214a4a commit b0e3162
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cms/djangoapps/contentstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)
from olxcleaner.exceptions import ErrorLevel
from olxcleaner.reporting import report_error_summary, report_errors
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocator
from organizations.api import add_organization_course, ensure_organization
Expand Down Expand Up @@ -1079,7 +1080,11 @@ def handle_create_or_update_xblock_upstream_link(usage_key):
Create or update upstream link for a single xblock.
"""
ensure_cms("handle_create_or_update_xblock_upstream_link may only be executed in a CMS context")
xblock = modulestore().get_item(UsageKey.from_string(usage_key))
try:
xblock = modulestore().get_item(UsageKey.from_string(usage_key))
except (ItemNotFoundError, InvalidKeyError):
LOGGER.exception(f'Could not find item for given usage_key: {usage_key}')
return
if not xblock.upstream or not xblock.upstream_version:
return
create_or_update_xblock_upstream_link(xblock, xblock.course_id)
Expand Down
13 changes: 13 additions & 0 deletions xmodule/modulestore/tests/test_mixed_modulestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ def setUp(self):
self.course_locations = {}

self.user_id = ModuleStoreEnum.UserID.test
# mock and ignore publishable link entity related tasks to avoid unnecessary
# errors as it is tested separately
if settings.ROOT_URLCONF == 'cms.urls':
create_or_update_xblock_upstream_link_patch = patch(
'cms.djangoapps.contentstore.signals.handlers.handle_create_or_update_xblock_upstream_link'
)
create_or_update_xblock_upstream_link_patch.start()
self.addCleanup(create_or_update_xblock_upstream_link_patch.stop)
publishableEntityLinkPatch = patch(
'cms.djangoapps.contentstore.signals.handlers.PublishableEntityLink'
)
publishableEntityLinkPatch.start()
self.addCleanup(publishableEntityLinkPatch.stop)

def _check_connection(self):
"""
Expand Down

0 comments on commit b0e3162

Please sign in to comment.